directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r441336 - in /directory/trunks/mina: core/src/main/java/org/apache/mina/management/ integration-jmx/src/main/java/org/apache/mina/integration/jmx/
Date Fri, 08 Sep 2006 02:11:34 GMT
Author: trustin
Date: Thu Sep  7 19:11:33 2006
New Revision: 441336

URL: http://svn.apache.org/viewvc?view=rev&rev=441336
Log:
* Fixed a few documentation problems and coding practices


Modified:
    directory/trunks/mina/core/src/main/java/org/apache/mina/management/IoSessionStat.java
  (contents, props changed)
    directory/trunks/mina/core/src/main/java/org/apache/mina/management/StatCollector.java
  (contents, props changed)
    directory/trunks/mina/integration-jmx/src/main/java/org/apache/mina/integration/jmx/IoServiceManager.java
    directory/trunks/mina/integration-jmx/src/main/java/org/apache/mina/integration/jmx/IoSessionManager.java

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/management/IoSessionStat.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/management/IoSessionStat.java?view=diff&rev=441336&r1=441335&r2=441336
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/management/IoSessionStat.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/management/IoSessionStat.java
Thu Sep  7 19:11:33 2006
@@ -20,12 +20,14 @@
 package org.apache.mina.management;
 
 /**
+ * The collected stats for a session. It's used by {@link StatCollector} to attach
+ * throughput stats to an {@link IoSession}.
+ * 
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
- * The collected stats for a session. It's used by StatCollector for attach throughput stats
to IoSession
+ * @version $Rev$, $Date$
  */
 public class IoSessionStat
 {
-
     long lastByteRead = -1;
     long lastByteWrite = -1;
     long lastMessageRead = -1;

Propchange: directory/trunks/mina/core/src/main/java/org/apache/mina/management/IoSessionStat.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/management/StatCollector.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/management/StatCollector.java?view=diff&rev=441336&r1=441335&r2=441336
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/management/StatCollector.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/management/StatCollector.java
Thu Sep  7 19:11:33 2006
@@ -23,6 +23,7 @@
 import java.net.SocketAddress;
 import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
 
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoService;
@@ -32,48 +33,46 @@
 
 
 /**
+ * Collects statistics of an {@linkIoService}. It's polling all the sessions of a given
+ * IoService. It's attaching a {@link IoSessionStat} object to all the sessions polled
+ * and filling the throughput values.
+ * 
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
- * An  IoService statistic collector. It's polling all the sessions of a given IoService.
It's attaching a IoSessionStats object to
- * all the sessions polled and filling the throughput values.
+ * @version $Rev$, $Date$
  */
 public class StatCollector
 {
-    private IoService service;
-
-    public static String STAT_ID = "StatCollected";
+    /**
+     * The session attribute key for {@link IoSessionStat}.
+     */
+    public static final String KEY = StatCollector.class.getName() + ".stat";
 
+    private final IoService service;
     private Worker worker;
-
     private int pollingInterval = 5000;
+    private List polledSessions;
 
-    private ArrayList polledSessions;
-
-    private IoServiceListener serviceListener = new IoServiceListener()
+    private final IoServiceListener serviceListener = new IoServiceListener()
     {
-
         public void serviceActivated( IoService service, SocketAddress serviceAddress, IoHandler
handler,
             IoServiceConfig config )
         {
         }
 
-
         public void serviceDeactivated( IoService service, SocketAddress serviceAddress,
IoHandler handler,
             IoServiceConfig config )
         {
         }
 
-
         public void sessionCreated( IoSession session )
         {
             addSession( session );
         }
 
-
         public void sessionDestroyed( IoSession session )
         {
             removeSession( session );
         }
-
     };
 
     /**
@@ -82,7 +81,7 @@
      */
     public StatCollector( IoService service )
     {
-        this(service,5000);
+        this( service,5000 );
 
     }
 
@@ -102,6 +101,7 @@
      */
     public void start()
     {
+        // TODO Make this method thread-safe.
         if ( worker != null && worker.isAlive() )
             throw new RuntimeException( "Stat collecting already started" );
 
@@ -133,6 +133,8 @@
      */
     public void stop()
     {
+        // TODO Make this method thread-safe.
+        // TODO Make the worker stop immediately, not waiting for the next loop.
         service.removeListener( serviceListener );
 
         // stop worker
@@ -159,21 +161,20 @@
      */
     public boolean isRunning()
     {
+        // TODO Make this method thread-safe
         return worker != null && worker.stop != true;
     }
 
-
     private void addSession( IoSession session )
     {
         polledSessions.add( session );
-        session.setAttribute( STAT_ID, new IoSessionStat() );
+        session.setAttribute( KEY, new IoSessionStat() );
     }
 
-
     private void removeSession( IoSession session )
     {
         polledSessions.remove( session );
-        session.removeAttribute( STAT_ID );
+        session.removeAttribute( KEY );
     }
 
     private class Worker extends Thread
@@ -181,9 +182,9 @@
 
         boolean stop = false;
 
-
         private Worker()
         {
+            // TODO Append a thread ID or any distingushed information to the thread name.
             super( "StatCollectorWorker" );
         }
 
@@ -194,7 +195,7 @@
                 for ( Iterator iter = polledSessions.iterator(); iter.hasNext(); )
                 {
                     IoSession session = ( IoSession ) iter.next();
-                    IoSessionStat sessStat = ( IoSessionStat ) session.getAttribute( STAT_ID
);
+                    IoSessionStat sessStat = ( IoSessionStat ) session.getAttribute( KEY
);
 
                     sessStat.lastByteRead = session.getReadBytes();
                     sessStat.lastByteWrite = session.getWrittenBytes();
@@ -214,20 +215,19 @@
                 for ( Iterator iter = polledSessions.iterator(); iter.hasNext(); )
                 {
                     IoSession session = ( IoSession ) iter.next();
-                    IoSessionStat sessStat = ( IoSessionStat ) session.getAttribute( STAT_ID
);
+                    IoSessionStat sessStat = ( IoSessionStat ) session.getAttribute( KEY
);
 
-                    sessStat.byteReadThroughput = ( ( float ) ( session.getReadBytes() -
sessStat.lastByteRead ) )
-                        / ( ( ( float ) pollingInterval ) / 1000f );
-                    sessStat.byteWrittenThroughput = ( ( float ) ( session.getWrittenBytes()
- sessStat.lastByteWrite ) )
-                        / ( ( ( float ) pollingInterval ) / 1000f );
-
-                    sessStat.messageReadThroughput = ( ( float ) ( session.getReadMessages()
- sessStat.lastMessageRead ) )
-                        / ( ( ( float ) pollingInterval ) / 1000f );
-                    sessStat.messageWrittenThroughput = ( ( float ) ( session.getWrittenMessages()
- sessStat.lastMessageWrite ) )
-                        / ( ( ( float ) pollingInterval ) / 1000f );
+                    sessStat.byteReadThroughput = ( session.getReadBytes() - sessStat.lastByteRead
)
+                        / ( pollingInterval / 1000f );
+                    sessStat.byteWrittenThroughput = ( session.getWrittenBytes() - sessStat.lastByteWrite
)
+                        / ( pollingInterval / 1000f );
+
+                    sessStat.messageReadThroughput = ( session.getReadMessages() - sessStat.lastMessageRead
)
+                        / ( pollingInterval / 1000f );
+                    sessStat.messageWrittenThroughput = ( session.getWrittenMessages() -
sessStat.lastMessageWrite )
+                        / ( pollingInterval / 1000f );
 
                 }
-
             }
         }
     }

Propchange: directory/trunks/mina/core/src/main/java/org/apache/mina/management/StatCollector.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/trunks/mina/integration-jmx/src/main/java/org/apache/mina/integration/jmx/IoServiceManager.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/integration-jmx/src/main/java/org/apache/mina/integration/jmx/IoServiceManager.java?view=diff&rev=441336&r1=441335&r2=441336
==============================================================================
--- directory/trunks/mina/integration-jmx/src/main/java/org/apache/mina/integration/jmx/IoServiceManager.java
(original)
+++ directory/trunks/mina/integration-jmx/src/main/java/org/apache/mina/integration/jmx/IoServiceManager.java
Thu Sep  7 19:11:33 2006
@@ -91,7 +91,7 @@
             for ( Iterator iter2 = service.getManagedSessions( element ).iterator(); iter2.hasNext();
)
             {
                 IoSession session = ( IoSession ) iter2.next();
-                total += ( ( IoSessionStat ) session.getAttribute( StatCollector.STAT_ID
) )
+                total += ( ( IoSessionStat ) session.getAttribute( StatCollector.KEY ) )
                     .getByteReadThroughput();
             }
         }
@@ -109,7 +109,7 @@
             for ( Iterator iter2 = service.getManagedSessions( element ).iterator(); iter2.hasNext();
)
             {
                 IoSession session = ( IoSession ) iter2.next();
-                total += ( ( IoSessionStat ) session.getAttribute( StatCollector.STAT_ID
) )
+                total += ( ( IoSessionStat ) session.getAttribute( StatCollector.KEY ) )
                     .getByteWrittenThroughput();
             }
         }
