Author: trustin
Date: Tue Jan 30 01:25:25 2007
New Revision: 501353
URL: http://svn.apache.org/viewvc?view=rev&rev=501353
Log:
Related issue: DIRMINA-331 (StatCollector is not thread safe and some stats are
being mixed up)
* Added more generics support to IoService
* Fixed incorrect calculation of bytesReadThroughput
Modified:
mina/branches/1.0/core/src/main/java/org/apache/mina/management/StatCollector.java
mina/branches/1.1/core/src/main/java/org/apache/mina/management/StatCollector.java
mina/trunk/core/src/main/java/org/apache/mina/common/IoService.java
mina/trunk/core/src/main/java/org/apache/mina/common/support/BaseIoService.java
mina/trunk/core/src/main/java/org/apache/mina/common/support/DelegatedIoAcceptor.java
mina/trunk/core/src/main/java/org/apache/mina/common/support/DelegatedIoConnector.java
mina/trunk/core/src/main/java/org/apache/mina/common/support/IoServiceListenerSupport.java
mina/trunk/core/src/main/java/org/apache/mina/management/StatCollector.java
Modified:
mina/branches/1.0/core/src/main/java/org/apache/mina/management/StatCollector.java
URL:
http://svn.apache.org/viewvc/mina/branches/1.0/core/src/main/java/org/apache/mina/management/StatCollector.java?view=diff&rev=501353&r1=501352&r2=501353
==============================================================================
---
mina/branches/1.0/core/src/main/java/org/apache/mina/management/StatCollector.java
(original)
+++
mina/branches/1.0/core/src/main/java/org/apache/mina/management/StatCollector.java
Tue Jan 30 01:25:25 2007
@@ -202,37 +202,36 @@
private void addSession( IoSession session )
{
- synchronized (this)
- {
- totalProcessedSessions += 1;
- polledSessions.add( session );
- IoSessionStat sessionStats = new IoSessionStat();
- sessionStats.lastPollingTime = System.currentTimeMillis();
+ synchronized (this)
+ {
+ totalProcessedSessions += 1;
+ polledSessions.add( session );
+ IoSessionStat sessionStats = new IoSessionStat();
+ sessionStats.lastPollingTime = System.currentTimeMillis();
session.setAttribute( KEY, sessionStats );
- }
+ }
}
private void removeSession( IoSession session )
{
- synchronized (this)
- {
-
- // remove the session from the list of polled sessions
- polledSessions.remove( session );
-
- // add the bytes processed between last polling and session
closing
- // prevent non seen byte with non-connected protocols like HTTP
and datagrams
- IoSessionStat sessStat = ( IoSessionStat )
session.getAttribute( KEY );
-
- // computing with time between polling and closing
- bytesReadThroughput += ( (float) (session.getReadBytes() -
sessStat.lastByteRead) ) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
- bytesWrittenThroughput += ( (float) (session.getWrittenBytes()
- sessStat.lastByteWrite) ) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
- msgReadThroughput += ( (float) (session.getReadMessages() -
sessStat.lastMessageRead) ) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
- msgWrittenThroughput += ( (float) (session.getWrittenMessages()
- sessStat.lastMessageWrite) ) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
-
+ synchronized (this)
+ {
+ // remove the session from the list of polled sessions
+ polledSessions.remove( session );
+
+ // add the bytes processed between last polling and session closing
+ // prevent non seen byte with non-connected protocols like HTTP
and datagrams
+ IoSessionStat sessStat = ( IoSessionStat ) session.getAttribute(
KEY );
+
+ // computing with time between polling and closing
+ bytesReadThroughput += (session.getReadBytes() -
sessStat.lastByteRead) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
+ bytesWrittenThroughput += (session.getWrittenBytes() -
sessStat.lastByteWrite) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
+ msgReadThroughput += (session.getReadMessages() -
sessStat.lastMessageRead) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
+ msgWrittenThroughput += (session.getWrittenMessages() -
sessStat.lastMessageWrite) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
+
session.removeAttribute( KEY );
-
- }
+
+ }
}
@@ -242,34 +241,34 @@
*/
public long getTotalProcessedSessions()
{
- return totalProcessedSessions;
+ return totalProcessedSessions;
+ }
+
+ public float getBytesReadThroughput()
+ {
+ return bytesReadThroughput;
+ }
+
+ public float getBytesWrittenThroughput()
+ {
+ return bytesWrittenThroughput;
+ }
+
+ public float getMsgReadThroughput()
+ {
+ return msgReadThroughput;
}
- public float getBytesReadThroughput()
- {
- return bytesReadThroughput;
- }
-
- public float getBytesWrittenThroughput()
- {
- return bytesWrittenThroughput;
- }
-
- public float getMsgReadThroughput()
- {
- return msgReadThroughput;
- }
-
- public float getMsgWrittenThroughput()
- {
- return msgWrittenThroughput;
- }
-
- public long getSessionCount()
- {
- return polledSessions.size();
- }
-
+ public float getMsgWrittenThroughput()
+ {
+ return msgWrittenThroughput;
+ }
+
+ public long getSessionCount()
+ {
+ return polledSessions.size();
+ }
+
private class Worker extends Thread
{
@@ -277,7 +276,7 @@
private Worker()
{
- super( "StatCollectorWorker-"+id );
+ super( "StatCollectorWorker-" + id );
}
public void run()
@@ -311,8 +310,8 @@
for ( Iterator iter = polledSessions.iterator();
iter.hasNext(); )
{
-
- // upadating individual session statistics
+
+ // upadating individual session statistics
IoSession session = ( IoSession ) iter.next();
IoSessionStat sessStat = ( IoSessionStat )
session.getAttribute( KEY );
@@ -335,7 +334,7 @@
msgWrittenThroughput = tmpMsgWrittenThroughput;
msgReadThroughput = tmpMsgReadThroughput;
bytesWrittenThroughput = tmpBytesWrittenThroughput;
- bytesReadThroughput = tmpMsgWrittenThroughput;
+ bytesReadThroughput = tmpBytesReadThroughput;
sessStat.lastPollingTime = System.currentTimeMillis();
}
Modified:
mina/branches/1.1/core/src/main/java/org/apache/mina/management/StatCollector.java
URL:
http://svn.apache.org/viewvc/mina/branches/1.1/core/src/main/java/org/apache/mina/management/StatCollector.java?view=diff&rev=501353&r1=501352&r2=501353
==============================================================================
---
mina/branches/1.1/core/src/main/java/org/apache/mina/management/StatCollector.java
(original)
+++
mina/branches/1.1/core/src/main/java/org/apache/mina/management/StatCollector.java
Tue Jan 30 01:25:25 2007
@@ -202,37 +202,36 @@
private void addSession( IoSession session )
{
- synchronized (this)
- {
- totalProcessedSessions += 1;
- polledSessions.add( session );
- IoSessionStat sessionStats = new IoSessionStat();
+ synchronized (this)
+ {
+ totalProcessedSessions += 1;
+ polledSessions.add( session );
+ IoSessionStat sessionStats = new IoSessionStat();
sessionStats.lastPollingTime = System.currentTimeMillis();
session.setAttribute( KEY, sessionStats );
- }
+ }
}
private void removeSession( IoSession session )
{
- synchronized (this)
- {
-
- // remove the session from the list of polled sessions
- polledSessions.remove( session );
-
- // add the bytes processed between last polling and session
closing
- // prevent non seen byte with non-connected protocols like HTTP
and datagrams
- IoSessionStat sessStat = ( IoSessionStat )
session.getAttribute( KEY );
-
- // computing with time between polling and closing
- bytesReadThroughput += ( (float) (session.getReadBytes() -
sessStat.lastByteRead) ) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
- bytesWrittenThroughput += ( (float) (session.getWrittenBytes()
- sessStat.lastByteWrite) ) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
- msgReadThroughput += ( (float) (session.getReadMessages() -
sessStat.lastMessageRead) ) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
- msgWrittenThroughput += ( (float) (session.getWrittenMessages()
- sessStat.lastMessageWrite) ) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
-
+ synchronized (this)
+ {
+ // remove the session from the list of polled sessions
+ polledSessions.remove( session );
+
+ // add the bytes processed between last polling and session closing
+ // prevent non seen byte with non-connected protocols like HTTP
and datagrams
+ IoSessionStat sessStat = ( IoSessionStat ) session.getAttribute(
KEY );
+
+ // computing with time between polling and closing
+ bytesReadThroughput += (session.getReadBytes() -
sessStat.lastByteRead) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
+ bytesWrittenThroughput += (session.getWrittenBytes() -
sessStat.lastByteWrite) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
+ msgReadThroughput += (session.getReadMessages() -
sessStat.lastMessageRead) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
+ msgWrittenThroughput += (session.getWrittenMessages() -
sessStat.lastMessageWrite) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
+
session.removeAttribute( KEY );
-
- }
+
+ }
}
@@ -242,34 +241,34 @@
*/
public long getTotalProcessedSessions()
{
- return totalProcessedSessions;
+ return totalProcessedSessions;
+ }
+
+ public float getBytesReadThroughput()
+ {
+ return bytesReadThroughput;
+ }
+
+ public float getBytesWrittenThroughput()
+ {
+ return bytesWrittenThroughput;
}
- public float getBytesReadThroughput()
- {
- return bytesReadThroughput;
- }
-
- public float getBytesWrittenThroughput()
- {
- return bytesWrittenThroughput;
- }
-
- public float getMsgReadThroughput()
- {
- return msgReadThroughput;
- }
-
- public float getMsgWrittenThroughput()
- {
- return msgWrittenThroughput;
- }
-
- public long getSessionCount()
- {
- return polledSessions.size();
- }
-
+ public float getMsgReadThroughput()
+ {
+ return msgReadThroughput;
+ }
+
+ public float getMsgWrittenThroughput()
+ {
+ return msgWrittenThroughput;
+ }
+
+ public long getSessionCount()
+ {
+ return polledSessions.size();
+ }
+
private class Worker extends Thread
{
@@ -277,7 +276,7 @@
private Worker()
{
- super( "StatCollectorWorker-"+id );
+ super( "StatCollectorWorker-" + id );
}
public void run()
@@ -311,8 +310,8 @@
for ( Iterator iter = polledSessions.iterator();
iter.hasNext(); )
{
-
- // upadating individual session statistics
+
+ // upadating individual session statistics
IoSession session = ( IoSession ) iter.next();
IoSessionStat sessStat = ( IoSessionStat )
session.getAttribute( KEY );
@@ -331,11 +330,11 @@
sessStat.messageWrittenThroughput = (
session.getWrittenMessages() - sessStat.lastMessageWrite )
/ ( pollingInterval / 1000f );
tmpMsgWrittenThroughput +=
sessStat.messageWrittenThroughput;
-
+
msgWrittenThroughput = tmpMsgWrittenThroughput;
msgReadThroughput = tmpMsgReadThroughput;
bytesWrittenThroughput = tmpBytesWrittenThroughput;
- bytesReadThroughput = tmpMsgWrittenThroughput;
+ bytesReadThroughput = tmpBytesReadThroughput;
sessStat.lastPollingTime = System.currentTimeMillis();
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/common/IoService.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/IoService.java?view=diff&rev=501353&r1=501352&r2=501353
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/common/IoService.java
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/common/IoService.java Tue Jan
30 01:25:25 2007
@@ -67,7 +67,7 @@
* @throws UnsupportedOperationException if this operation isn't supported
* for the particular transport type implemented by this [EMAIL
PROTECTED] IoService}.
*/
- Set getManagedSessions();
+ Set<IoSession> getManagedSessions();
/**
* Returns the default configuration of the new [EMAIL PROTECTED]
IoSession}s
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/support/BaseIoService.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/support/BaseIoService.java?view=diff&rev=501353&r1=501352&r2=501353
==============================================================================
---
mina/trunk/core/src/main/java/org/apache/mina/common/support/BaseIoService.java
(original)
+++
mina/trunk/core/src/main/java/org/apache/mina/common/support/BaseIoService.java
Tue Jan 30 01:25:25 2007
@@ -26,6 +26,7 @@
import org.apache.mina.common.IoHandler;
import org.apache.mina.common.IoService;
import org.apache.mina.common.IoServiceListener;
+import org.apache.mina.common.IoSession;
import org.apache.mina.common.IoSessionConfig;
/**
@@ -99,7 +100,7 @@
getListeners().remove( listener );
}
- public Set getManagedSessions()
+ public Set<IoSession> getManagedSessions()
{
return getListeners().getManagedSessions();
}
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/support/DelegatedIoAcceptor.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/support/DelegatedIoAcceptor.java?view=diff&rev=501353&r1=501352&r2=501353
==============================================================================
---
mina/trunk/core/src/main/java/org/apache/mina/common/support/DelegatedIoAcceptor.java
(original)
+++
mina/trunk/core/src/main/java/org/apache/mina/common/support/DelegatedIoAcceptor.java
Tue Jan 30 01:25:25 2007
@@ -123,7 +123,7 @@
return delegate.getHandler();
}
- public Set getManagedSessions()
+ public Set<IoSession> getManagedSessions()
{
return delegate.getManagedSessions();
}
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/support/DelegatedIoConnector.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/support/DelegatedIoConnector.java?view=diff&rev=501353&r1=501352&r2=501353
==============================================================================
---
mina/trunk/core/src/main/java/org/apache/mina/common/support/DelegatedIoConnector.java
(original)
+++
mina/trunk/core/src/main/java/org/apache/mina/common/support/DelegatedIoConnector.java
Tue Jan 30 01:25:25 2007
@@ -28,6 +28,7 @@
import org.apache.mina.common.IoFilterChainBuilder;
import org.apache.mina.common.IoHandler;
import org.apache.mina.common.IoServiceListener;
+import org.apache.mina.common.IoSession;
import org.apache.mina.common.IoSessionConfig;
import org.apache.mina.common.TransportType;
@@ -112,7 +113,7 @@
return delegate.getHandler();
}
- public Set getManagedSessions()
+ public Set<IoSession> getManagedSessions()
{
return delegate.getManagedSessions();
}
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/support/IoServiceListenerSupport.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/support/IoServiceListenerSupport.java?view=diff&rev=501353&r1=501352&r2=501353
==============================================================================
---
mina/trunk/core/src/main/java/org/apache/mina/common/support/IoServiceListenerSupport.java
(original)
+++
mina/trunk/core/src/main/java/org/apache/mina/common/support/IoServiceListenerSupport.java
Tue Jan 30 01:25:25 2007
@@ -93,7 +93,7 @@
}
}
- public Set getManagedSessions()
+ public Set<IoSession> getManagedSessions()
{
synchronized( managedSessions )
{
Modified:
mina/trunk/core/src/main/java/org/apache/mina/management/StatCollector.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/management/StatCollector.java?view=diff&rev=501353&r1=501352&r2=501353
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/management/StatCollector.java
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/management/StatCollector.java
Tue Jan 30 01:25:25 2007
@@ -43,7 +43,7 @@
* By default the [EMAIL PROTECTED] StatCollector} is polling the sessions
every 5 seconds. You can
* give a different polling time using a second constructor.
*
- * @author The Apache MINA Project ([email protected])
+ * @author The Apache Directory Project ([email protected])
* @version $Rev$, $Date$
*/
public class StatCollector
@@ -70,7 +70,7 @@
private float msgWrittenThroughput = 0f;
private float msgReadThroughput = 0f;
private float bytesWrittenThroughput = 0f;
- private float bytesReadThroughput = 0f;
+ private float bytesReadThroughput = 0f;
private final IoServiceListener serviceListener = new IoServiceListener()
{
@@ -127,10 +127,10 @@
// add all current sessions
polledSessions = new ArrayList<IoSession>();
-
- for ( Iterator iter = service.getManagedSessions().iterator();
iter.hasNext(); )
+
+ for ( Iterator<IoSession> iter =
service.getManagedSessions().iterator(); iter.hasNext(); )
{
- addSession( ( IoSession ) iter.next() );
+ addSession( iter.next() );
}
// listen for new ones
@@ -191,37 +191,36 @@
private void addSession( IoSession session )
{
- synchronized (this)
- {
- totalProcessedSessions += 1;
- polledSessions.add( session );
-
- IoSessionStat sessionStats = new IoSessionStat();
- sessionStats.lastPollingTime = System.currentTimeMillis();
- session.setAttribute( KEY, sessionStats );
- }
+ synchronized (this)
+ {
+ totalProcessedSessions += 1;
+ polledSessions.add( session );
+ IoSessionStat sessionStats = new IoSessionStat();
+ sessionStats.lastPollingTime = System.currentTimeMillis();
+ session.setAttribute( KEY, sessionStats );
+ }
}
private void removeSession( IoSession session )
{
- synchronized (this)
- {
-
- // remove the session from the list of polled sessions
- polledSessions.remove( session );
-
- // add the bytes processed between last polling and session closing
- // prevent non seen byte with non-connected protocols like HTTP and
datagrams
- IoSessionStat sessStat = ( IoSessionStat ) session.getAttribute(
KEY );
-
- // computing with time between polling and closing
- bytesReadThroughput += (session.getReadBytes() -
sessStat.lastByteRead) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
- bytesWrittenThroughput += (session.getWrittenBytes() -
sessStat.lastByteWrite) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
- msgReadThroughput += (session.getReadMessages() -
sessStat.lastMessageRead) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
- msgWrittenThroughput += (session.getWrittenMessages() -
sessStat.lastMessageWrite) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
-
+ synchronized (this)
+ {
+ // remove the session from the list of polled sessions
+ polledSessions.remove( session );
+
+ // add the bytes processed between last polling and session closing
+ // prevent non seen byte with non-connected protocols like HTTP
and datagrams
+ IoSessionStat sessStat = ( IoSessionStat ) session.getAttribute(
KEY );
+
+ // computing with time between polling and closing
+ bytesReadThroughput += (session.getReadBytes() -
sessStat.lastByteRead) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
+ bytesWrittenThroughput += (session.getWrittenBytes() -
sessStat.lastByteWrite) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
+ msgReadThroughput += (session.getReadMessages() -
sessStat.lastMessageRead) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
+ msgWrittenThroughput += (session.getWrittenMessages() -
sessStat.lastMessageWrite) / ( ( System.currentTimeMillis() -
sessStat.lastPollingTime ) /1000f ) ;
+
session.removeAttribute( KEY );
- }
+
+ }
}
@@ -231,34 +230,34 @@
*/
public long getTotalProcessedSessions()
{
- return totalProcessedSessions;
+ return totalProcessedSessions;
+ }
+
+ public float getBytesReadThroughput()
+ {
+ return bytesReadThroughput;
+ }
+
+ public float getBytesWrittenThroughput()
+ {
+ return bytesWrittenThroughput;
+ }
+
+ public float getMsgReadThroughput()
+ {
+ return msgReadThroughput;
+ }
+
+ public float getMsgWrittenThroughput()
+ {
+ return msgWrittenThroughput;
}
- public float getBytesReadThroughput()
- {
- return bytesReadThroughput;
- }
-
- public float getBytesWrittenThroughput()
- {
- return bytesWrittenThroughput;
- }
-
- public float getMsgReadThroughput()
- {
- return msgReadThroughput;
- }
-
- public float getMsgWrittenThroughput()
- {
- return msgWrittenThroughput;
- }
-
- public long getSessionCount()
- {
- return polledSessions.size();
- }
-
+ public long getSessionCount()
+ {
+ return polledSessions.size();
+ }
+
private class Worker extends Thread
{
@@ -266,7 +265,7 @@
private Worker()
{
- super( "StatCollectorWorker-"+id );
+ super( "StatCollectorWorker-" + id );
}
public void run()
@@ -293,7 +292,6 @@
{
}
-
float tmpMsgWrittenThroughput = 0f;
float tmpMsgReadThroughput = 0f;
float tmpBytesWrittenThroughput = 0f;
@@ -301,8 +299,8 @@
for ( Iterator iter = polledSessions.iterator();
iter.hasNext(); )
{
-
- // upadating individual session statistics
+
+ // upadating individual session statistics
IoSession session = ( IoSession ) iter.next();
IoSessionStat sessStat = ( IoSessionStat )
session.getAttribute( KEY );
@@ -321,11 +319,11 @@
sessStat.messageWrittenThroughput = (
session.getWrittenMessages() - sessStat.lastMessageWrite )
/ ( pollingInterval / 1000f );
tmpMsgWrittenThroughput +=
sessStat.messageWrittenThroughput;
-
+
msgWrittenThroughput = tmpMsgWrittenThroughput;
msgReadThroughput = tmpMsgReadThroughput;
bytesWrittenThroughput = tmpBytesWrittenThroughput;
- bytesReadThroughput = tmpMsgWrittenThroughput;
+ bytesReadThroughput = tmpBytesReadThroughput;
sessStat.lastPollingTime = System.currentTimeMillis();
}