1
1
using System ;
2
2
using System . Collections . Generic ;
3
- using System . Runtime . CompilerServices ;
4
3
using System . Text ;
5
- using System . Threading ;
6
-
7
- using NHibernate . Cache ;
8
4
using NHibernate . Engine ;
9
- using NHibernate . Util ;
10
5
using System . Linq ;
11
6
12
7
namespace NHibernate . Stat
13
8
{
14
9
public class StatisticsImpl : IStatistics , IStatisticsImplementor
15
10
{
16
- private object _syncRoot ;
11
+ private readonly object _syncRoot = new object ( ) ;
17
12
18
13
private static readonly INHibernateLogger log = NHibernateLogger . For ( typeof ( StatisticsImpl ) ) ;
19
14
private readonly ISessionFactoryImplementor sessionFactory ;
@@ -81,17 +76,6 @@ public StatisticsImpl(ISessionFactoryImplementor sessionFactory)
81
76
this . sessionFactory = sessionFactory ;
82
77
}
83
78
84
- private object SyncRoot
85
- {
86
- get
87
- {
88
- if ( _syncRoot == null )
89
- Interlocked . CompareExchange ( ref _syncRoot , new object ( ) , null ) ;
90
-
91
- return _syncRoot ;
92
- }
93
- }
94
-
95
79
#region IStatistics Members
96
80
97
81
public long EntityDeleteCount
@@ -305,10 +289,9 @@ public long OptimisticFailureCount
305
289
get { return optimisticFailureCount ; }
306
290
}
307
291
308
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
309
292
public void Clear ( )
310
293
{
311
- lock ( SyncRoot )
294
+ lock ( _syncRoot )
312
295
{
313
296
secondLevelCacheHitCount = 0 ;
314
297
secondLevelCacheMissCount = 0 ;
@@ -355,10 +338,9 @@ public void Clear()
355
338
}
356
339
}
357
340
358
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
359
341
public EntityStatistics GetEntityStatistics ( string entityName )
360
342
{
361
- lock ( SyncRoot )
343
+ lock ( _syncRoot )
362
344
{
363
345
EntityStatistics es ;
364
346
if ( ! entityStatistics . TryGetValue ( entityName , out es ) )
@@ -370,10 +352,9 @@ public EntityStatistics GetEntityStatistics(string entityName)
370
352
}
371
353
}
372
354
373
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
374
355
public CollectionStatistics GetCollectionStatistics ( string role )
375
356
{
376
- lock ( SyncRoot )
357
+ lock ( _syncRoot )
377
358
{
378
359
CollectionStatistics cs ;
379
360
if ( ! collectionStatistics . TryGetValue ( role , out cs ) )
@@ -385,10 +366,9 @@ public CollectionStatistics GetCollectionStatistics(string role)
385
366
}
386
367
}
387
368
388
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
389
369
public SecondLevelCacheStatistics GetSecondLevelCacheStatistics ( string regionName )
390
370
{
391
- lock ( SyncRoot )
371
+ lock ( _syncRoot )
392
372
{
393
373
SecondLevelCacheStatistics slcs ;
394
374
@@ -406,10 +386,9 @@ public SecondLevelCacheStatistics GetSecondLevelCacheStatistics(string regionNam
406
386
}
407
387
}
408
388
409
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
410
389
public QueryStatistics GetQueryStatistics ( string queryString )
411
390
{
412
- lock ( SyncRoot )
391
+ lock ( _syncRoot )
413
392
{
414
393
QueryStatistics qs ;
415
394
if ( ! queryStatistics . TryGetValue ( queryString , out qs ) )
@@ -460,10 +439,9 @@ public TimeSpan OperationThreshold
460
439
{
461
440
return operationThreshold ;
462
441
}
463
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
464
442
set
465
443
{
466
- lock ( SyncRoot )
444
+ lock ( _syncRoot )
467
445
{
468
446
operationThreshold = value ;
469
447
}
@@ -474,46 +452,41 @@ public TimeSpan OperationThreshold
474
452
475
453
#region IStatisticsImplementor Members
476
454
477
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
478
455
public void OpenSession ( )
479
456
{
480
- lock ( SyncRoot )
457
+ lock ( _syncRoot )
481
458
{
482
459
sessionOpenCount ++ ;
483
460
}
484
461
}
485
462
486
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
487
463
public void CloseSession ( )
488
464
{
489
- lock ( SyncRoot )
465
+ lock ( _syncRoot )
490
466
{
491
467
sessionCloseCount ++ ;
492
468
}
493
469
}
494
470
495
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
496
471
public void Flush ( )
497
472
{
498
- lock ( SyncRoot )
473
+ lock ( _syncRoot )
499
474
{
500
475
flushCount ++ ;
501
476
}
502
477
}
503
478
504
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
505
479
public void Connect ( )
506
480
{
507
- lock ( SyncRoot )
481
+ lock ( _syncRoot )
508
482
{
509
483
connectCount ++ ;
510
484
}
511
485
}
512
486
513
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
514
487
public void LoadEntity ( string entityName , TimeSpan time )
515
488
{
516
- lock ( SyncRoot )
489
+ lock ( _syncRoot )
517
490
{
518
491
entityLoadCount ++ ;
519
492
GetEntityStatistics ( entityName ) . loadCount ++ ;
@@ -524,10 +497,9 @@ public void LoadEntity(string entityName, TimeSpan time)
524
497
}
525
498
}
526
499
527
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
528
500
public void FetchEntity ( string entityName , TimeSpan time )
529
501
{
530
- lock ( SyncRoot )
502
+ lock ( _syncRoot )
531
503
{
532
504
entityFetchCount ++ ;
533
505
GetEntityStatistics ( entityName ) . fetchCount ++ ;
@@ -538,10 +510,9 @@ public void FetchEntity(string entityName, TimeSpan time)
538
510
}
539
511
}
540
512
541
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
542
513
public void UpdateEntity ( string entityName , TimeSpan time )
543
514
{
544
- lock ( SyncRoot )
515
+ lock ( _syncRoot )
545
516
{
546
517
entityUpdateCount ++ ;
547
518
GetEntityStatistics ( entityName ) . updateCount ++ ;
@@ -552,10 +523,9 @@ public void UpdateEntity(string entityName, TimeSpan time)
552
523
}
553
524
}
554
525
555
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
556
526
public void InsertEntity ( string entityName , TimeSpan time )
557
527
{
558
- lock ( SyncRoot )
528
+ lock ( _syncRoot )
559
529
{
560
530
entityInsertCount ++ ;
561
531
GetEntityStatistics ( entityName ) . insertCount ++ ;
@@ -566,10 +536,9 @@ public void InsertEntity(string entityName, TimeSpan time)
566
536
}
567
537
}
568
538
569
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
570
539
public void DeleteEntity ( string entityName , TimeSpan time )
571
540
{
572
- lock ( SyncRoot )
541
+ lock ( _syncRoot )
573
542
{
574
543
entityDeleteCount ++ ;
575
544
GetEntityStatistics ( entityName ) . deleteCount ++ ;
@@ -580,10 +549,9 @@ public void DeleteEntity(string entityName, TimeSpan time)
580
549
}
581
550
}
582
551
583
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
584
552
public void LoadCollection ( string role , TimeSpan time )
585
553
{
586
- lock ( SyncRoot )
554
+ lock ( _syncRoot )
587
555
{
588
556
collectionLoadCount ++ ;
589
557
GetCollectionStatistics ( role ) . loadCount ++ ;
@@ -594,10 +562,9 @@ public void LoadCollection(string role, TimeSpan time)
594
562
}
595
563
}
596
564
597
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
598
565
public void FetchCollection ( string role , TimeSpan time )
599
566
{
600
- lock ( SyncRoot )
567
+ lock ( _syncRoot )
601
568
{
602
569
collectionFetchCount ++ ;
603
570
GetCollectionStatistics ( role ) . fetchCount ++ ;
@@ -608,10 +575,9 @@ public void FetchCollection(string role, TimeSpan time)
608
575
}
609
576
}
610
577
611
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
612
578
public void UpdateCollection ( string role , TimeSpan time )
613
579
{
614
- lock ( SyncRoot )
580
+ lock ( _syncRoot )
615
581
{
616
582
collectionUpdateCount ++ ;
617
583
GetCollectionStatistics ( role ) . updateCount ++ ;
@@ -622,10 +588,9 @@ public void UpdateCollection(string role, TimeSpan time)
622
588
}
623
589
}
624
590
625
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
626
591
public void RecreateCollection ( string role , TimeSpan time )
627
592
{
628
- lock ( SyncRoot )
593
+ lock ( _syncRoot )
629
594
{
630
595
collectionRecreateCount ++ ;
631
596
GetCollectionStatistics ( role ) . recreateCount ++ ;
@@ -636,24 +601,22 @@ public void RecreateCollection(string role, TimeSpan time)
636
601
}
637
602
}
638
603
639
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
640
604
public void RemoveCollection ( string role , TimeSpan time )
641
605
{
642
- lock ( SyncRoot )
606
+ lock ( _syncRoot )
643
607
{
644
608
collectionRemoveCount ++ ;
645
609
GetCollectionStatistics ( role ) . removeCount ++ ;
646
610
}
647
611
if ( operationThreshold < time )
648
612
{
649
- LogOperation ( OperationRecreateCollection , role , time ) ;
613
+ LogOperation ( OperationRemoveCollection , role , time ) ;
650
614
}
651
615
}
652
616
653
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
654
617
public void SecondLevelCachePut ( string regionName )
655
618
{
656
- lock ( SyncRoot )
619
+ lock ( _syncRoot )
657
620
{
658
621
SecondLevelCacheStatistics slc = GetSecondLevelCacheStatistics ( regionName ) ;
659
622
if ( slc != null )
@@ -664,10 +627,9 @@ public void SecondLevelCachePut(string regionName)
664
627
}
665
628
}
666
629
667
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
668
630
public void SecondLevelCacheHit ( string regionName )
669
631
{
670
- lock ( SyncRoot )
632
+ lock ( _syncRoot )
671
633
{
672
634
SecondLevelCacheStatistics slc = GetSecondLevelCacheStatistics ( regionName ) ;
673
635
if ( slc != null )
@@ -678,10 +640,9 @@ public void SecondLevelCacheHit(string regionName)
678
640
}
679
641
}
680
642
681
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
682
643
public void SecondLevelCacheMiss ( string regionName )
683
644
{
684
- lock ( SyncRoot )
645
+ lock ( _syncRoot )
685
646
{
686
647
SecondLevelCacheStatistics slc = GetSecondLevelCacheStatistics ( regionName ) ;
687
648
if ( slc != null )
@@ -692,10 +653,9 @@ public void SecondLevelCacheMiss(string regionName)
692
653
}
693
654
}
694
655
695
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
696
656
public void QueryExecuted ( string hql , int rows , TimeSpan time )
697
657
{
698
- lock ( SyncRoot )
658
+ lock ( _syncRoot )
699
659
{
700
660
queryExecutionCount ++ ;
701
661
if ( queryExecutionMaxTime < time )
@@ -715,10 +675,9 @@ public void QueryExecuted(string hql, int rows, TimeSpan time)
715
675
}
716
676
}
717
677
718
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
719
678
public void QueryCacheHit ( string hql , string regionName )
720
679
{
721
- lock ( SyncRoot )
680
+ lock ( _syncRoot )
722
681
{
723
682
queryCacheHitCount ++ ;
724
683
if ( hql != null )
@@ -734,10 +693,9 @@ public void QueryCacheHit(string hql, string regionName)
734
693
}
735
694
}
736
695
737
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
738
696
public void QueryCacheMiss ( string hql , string regionName )
739
697
{
740
- lock ( SyncRoot )
698
+ lock ( _syncRoot )
741
699
{
742
700
queryCacheMissCount ++ ;
743
701
if ( hql != null )
@@ -753,10 +711,9 @@ public void QueryCacheMiss(string hql, string regionName)
753
711
}
754
712
}
755
713
756
- [ MethodImpl ( MethodImplOptions . Synchronized ) ]
757
714
public void QueryCachePut ( string hql , string regionName )
758
715
{
759
- lock ( SyncRoot )
716
+ lock ( _syncRoot )
760
717
{
761
718
queryCachePutCount ++ ;
762
719
if ( hql != null )
0 commit comments