@@ -127,7 +127,7 @@
             for ( Iterator iter2 = service.getManagedSessions( element ).iterator(); iter2.hasNext();
)
             {
                 IoSession session = ( IoSession ) iter2.next();
-                total += ( ( IoSessionStat ) session.getAttribute( StatCollector.STAT_ID
) )
+                total += ( ( IoSessionStat ) session.getAttribute( StatCollector.KEY ) )
                     .getMessageReadThroughput();
             }
         }
@@ -145,7 +145,7 @@
             for ( Iterator iter2 = service.getManagedSessions( element ).iterator(); iter2.hasNext();
)
             {
                 IoSession session = ( IoSession ) iter2.next();
-                total += ( ( IoSessionStat ) session.getAttribute( StatCollector.STAT_ID
) )
+                total += ( ( IoSessionStat ) session.getAttribute( StatCollector.KEY ) )
                     .getMessageWrittenThroughput();
             }
         }
@@ -164,7 +164,7 @@
             for ( Iterator iter2 = service.getManagedSessions( element ).iterator(); iter2.hasNext();
)
             {
                 IoSession session = ( IoSession ) iter2.next();
-                total += ( ( IoSessionStat ) session.getAttribute( StatCollector.STAT_ID
) )
+                total += ( ( IoSessionStat ) session.getAttribute( StatCollector.KEY ) )
                     .getByteReadThroughput();
                 count++;
             }
