Fix NPE in the RequestCompletedEvent listener
@@ -65,7 +65,7 @@ public class AzurePersistence implements SegmentNodeStorePersistence {
@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,20 +127,20 @@ public class AzurePersistence implements SegmentNodeStorePersistence {
}
}
- 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();
+ 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) {
remoteStoreMonitor.requestCount();
@@ -148,6 +148,7 @@ public class AzurePersistence implements SegmentNodeStorePersistence {
remoteStoreMonitor.requestError();
}
}
+
});
}
