cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yu...@apache.org
Subject [6/9] git commit: suppress sending too many progress notifications
Date Mon, 12 Aug 2013 16:14:20 GMT
suppress sending too many progress notifications


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/a3479008
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/a3479008
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/a3479008

Branch: refs/heads/trunk
Commit: a34790085ae7f79615f7225911ba9cf8ceb8f3e2
Parents: a0d6ed1
Author: Yuki Morishita <yukim@apache.org>
Authored: Mon Aug 12 11:07:53 2013 -0500
Committer: Yuki Morishita <yukim@apache.org>
Committed: Mon Aug 12 11:10:37 2013 -0500

----------------------------------------------------------------------
 .../management/StreamEventJMXNotifier.java      | 26 ++++++++++++++------
 1 file changed, 18 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/a3479008/src/java/org/apache/cassandra/streaming/management/StreamEventJMXNotifier.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/streaming/management/StreamEventJMXNotifier.java
b/src/java/org/apache/cassandra/streaming/management/StreamEventJMXNotifier.java
index f8c54ec..01ca9a1 100644
--- a/src/java/org/apache/cassandra/streaming/management/StreamEventJMXNotifier.java
+++ b/src/java/org/apache/cassandra/streaming/management/StreamEventJMXNotifier.java
@@ -21,17 +21,19 @@ import java.util.concurrent.atomic.AtomicLong;
 import javax.management.Notification;
 import javax.management.NotificationBroadcasterSupport;
 
-import org.apache.cassandra.streaming.StreamEvent;
-import org.apache.cassandra.streaming.StreamEventHandler;
-import org.apache.cassandra.streaming.StreamManagerMBean;
-import org.apache.cassandra.streaming.StreamState;
+import org.apache.cassandra.streaming.*;
 
 /**
  */
 public class StreamEventJMXNotifier extends NotificationBroadcasterSupport implements StreamEventHandler
 {
+    // interval in millisec to use for progress notification
+    private static final long PROGRESS_NOTIFICATION_INTERVAL = 1000;
+
     private final AtomicLong seq = new AtomicLong();
 
+    private long progressLastSent;
+
     public void handleStreamEvent(StreamEvent event)
     {
         Notification notif = null;
@@ -49,10 +51,18 @@ public class StreamEventJMXNotifier extends NotificationBroadcasterSupport
imple
                 notif.setUserData(SessionCompleteEventCompositeData.toCompositeData((StreamEvent.SessionCompleteEvent)
event));
                 break;
             case FILE_PROGRESS:
-                notif = new Notification(StreamEvent.ProgressEvent.class.getCanonicalName(),
-                                         StreamManagerMBean.OBJECT_NAME,
-                                         seq.getAndIncrement());
-                notif.setUserData(ProgressInfoCompositeData.toCompositeData(event.planId,
((StreamEvent.ProgressEvent) event).progress));
+                ProgressInfo progress = ((StreamEvent.ProgressEvent) event).progress;
+                long current = System.currentTimeMillis();
+                if (current - progressLastSent >= PROGRESS_NOTIFICATION_INTERVAL || progress.isCompleted())
+                {
+                    notif = new Notification(StreamEvent.ProgressEvent.class.getCanonicalName(),
+                                             StreamManagerMBean.OBJECT_NAME,
+                                             seq.getAndIncrement());
+                    notif.setUserData(ProgressInfoCompositeData.toCompositeData(event.planId,
progress));
+                    progressLastSent = System.currentTimeMillis();
+                } else {
+                    return;
+                }
                 break;
         }
         sendNotification(notif);


Mime
View raw message