@@ -184,7 +184,7 @@
             for ( Iterator iter2 = service.getManagedSessions( element ).iterator(); iter2.hasNext();
)
             {
                 IoSession session = ( IoSession ) iter2.next();
-                total += ( ( IoSessionStat ) session.getAttribute( StatCollector.STAT_ID
) )
+                total += ( ( IoSessionStat ) session.getAttribute( StatCollector.KEY ) )
                     .getByteWrittenThroughput();
                 count++;
             }
@@ -204,7 +204,7 @@
             for ( Iterator iter2 = service.getManagedSessions( element ).iterator(); iter2.hasNext();
)
             {
                 IoSession session = ( IoSession ) iter2.next();
-                total += ( ( IoSessionStat ) session.getAttribute( StatCollector.STAT_ID
) )
+                total += ( ( IoSessionStat ) session.getAttribute( StatCollector.KEY ) )
                     .getMessageReadThroughput();
                 count++;
             }
@@ -224,7 +224,7 @@
             for ( Iterator iter2 = service.getManagedSessions( element ).iterator(); iter2.hasNext();
)
             {
                 IoSession session = ( IoSession ) iter2.next();
-                total += ( ( IoSessionStat ) session.getAttribute( StatCollector.STAT_ID
) )
+                total += ( ( IoSessionStat ) session.getAttribute( StatCollector.KEY ) )
                     .getMessageWrittenThroughput();
                 count++;
             }

Modified: directory/trunks/mina/integration-jmx/src/main/java/org/apache/mina/integration/jmx/IoSessionManager.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/integration-jmx/src/main/java/org/apache/mina/integration/jmx/IoSessionManager.java?view=diff&rev=441336&r1=441335&r2=441336
==============================================================================
--- directory/trunks/mina/integration-jmx/src/main/java/org/apache/mina/integration/jmx/IoSessionManager.java
(original)
+++ directory/trunks/mina/integration-jmx/src/main/java/org/apache/mina/integration/jmx/IoSessionManager.java
Thu Sep  7 19:11:33 2006
@@ -219,7 +219,7 @@
 
     public float getByteReadThroughtput()
     {
-        IoSessionStat stats=(IoSessionStat)session.getAttribute(StatCollector.STAT_ID);
+        IoSessionStat stats=(IoSessionStat)session.getAttribute(StatCollector.KEY);
         if(stats==null)
             return Float.NaN;
         else
@@ -229,7 +229,7 @@
 
     public float getByteWrittenThroughtput()
     {
-        IoSessionStat stats=(IoSessionStat)session.getAttribute(StatCollector.STAT_ID);
+        IoSessionStat stats=(IoSessionStat)session.getAttribute(StatCollector.KEY);
         if(stats==null)
             return Float.NaN;
         else
@@ -239,7 +239,7 @@
 
     public float getMessageReadThroughtput()
     {
-        IoSessionStat stats=(IoSessionStat)session.getAttribute(StatCollector.STAT_ID);
+        IoSessionStat stats=(IoSessionStat)session.getAttribute(StatCollector.KEY);
         if(stats==null)
             return Float.NaN;
         else
@@ -249,7 +249,7 @@
 
     public float getMessageWrittenThroughtput()
     {
-        IoSessionStat stats=(IoSessionStat)session.getAttribute(StatCollector.STAT_ID);
+        IoSessionStat stats=(IoSessionStat)session.getAttribute(StatCollector.KEY);
         if(stats==null)
             return Float.NaN;
         else



Mime
View raw message