Author: frm
Date: Tue Jun 18 12:36:26 2019
New Revision: 1861576

URL: http://svn.apache.org/viewvc?rev=1861576&view=rev
Log:
OAK-8410 - Fix NPE in the RequestCompletedEvent listener

Modified:
    
jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzurePersistence.java

Modified: 
jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzurePersistence.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzurePersistence.java?rev=1861576&r1=1861575&r2=1861576&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzurePersistence.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-azure/src/main/java/org/apache/jackrabbit/oak/segment/azure/AzurePersistence.java
 Tue Jun 18 12:36:26 2019
@@ -65,7 +65,7 @@ public class AzurePersistence implements
 
     @Override
     public SegmentArchiveManager createArchiveManager(boolean mmap, boolean 
offHeapAccess, IOMonitor ioMonitor, FileStoreMonitor fileStoreMonitor, 
RemoteStoreMonitor remoteStoreMonitor) {
-        azureRemoteStoreMonitor(remoteStoreMonitor);
+        attachRemoteStoreMonitor(remoteStoreMonitor);
         return new AzureArchiveManager(segmentstoreDirectory, ioMonitor, 
fileStoreMonitor);
     }
 
@@ -127,27 +127,28 @@ public class AzurePersistence implements
         }
     }
 
-    private void azureRemoteStoreMonitor(RemoteStoreMonitor 
remoteStoreMonitor){
-
-        OperationContext operationContext = new OperationContext();
-
-        
operationContext.getGlobalRequestCompletedEventHandler().addListener(new 
StorageEvent<RequestCompletedEvent>() {
+    private static void attachRemoteStoreMonitor(RemoteStoreMonitor 
remoteStoreMonitor) {
+        
OperationContext.getGlobalRequestCompletedEventHandler().addListener(new 
StorageEvent<RequestCompletedEvent>() {
 
             @Override
-            public void eventOccurred(RequestCompletedEvent eventArg) {
-                Date startDate = eventArg.getRequestResult().getStartDate();
-                Date stopDate = eventArg.getRequestResult().getStopDate();
-                long requestDuration = stopDate.getTime() - 
startDate.getTime();
-                remoteStoreMonitor.requestDuration(requestDuration, 
TimeUnit.MILLISECONDS);
+            public void eventOccurred(RequestCompletedEvent e) {
+                Date startDate = e.getRequestResult().getStartDate();
+                Date stopDate = e.getRequestResult().getStopDate();
+
+                if (startDate != null && stopDate != null) {
+                    long requestDuration = stopDate.getTime() - 
startDate.getTime();
+                    remoteStoreMonitor.requestDuration(requestDuration, 
TimeUnit.MILLISECONDS);
+                }
 
-                Exception exception = 
eventArg.getRequestResult().getException();
+                Exception exception = e.getRequestResult().getException();
 
-                if(exception == null){
+                if (exception == null) {
                     remoteStoreMonitor.requestCount();
-                }else {
+                } else {
                     remoteStoreMonitor.requestError();
                 }
             }
+
         });
     }
 


Reply via email to