Fix NPE in the map, add accessors to stats information
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 13 Aug 2007 13:54:30 +0000 (13:54 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 13 Aug 2007 13:54:30 +0000 (13:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@565352 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/tribes/group/interceptors/ThroughputInterceptor.java
java/org/apache/catalina/tribes/tipis/AbstractReplicatedMap.java

index e9636a9..2d4935f 100644 (file)
 
 package org.apache.catalina.tribes.group.interceptors;
 
+import java.text.DecimalFormat;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+
 import org.apache.catalina.tribes.ChannelException;
 import org.apache.catalina.tribes.ChannelMessage;
 import org.apache.catalina.tribes.Member;
@@ -23,10 +27,6 @@ import org.apache.catalina.tribes.group.ChannelInterceptorBase;
 import org.apache.catalina.tribes.group.InterceptorPayload;
 import org.apache.catalina.tribes.io.ChannelData;
 import org.apache.catalina.tribes.io.XByteBuffer;
-import java.text.DecimalFormat;
-import org.apache.catalina.tribes.membership.MemberImpl;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicLong;
 
 
 
@@ -61,7 +61,7 @@ public class ThroughputInterceptor extends ChannelInterceptorBase {
             super.sendMessage(destination, msg, payload);
         }catch ( ChannelException x ) {
             msgTxErr.addAndGet(1);
-            access.addAndGet(-1);
+            if ( access.get() == 1 ) access.addAndGet(-1);
             throw x;
         } 
         mbTx += ((double)(bytes*destination.length))/(1024d*1024d);
@@ -117,4 +117,44 @@ public class ThroughputInterceptor extends ChannelInterceptorBase {
         return interval;
     }
 
+    public double getLastCnt() {
+        return lastCnt;
+    }
+
+    public double getMbAppTx() {
+        return mbAppTx;
+    }
+
+    public double getMbRx() {
+        return mbRx;
+    }
+
+    public double getMbTx() {
+        return mbTx;
+    }
+
+    public AtomicLong getMsgRxCnt() {
+        return msgRxCnt;
+    }
+
+    public AtomicLong getMsgTxCnt() {
+        return msgTxCnt;
+    }
+
+    public AtomicLong getMsgTxErr() {
+        return msgTxErr;
+    }
+
+    public long getRxStart() {
+        return rxStart;
+    }
+
+    public double getTimeTx() {
+        return timeTx;
+    }
+
+    public long getTxStart() {
+        return txStart;
+    }
+
 }
index 2261f7d..f6acac5 100644 (file)
@@ -511,7 +511,7 @@ public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements
                 while (i.hasNext()) {
                     Map.Entry e = (Map.Entry) i.next();
                     MapEntry entry = (MapEntry) super.get(e.getKey());
-                    if ( entry.isSerializable() ) {
+                    if ( entry != null && entry.isSerializable() ) {
                         boolean copy = (mapmsg.getMsgType() == mapmsg.MSG_STATE_COPY);
                         MapMessage me = new MapMessage(mapContextName, 
                                                        copy?MapMessage.MSG_COPY:MapMessage.MSG_PROXY,
@@ -719,6 +719,7 @@ public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements
         while (i.hasNext()) {
             Map.Entry e = (Map.Entry) i.next();
             MapEntry entry = (MapEntry) super.get(e.getKey());
+            if (entry==null) continue;
             if (entry.isPrimary() && inSet(member,entry.getBackupNodes())) {
                 if (log.isDebugEnabled()) log.debug("[1] Primary choosing a new backup");
                 try {
@@ -977,7 +978,7 @@ public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements
                 while (i.hasNext()) {
                     Map.Entry e = (Map.Entry) i.next();
                     MapEntry entry = (MapEntry) super.get(e.getKey());
-                    if (entry.isPrimary() && value.equals(entry.getValue())) return true;
+                    if (entry!=null && entry.isPrimary() && value.equals(entry.getValue())) return true;
                 }//while
                 return false;
             }//end if
@@ -1062,7 +1063,7 @@ public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements
             while ( i.hasNext() ) {
                 Map.Entry e = (Map.Entry)i.next();
                 MapEntry entry = (MapEntry)super.get(e.getKey());
-                if ( entry.isPrimary() && entry.getValue()!=null) values.add(entry.getValue());
+                if (entry!=null && entry.isPrimary() && entry.getValue()!=null) values.add(entry.getValue());
             }
             return Collections.unmodifiableCollection(values);
         }