Author: trustin
Date: Thu Nov 15 20:34:21 2007
New Revision: 595545
URL: http://svn.apache.org/viewvc?rev=595545&view=rev
Log:
* Removed JMX classes temporarilly - will be rewritten next week
* Added many more statistics properties to IoService
Removed:
mina/trunk/core/src/main/java/org/apache/mina/management/
mina/trunk/integration-jmx/src/main/java/org/apache/mina/integration/jmx/IoServiceManager.java
mina/trunk/integration-jmx/src/main/java/org/apache/mina/integration/jmx/IoServiceManagerMBean.java
mina/trunk/integration-jmx/src/main/java/org/apache/mina/integration/jmx/IoSessionManager.java
mina/trunk/integration-jmx/src/main/java/org/apache/mina/integration/jmx/IoSessionManagerMBean.java
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoProcessor.java
mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoService.java
mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoSession.java
mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoSessionConfig.java
mina/trunk/core/src/main/java/org/apache/mina/common/DefaultIoFilterChain.java
mina/trunk/core/src/main/java/org/apache/mina/common/IdleStatusChecker.java
mina/trunk/core/src/main/java/org/apache/mina/common/IoService.java
mina/trunk/core/src/main/java/org/apache/mina/common/IoServiceListener.java
mina/trunk/core/src/main/java/org/apache/mina/common/IoServiceListenerSupport.java
mina/trunk/core/src/main/java/org/apache/mina/common/IoSession.java
mina/trunk/core/src/main/java/org/apache/mina/common/IoSessionConfig.java
mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.java
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoProcessor.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoProcessor.java?rev=595545&r1=595544&r2=595545&view=diff
==============================================================================
---
mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoProcessor.java
(original)
+++
mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoProcessor.java
Thu Nov 15 20:34:21 2007
@@ -372,7 +372,7 @@
long currentTime = System.currentTimeMillis();
if (currentTime - lastIdleCheckTime >= 1000) {
lastIdleCheckTime = currentTime;
- IdleStatusChecker.notifyIdleSessions(allSessions(), currentTime);
+ IdleStatusChecker.notifyIdleness(allSessions(), currentTime);
}
}
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoService.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoService.java?rev=595545&r1=595544&r2=595545&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoService.java
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoService.java
Thu Nov 15 20:34:21 2007
@@ -52,14 +52,42 @@
private final IoServiceListenerSupport listeners;
private volatile boolean disposed;
- private volatile long activationTime;
private final AtomicLong readBytes = new AtomicLong();
private final AtomicLong writtenBytes = new AtomicLong();
private final AtomicLong readMessages = new AtomicLong();
private final AtomicLong writtenMessages = new AtomicLong();
+ private long lastReadTime;
+ private long lastWriteTime;
+
private final AtomicLong scheduledWriteBytes = new AtomicLong();
private final AtomicLong scheduledWriteMessages = new AtomicLong();
+ private final Object throughputCalculationLock = new Object();
+ private int throughputCalculationInterval = 3;
+
+ private long lastThroughputCalculationTime;
+ private long lastReadBytes;
+ private long lastWrittenBytes;
+ private long lastReadMessages;
+ private long lastWrittenMessages;
+ private double readBytesThroughput;
+ private double writtenBytesThroughput;
+ private double readMessagesThroughput;
+ private double writtenMessagesThroughput;
+
+ private final Object idlenessCheckLock = new Object();
+ private int idleTimeForRead;
+ private int idleTimeForWrite;
+ private int idleTimeForBoth;
+
+ private int idleCountForBoth;
+ private int idleCountForRead;
+ private int idleCountForWrite;
+
+ private long lastIdleTimeForBoth;
+ private long lastIdleTimeForRead;
+ private long lastIdleTimeForWrite;
+
/**
* The default [EMAIL PROTECTED] IoSessionConfig} which will be used to
configure new sessions.
*/
@@ -136,6 +164,18 @@
return getListeners().getManagedSessions();
}
+ public long getCumulativeManagedSessionCount() {
+ return getListeners().getCumulativeManagedSessionCount();
+ }
+
+ public int getLargestManagedSessionCount() {
+ return getListeners().getLargestManagedSessionCount();
+ }
+
+ public int getManagedSessionCount() {
+ return getListeners().getManagedSessionCount();
+ }
+
public IoHandler getHandler() {
return handler;
}
@@ -181,18 +221,84 @@
return readBytes.get();
}
- protected void increaseReadBytes(long increment) {
+ protected void increaseReadBytes(long increment, long currentTime) {
readBytes.addAndGet(increment);
+ lastReadTime = currentTime;
+ idleCountForBoth = 0;
+ idleCountForRead = 0;
}
public long getReadMessages() {
return readMessages.get();
}
- protected void increaseReadMessages() {
+ protected void increaseReadMessages(long currentTime) {
readMessages.incrementAndGet();
+ lastReadTime = currentTime;
+ idleCountForBoth = 0;
+ idleCountForRead = 0;
+ }
+
+ public int getThroughputCalculationInterval() {
+ return throughputCalculationInterval;
+ }
+
+ public void setThroughputCalculationInterval(int
throughputCalculationInterval) {
+ if (throughputCalculationInterval < 0) {
+ throw new IllegalArgumentException(
+ "throughputCalculationInterval: " +
throughputCalculationInterval);
+ }
+
+ this.throughputCalculationInterval = throughputCalculationInterval;
+ }
+
+ public long getThroughputCalculationIntervalInMillis() {
+ return throughputCalculationInterval * 1000L;
+ }
+
+ public double getReadBytesThroughput() {
+ return readBytesThroughput;
+ }
+
+ public double getWrittenBytesThroughput() {
+ return writtenBytesThroughput;
}
+ public double getReadMessagesThroughput() {
+ return readMessagesThroughput;
+ }
+
+ public double getWrittenMessagesThroughput() {
+ return writtenMessagesThroughput;
+ }
+
+ private void updateThroughput(long currentTime) {
+ synchronized (throughputCalculationLock) {
+ int interval = (int) (currentTime - lastThroughputCalculationTime);
+ long minInterval = getThroughputCalculationIntervalInMillis();
+ if (minInterval == 0 || interval < minInterval) {
+ return;
+ }
+
+ long readBytes = this.readBytes.get();
+ long writtenBytes = this.writtenBytes.get();
+ long readMessages = this.readMessages.get();
+ long writtenMessages = this.writtenMessages.get();
+
+ readBytesThroughput = (readBytes - lastReadBytes) * 1000.0 /
interval;
+ writtenBytesThroughput = (writtenBytes - lastWrittenBytes) *
1000.0 / interval;
+ readMessagesThroughput = (readMessages - lastReadMessages) *
1000.0 / interval;
+ writtenMessagesThroughput = (writtenMessages -
lastWrittenMessages) * 1000.0 / interval;
+
+ lastReadBytes = readBytes;
+ lastWrittenBytes = writtenBytes;
+ lastReadMessages = readMessages;
+ lastWrittenMessages = writtenMessages;
+
+ lastThroughputCalculationTime = currentTime;
+ }
+ }
+
public long getScheduledWriteBytes() {
return scheduledWriteBytes.get();
}
@@ -214,29 +320,179 @@
}
public long getActivationTime() {
- return activationTime;
+ return getListeners().getActivationTime();
+ }
+
+ public long getLastIoTime() {
+ return Math.max(lastReadTime, lastWriteTime);
+ }
+
+ public long getLastReadTime() {
+ return lastReadTime;
}
- protected void setActivationTime(long activationTime) {
- this.activationTime = activationTime;
+ public long getLastWriteTime() {
+ return lastWriteTime;
}
public long getWrittenBytes() {
return writtenBytes.get();
}
- protected void increaseWrittenBytes(long increment) {
+ protected void increaseWrittenBytes(long increment, long currentTime) {
writtenBytes.addAndGet(increment);
+ lastWriteTime = currentTime;
+ idleCountForBoth = 0;
+ idleCountForWrite = 0;
}
public long getWrittenMessages() {
return writtenMessages.get();
}
- protected void increaseWrittenMessages() {
+ protected void increaseWrittenMessages(long currentTime) {
writtenMessages.incrementAndGet();
+ lastWriteTime = currentTime;
+ idleCountForBoth = 0;
+ idleCountForWrite = 0;
+ }
+
+ public int getIdleTime(IdleStatus status) {
+ if (status == IdleStatus.BOTH_IDLE) {
+ return idleTimeForBoth;
+ }
+
+ if (status == IdleStatus.READER_IDLE) {
+ return idleTimeForRead;
+ }
+
+ if (status == IdleStatus.WRITER_IDLE) {
+ return idleTimeForWrite;
+ }
+
+ throw new IllegalArgumentException("Unknown idle status: " + status);
+ }
+
+ public long getIdleTimeInMillis(IdleStatus status) {
+ return getIdleTime(status) * 1000L;
}
+ public void setIdleTime(IdleStatus status, int idleTime) {
+ if (idleTime < 0) {
+ throw new IllegalArgumentException("Illegal idle time: " +
idleTime);
+ }
+
+ if (status == IdleStatus.BOTH_IDLE) {
+ idleTimeForBoth = idleTime;
+ } else if (status == IdleStatus.READER_IDLE) {
+ idleTimeForRead = idleTime;
+ } else if (status == IdleStatus.WRITER_IDLE) {
+ idleTimeForWrite = idleTime;
+ } else {
+ throw new IllegalArgumentException("Unknown idle status: " +
status);
+ }
+ }
+
+ public boolean isIdle(IdleStatus status) {
+ if (status == IdleStatus.BOTH_IDLE) {
+ return idleCountForBoth > 0;
+ }
+
+ if (status == IdleStatus.READER_IDLE) {
+ return idleCountForRead > 0;
+ }
+
+ if (status == IdleStatus.WRITER_IDLE) {
+ return idleCountForWrite > 0;
+ }
+
+ throw new IllegalArgumentException("Unknown idle status: " + status);
+ }
+
+ public int getIdleCount(IdleStatus status) {
+ if (status == IdleStatus.BOTH_IDLE) {
+ return idleCountForBoth;
+ }
+
+ if (status == IdleStatus.READER_IDLE) {
+ return idleCountForRead;
+ }
+
+ if (status == IdleStatus.WRITER_IDLE) {
+ return idleCountForWrite;
+ }
+
+ throw new IllegalArgumentException("Unknown idle status: " + status);
+ }
+
+ public long getLastIdleTime(IdleStatus status) {
+ if (status == IdleStatus.BOTH_IDLE) {
+ return lastIdleTimeForBoth;
+ }
+
+ if (status == IdleStatus.READER_IDLE) {
+ return lastIdleTimeForRead;
+ }
+
+ if (status == IdleStatus.WRITER_IDLE) {
+ return lastIdleTimeForWrite;
+ }
+
+ throw new IllegalArgumentException("Unknown idle status: " + status);
+ }
+
+ private void increaseIdleCount(IdleStatus status, long currentTime) {
+ if (status == IdleStatus.BOTH_IDLE) {
+ idleCountForBoth++;
+ lastIdleTimeForBoth = currentTime;
+ } else if (status == IdleStatus.READER_IDLE) {
+ idleCountForRead++;
+ lastIdleTimeForRead = currentTime;
+ } else if (status == IdleStatus.WRITER_IDLE) {
+ idleCountForWrite++;
+ lastIdleTimeForWrite = currentTime;
+ } else {
+ throw new IllegalArgumentException("Unknown idle status: " +
status);
+ }
+ }
+
+ protected void notifyIdleness(long currentTime) {
+ updateThroughput(currentTime);
+
+ synchronized (idlenessCheckLock) {
+ notifyIdleness(
+ currentTime,
+ getIdleTimeInMillis(IdleStatus.BOTH_IDLE),
+ IdleStatus.BOTH_IDLE, Math.max(
+ getLastIoTime(),
+ getLastIdleTime(IdleStatus.BOTH_IDLE)));
+
+ notifyIdleness(
+ currentTime,
+ getIdleTimeInMillis(IdleStatus.READER_IDLE),
+ IdleStatus.READER_IDLE, Math.max(
+ getLastReadTime(),
+ getLastIdleTime(IdleStatus.READER_IDLE)));
+
+ notifyIdleness(
+ currentTime,
+ getIdleTimeInMillis(IdleStatus.WRITER_IDLE),
+ IdleStatus.WRITER_IDLE, Math.max(
+ getLastWriteTime(),
+ getLastIdleTime(IdleStatus.WRITER_IDLE)));
+ }
+ }
+
+ private void notifyIdleness(
+ long currentTime, long idleTime, IdleStatus status, long
lastIoTime) {
+ if (idleTime > 0 && lastIoTime != 0
+ && currentTime - lastIoTime >= idleTime) {
+ increaseIdleCount(status, currentTime);
+ getListeners().fireServiceIdle(status);
+ }
+ }
+
+
public Set<WriteFuture> broadcast(Object message) {
// Convert to Set. We do not return a List here because only the
// direct caller of MessageBroadcaster knows the order of write
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoSession.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoSession.java?rev=595545&r1=595544&r2=595545&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoSession.java
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoSession.java
Thu Nov 15 20:34:21 2007
@@ -88,6 +88,16 @@
private long writtenMessages;
private long lastReadTime;
private long lastWriteTime;
+
+ private long lastThroughputCalculationTime;
+ private long lastReadBytes;
+ private long lastWrittenBytes;
+ private long lastReadMessages;
+ private long lastWrittenMessages;
+ private double readBytesThroughput;
+ private double writtenBytesThroughput;
+ private double readMessagesThroughput;
+ private double writtenMessagesThroughput;
private int idleCountForBoth;
private int idleCountForRead;
@@ -100,9 +110,10 @@
private boolean deferDecreaseReadBuffer = true;
protected AbstractIoSession() {
- creationTime = lastReadTime = lastWriteTime =
+ creationTime = lastThroughputCalculationTime =
+ lastReadTime = lastWriteTime =
lastIdleTimeForBoth = lastIdleTimeForRead =
- lastIdleTimeForWrite = System.currentTimeMillis();
+ lastIdleTimeForWrite = System.currentTimeMillis();
closeFuture.addListener(SCHEDULED_COUNTER_RESETTER);
}
@@ -418,6 +429,42 @@
return writtenMessages;
}
+ public double getReadBytesThroughput() {
+ return readBytesThroughput;
+ }
+
+ public double getWrittenBytesThroughput() {
+ return writtenBytesThroughput;
+ }
+
+ public double getReadMessagesThroughput() {
+ return readMessagesThroughput;
+ }
+
+ public double getWrittenMessagesThroughput() {
+ return writtenMessagesThroughput;
+ }
+
+ protected void updateThroughput(long currentTime) {
+ int interval = (int) (currentTime - lastThroughputCalculationTime);
+ long minInterval =
getConfig().getThroughputCalculationIntervalInMillis();
+ if (minInterval == 0 || interval < minInterval) {
+ return;
+ }
+
+ readBytesThroughput = (readBytes - lastReadBytes) * 1000.0 / interval;
+ writtenBytesThroughput = (writtenBytes - lastWrittenBytes) * 1000.0 /
interval;
+ readMessagesThroughput = (readMessages - lastReadMessages) * 1000.0 /
interval;
+ writtenMessagesThroughput = (writtenMessages - lastWrittenMessages) *
1000.0 / interval;
+
+ lastReadBytes = readBytes;
+ lastWrittenBytes = writtenBytes;
+ lastReadMessages = readMessages;
+ lastWrittenMessages = writtenMessages;
+
+ lastThroughputCalculationTime = currentTime;
+ }
+
public long getScheduledWriteBytes() {
return scheduledWriteBytes.get();
}
@@ -426,61 +473,81 @@
return scheduledWriteMessages.get();
}
- protected void increaseReadBytes(long increment) {
+ protected void increaseReadBytesAndMessages(
+ Object message, long currentTime) {
+ if (message instanceof IoBuffer) {
+ IoBuffer b = (IoBuffer) message;
+ if (b.hasRemaining()) {
+ increaseReadBytes(((IoBuffer) message).remaining(),
currentTime);
+ } else {
+ increaseReadMessages(currentTime);
+ }
+ } else {
+ increaseReadMessages(currentTime);
+ }
+ }
+
+ private void increaseReadBytes(long increment, long currentTime) {
if (increment > 0) {
readBytes += increment;
- lastReadTime = System.currentTimeMillis();
+ lastReadTime = currentTime;
idleCountForBoth = 0;
idleCountForRead = 0;
if (getService() instanceof AbstractIoService) {
- ((AbstractIoService)
getService()).increaseReadBytes(increment);
+ ((AbstractIoService)
getService()).increaseReadBytes(increment, currentTime);
}
}
}
- protected void increaseReadMessages() {
+ private void increaseReadMessages(long currentTime) {
readMessages++;
- lastWriteTime = System.currentTimeMillis();
+ lastWriteTime = currentTime;
+ idleCountForBoth = 0;
+ idleCountForRead = 0;
if (getService() instanceof AbstractIoService) {
- ((AbstractIoService) getService()).increaseReadMessages();
+ ((AbstractIoService)
getService()).increaseReadMessages(currentTime);
}
}
- protected void increaseWrittenBytesAndMessages(WriteRequest request) {
+ protected void increaseWrittenBytesAndMessages(
+ WriteRequest request, long currentTime) {
+
Object message = request.getMessage();
if (message instanceof IoBuffer) {
IoBuffer b = (IoBuffer) message;
if (b.hasRemaining()) {
- increaseWrittenBytes(((IoBuffer) message).remaining());
+ increaseWrittenBytes(((IoBuffer) message).remaining(),
currentTime);
} else {
- increaseWrittenMessages();
+ increaseWrittenMessages(currentTime);
}
} else {
- increaseWrittenMessages();
+ increaseWrittenMessages(currentTime);
}
}
- protected void increaseWrittenBytes(long increment) {
- if (increment > 0) {
- writtenBytes += increment;
- lastWriteTime = System.currentTimeMillis();
- idleCountForBoth = 0;
- idleCountForWrite = 0;
+ private void increaseWrittenBytes(long increment, long currentTime) {
+ if (increment <= 0) {
+ return;
+ }
- if (getService() instanceof AbstractIoService) {
- ((AbstractIoService)
getService()).increaseWrittenBytes(increment);
- }
+ writtenBytes += increment;
+ lastWriteTime = currentTime;
+ idleCountForBoth = 0;
+ idleCountForWrite = 0;
- increaseScheduledWriteBytes(-increment);
+ if (getService() instanceof AbstractIoService) {
+ ((AbstractIoService) getService()).increaseWrittenBytes(increment,
currentTime);
}
+
+ increaseScheduledWriteBytes(-increment);
}
- protected void increaseWrittenMessages() {
+ private void increaseWrittenMessages(long currentTime) {
writtenMessages++;
- lastWriteTime = System.currentTimeMillis();
+ lastWriteTime = currentTime;
if (getService() instanceof AbstractIoService) {
- ((AbstractIoService) getService()).increaseWrittenMessages();
+ ((AbstractIoService)
getService()).increaseWrittenMessages(currentTime);
}
decreaseScheduledWriteMessages();
@@ -500,7 +567,7 @@
}
}
- protected void decreaseScheduledWriteMessages() {
+ private void decreaseScheduledWriteMessages() {
scheduledWriteMessages.decrementAndGet();
if (getService() instanceof AbstractIoService) {
((AbstractIoService)
getService()).decreaseScheduledWriteMessages();
@@ -621,16 +688,16 @@
throw new IllegalArgumentException("Unknown idle status: " + status);
}
- protected void increaseIdleCount(IdleStatus status) {
+ protected void increaseIdleCount(IdleStatus status, long currentTime) {
if (status == IdleStatus.BOTH_IDLE) {
idleCountForBoth++;
- lastIdleTimeForBoth = System.currentTimeMillis();
+ lastIdleTimeForBoth = currentTime;
} else if (status == IdleStatus.READER_IDLE) {
idleCountForRead++;
- lastIdleTimeForRead = System.currentTimeMillis();
+ lastIdleTimeForRead = currentTime;
} else if (status == IdleStatus.WRITER_IDLE) {
idleCountForWrite++;
- lastIdleTimeForWrite = System.currentTimeMillis();
+ lastIdleTimeForWrite = currentTime;
} else {
throw new IllegalArgumentException("Unknown idle status: " +
status);
}
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoSessionConfig.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoSessionConfig.java?rev=595545&r1=595544&r2=595545&view=diff
==============================================================================
---
mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoSessionConfig.java
(original)
+++
mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoSessionConfig.java
Thu Nov 15 20:34:21 2007
@@ -34,8 +34,9 @@
private int idleTimeForRead;
private int idleTimeForWrite;
private int idleTimeForBoth;
- private int writeTimeout;
+ private int writeTimeout = 60;
private boolean useReadOperation;
+ private int throughputCalculationInterval = 3;
protected AbstractIoSessionConfig() {
}
@@ -53,6 +54,7 @@
setIdleTime(IdleStatus.WRITER_IDLE,
config.getIdleTime(IdleStatus.WRITER_IDLE));
setWriteTimeout(config.getWriteTimeout());
setUseReadOperation(config.isUseReadOperation());
+
setThroughputCalculationInterval(config.getThroughputCalculationInterval());
doSetAll(config);
}
@@ -163,5 +165,22 @@
public void setUseReadOperation(boolean useReadOperation) {
this.useReadOperation = useReadOperation;
+ }
+
+ public int getThroughputCalculationInterval() {
+ return throughputCalculationInterval;
+ }
+
+ public void setThroughputCalculationInterval(int
throughputCalculationInterval) {
+ if (throughputCalculationInterval < 0) {
+ throw new IllegalArgumentException(
+ "throughputCalculationInterval: " +
throughputCalculationInterval);
+ }
+
+ this.throughputCalculationInterval = throughputCalculationInterval;
+ }
+
+ public long getThroughputCalculationIntervalInMillis() {
+ return throughputCalculationInterval * 1000L;
}
}
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/DefaultIoFilterChain.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/DefaultIoFilterChain.java?rev=595545&r1=595544&r2=595545&view=diff
==============================================================================
---
mina/trunk/core/src/main/java/org/apache/mina/common/DefaultIoFilterChain.java
(original)
+++
mina/trunk/core/src/main/java/org/apache/mina/common/DefaultIoFilterChain.java
Thu Nov 15 20:34:21 2007
@@ -385,10 +385,7 @@
}
public void fireMessageReceived(Object message) {
- if (message instanceof IoBuffer) {
- session.increaseReadBytes(((IoBuffer) message).remaining());
- }
-
+ session.increaseReadBytesAndMessages(message,
System.currentTimeMillis());
Entry head = this.head;
callNextMessageReceived(head, session, message);
}
@@ -404,7 +401,7 @@
}
public void fireMessageSent(WriteRequest request) {
- session.increaseWrittenBytesAndMessages(request);
+ session.increaseWrittenBytesAndMessages(request,
System.currentTimeMillis());
try {
request.getFuture().setWritten();
@@ -727,7 +724,6 @@
public void messageReceived(NextFilter nextFilter, IoSession session,
Object message) throws Exception {
AbstractIoSession s = (AbstractIoSession) session;
- s.increaseReadMessages();
try {
session.getHandler().messageReceived(s, message);
} finally {
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/IdleStatusChecker.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/IdleStatusChecker.java?rev=595545&r1=595544&r2=595545&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/common/IdleStatusChecker.java
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/common/IdleStatusChecker.java
Thu Nov 15 20:34:21 2007
@@ -87,11 +87,32 @@
*
* @param currentTime the current time (i.e. [EMAIL PROTECTED]
System#currentTimeMillis()})
*/
- public static void notifyIdleSessions(Iterator<? extends IoSession>
sessions, long currentTime) {
+ public static void notifyIdleness(Iterator<? extends IoSession> sessions,
long currentTime) {
+ IoSession s = null;
while (sessions.hasNext()) {
- IoSession s = sessions.next();
+ s = sessions.next();
notifyIdleSession(s, currentTime);
}
+
+ if (s != null) {
+ notifyIdleness(s.getService(), currentTime, false);
+ }
+ }
+
+ public static void notifyIdleness(IoService service, long currentTime) {
+ notifyIdleness(service, currentTime, true);
+ }
+
+ private static void notifyIdleness(IoService service, long currentTime,
boolean includeSessions) {
+ if (!(service instanceof AbstractIoService)) {
+ return;
+ }
+
+ ((AbstractIoService) service).notifyIdleness(currentTime);
+
+ if (includeSessions) {
+ notifyIdleness(service.getManagedSessions().iterator(),
currentTime);
+ }
}
/**
@@ -101,51 +122,95 @@
* @param currentTime the current time (i.e. [EMAIL PROTECTED]
System#currentTimeMillis()})
*/
public static void notifyIdleSession(IoSession session, long currentTime) {
- notifyIdleSession0(session, currentTime, session
- .getConfig().getIdleTimeInMillis(IdleStatus.BOTH_IDLE),
- IdleStatus.BOTH_IDLE, Math.max(session.getLastIoTime(), session
- .getLastIdleTime(IdleStatus.BOTH_IDLE)));
- notifyIdleSession0(session, currentTime, session
- .getConfig().getIdleTimeInMillis(IdleStatus.READER_IDLE),
- IdleStatus.READER_IDLE, Math.max(session.getLastReadTime(),
- session.getLastIdleTime(IdleStatus.READER_IDLE)));
- notifyIdleSession0(session, currentTime, session
- .getConfig().getIdleTimeInMillis(IdleStatus.WRITER_IDLE),
- IdleStatus.WRITER_IDLE, Math.max(session.getLastWriteTime(),
- session.getLastIdleTime(IdleStatus.WRITER_IDLE)));
- notifyWriteTimeout(session, currentTime, session
- .getConfig().getWriteTimeoutInMillis(),
session.getLastWriteTime());
+ if (session instanceof AbstractIoSession) {
+ AbstractIoSession s = (AbstractIoSession) session;
+ notifyIdleSession1(
+ s, currentTime,
+ s.getConfig().getIdleTimeInMillis(IdleStatus.BOTH_IDLE),
+ IdleStatus.BOTH_IDLE, Math.max(
+ s.getLastIoTime(),
+ s.getLastIdleTime(IdleStatus.BOTH_IDLE)));
+
+ notifyIdleSession1(
+ s, currentTime,
+ s.getConfig().getIdleTimeInMillis(IdleStatus.READER_IDLE),
+ IdleStatus.READER_IDLE, Math.max(
+ s.getLastReadTime(),
+ s.getLastIdleTime(IdleStatus.READER_IDLE)));
+
+ notifyIdleSession1(
+ s, currentTime,
+ s.getConfig().getIdleTimeInMillis(IdleStatus.WRITER_IDLE),
+ IdleStatus.WRITER_IDLE, Math.max(
+ s.getLastWriteTime(),
+ s.getLastIdleTime(IdleStatus.WRITER_IDLE)));
+
+ notifyWriteTimeout(s, currentTime);
+ updateThroughput(s, currentTime);
+ } else {
+ notifyIdleSession0(
+ session, currentTime,
+
session.getConfig().getIdleTimeInMillis(IdleStatus.BOTH_IDLE),
+ IdleStatus.BOTH_IDLE, Math.max(
+ session.getLastIoTime(),
+ session.getLastIdleTime(IdleStatus.BOTH_IDLE)));
+
+ notifyIdleSession0(
+ session, currentTime,
+
session.getConfig().getIdleTimeInMillis(IdleStatus.READER_IDLE),
+ IdleStatus.READER_IDLE, Math.max(
+ session.getLastReadTime(),
+ session.getLastIdleTime(IdleStatus.READER_IDLE)));
+
+ notifyIdleSession0(
+ session, currentTime,
+
session.getConfig().getIdleTimeInMillis(IdleStatus.WRITER_IDLE),
+ IdleStatus.WRITER_IDLE, Math.max(
+ session.getLastWriteTime(),
+ session.getLastIdleTime(IdleStatus.WRITER_IDLE)));
+ }
}
- private static void notifyIdleSession0(IoSession session, long currentTime,
+ private static void notifyIdleSession0(
+ IoSession session, long currentTime,
long idleTime, IdleStatus status, long lastIoTime) {
if (idleTime > 0 && lastIoTime != 0
&& currentTime - lastIoTime >= idleTime) {
- if (session instanceof AbstractIoSession) {
- ((AbstractIoSession) session).increaseIdleCount(status);
- }
session.getFilterChain().fireSessionIdle(status);
}
}
- private static void notifyWriteTimeout(IoSession session,
- long currentTime, long writeTimeout, long lastIoTime) {
- if (!(session instanceof AbstractIoSession)) {
- return;
+ private static void notifyIdleSession1(
+ AbstractIoSession session, long currentTime,
+ long idleTime, IdleStatus status, long lastIoTime) {
+ if (idleTime > 0 && lastIoTime != 0
+ && currentTime - lastIoTime >= idleTime) {
+ session.increaseIdleCount(status, currentTime);
+ session.getFilterChain().fireSessionIdle(status);
}
+ }
+
+ private static void notifyWriteTimeout(
+ AbstractIoSession session, long currentTime) {
- AbstractIoSession s = (AbstractIoSession) session;
- if (writeTimeout > 0 && currentTime - lastIoTime >= writeTimeout &&
- !s.getWriteRequestQueue().isEmpty(session)) {
- WriteRequest request = s.getCurrentWriteRequest();
+ long writeTimeout = session.getConfig().getWriteTimeoutInMillis();
+ if (writeTimeout > 0 &&
+ currentTime - session.getLastWriteTime() >= writeTimeout &&
+ !session.getWriteRequestQueue().isEmpty(session)) {
+ WriteRequest request = session.getCurrentWriteRequest();
if (request != null) {
- s.setCurrentWriteRequest(null);
+ session.setCurrentWriteRequest(null);
WriteTimeoutException cause = new
WriteTimeoutException(request);
request.getFuture().setException(cause);
- s.getFilterChain().fireExceptionCaught(cause);
+ session.getFilterChain().fireExceptionCaught(cause);
// WriteException is an IOException, so we close the session.
- s.close();
+ session.close();
}
}
+ }
+
+ private static void updateThroughput(
+ AbstractIoSession session, long currentTime) {
+ session.updateThroughput(currentTime);
}
}
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?rev=595545&r1=595544&r2=595545&view=diff
==============================================================================
--- 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 Thu Nov
15 20:34:21 2007
@@ -67,14 +67,31 @@
/**
* Returns all sessions which are currently managed by this service.
- * [EMAIL PROTECTED] IoAcceptor} will assume the specified
<tt>address</tt> is a local
- * address, and [EMAIL PROTECTED] IoConnector} will assume it's a remote
address.
*
* @return the sessions. An empty collection if there's no session.
- * @throws UnsupportedOperationException if this operation isn't supported
- * for the particular transport type implemented by this [EMAIL
PROTECTED] IoService}.
*/
Set<IoSession> getManagedSessions();
+
+ /**
+ * Returns the number of all sessions which are currently managed by this
+ * service.
+ */
+ int getManagedSessionCount();
+
+ /**
+ * Returns the maximum number of sessions which were being managed at the
+ * same time. This value is reset to <tt>0</tt> when the service is
+ * activated.
+ */
+ int getLargestManagedSessionCount();
+
+ /**
+ * Returns the cumulative number of sessions which were managed (or are
+ * being managed) by this service, which means 'currently managed session
+ * count + closed session count'. This value is reset to <tt>0</tt> when
+ * the service is activated.
+ */
+ long getCumulativeManagedSessionCount();
/**
* Returns the default configuration of the new [EMAIL PROTECTED]
IoSession}s
@@ -120,15 +137,69 @@
boolean isActive();
/**
- * Returns the time when this service was activated. Should return
- * zero if the service has not been activated.
+ * Returns the time when this service was activated. It returns the last
+ * time when this service was activated if the service is not active now.
*
* @return
- * The time by using <code>System.currentTimeMillis()</code>
+ * The time by using [EMAIL PROTECTED] System#currentTimeMillis()}
*/
long getActivationTime();
/**
+ * Returns the time in millis when I/O occurred lastly.
+ */
+ long getLastIoTime();
+
+ /**
+ * Returns the time in millis when read operation occurred lastly.
+ */
+ long getLastReadTime();
+
+ /**
+ * Returns the time in millis when write operation occurred lastly.
+ */
+ long getLastWriteTime();
+
+ /**
+ * Returns <code>true</code> if this service is idle for the specified
+ * [EMAIL PROTECTED] IdleStatus}.
+ */
+ boolean isIdle(IdleStatus status);
+
+ /**
+ * Returns the number of the fired continuous <tt>serviceIdle</tt> events
+ * for the specified [EMAIL PROTECTED] IdleStatus}.
+ * <p/>
+ * If <tt>serviceIdle</tt> event is fired first after some time after I/O,
+ * <tt>idleCount</tt> becomes <tt>1</tt>. <tt>idleCount</tt> resets to
+ * <tt>0</tt> if any I/O occurs again, otherwise it increases to
+ * <tt>2</tt> and so on if <tt>serviceIdle</tt> event is fired again
without
+ * any I/O between two (or more) <tt>serviceIdle</tt> events.
+ */
+ int getIdleCount(IdleStatus status);
+
+ /**
+ * Returns the time in milliseconds when the last <tt>serviceIdle</tt>
event
+ * is fired for the specified [EMAIL PROTECTED] IdleStatus}.
+ */
+ long getLastIdleTime(IdleStatus status);
+
+ /**
+ * Returns idle time for the specified type of idleness in seconds.
+ */
+ int getIdleTime(IdleStatus status);
+
+ /**
+ * Returns idle time for the specified type of idleness in milliseconds.
+ */
+ long getIdleTimeInMillis(IdleStatus status);
+
+ /**
+ * Sets idle time for the specified type of idleness in seconds.
+ */
+ void setIdleTime(IdleStatus status, int idleTime);
+
+ /**
* Returns the number of bytes read by this service
*
* @return
@@ -159,6 +230,44 @@
* The number of messages this service has written
*/
long getWrittenMessages();
+
+ /**
+ * Returns the number of read bytes per second.
+ */
+ double getReadBytesThroughput();
+
+ /**
+ * Returns the number of written bytes per second.
+ */
+ double getWrittenBytesThroughput();
+
+ /**
+ * Returns the number of read messages per second.
+ */
+ double getReadMessagesThroughput();
+
+ /**
+ * Returns the number of written messages per second.
+ */
+ double getWrittenMessagesThroughput();
+
+ /**
+ * Returns the interval (seconds) between each throughput calculation.
+ * The default value is <tt>3</tt> seconds.
+ */
+ int getThroughputCalculationInterval();
+
+ /**
+ * Returns the interval (milliseconds) between each throughput calculation.
+ * The default value is <tt>3</tt> seconds.
+ */
+ long getThroughputCalculationIntervalInMillis();
+
+ /**
+ * Sets the interval (seconds) between each throughput calculation. The
+ * default value is <tt>3</tt> seconds.
+ */
+ void setThroughputCalculationInterval(int throughputCalculationInterval);
/**
* Returns the number of bytes scheduled to be written
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/IoServiceListener.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/IoServiceListener.java?rev=595545&r1=595544&r2=595545&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/common/IoServiceListener.java
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/common/IoServiceListener.java
Thu Nov 15 20:34:21 2007
@@ -35,6 +35,11 @@
* @param service the [EMAIL PROTECTED] IoService}
*/
void serviceActivated(IoService service);
+
+ /**
+ * Invoked when a service is idle.
+ */
+ void serviceIdle(IoService service, IdleStatus idleStatus);
/**
* Invoked when a service is deactivated by an [EMAIL PROTECTED]
IoService}.
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/IoServiceListenerSupport.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/IoServiceListenerSupport.java?rev=595545&r1=595544&r2=595545&view=diff
==============================================================================
---
mina/trunk/core/src/main/java/org/apache/mina/common/IoServiceListenerSupport.java
(original)
+++
mina/trunk/core/src/main/java/org/apache/mina/common/IoServiceListenerSupport.java
Thu Nov 15 20:34:21 2007
@@ -54,8 +54,11 @@
* Read only version of [EMAIL PROTECTED] #managedSessions}.
*/
private final Set<IoSession> readOnlyManagedSessions =
Collections.unmodifiableSet(managedSessions);
-
+
private final AtomicBoolean activated = new AtomicBoolean();
+ private volatile long activationTime;
+ private volatile int largestManagedSessionCount;
+ private volatile long cumulativeManagedSessionCount;
/**
* Creates a new instance.
@@ -80,10 +83,26 @@
public void remove(IoServiceListener listener) {
listeners.remove(listener);
}
+
+ public long getActivationTime() {
+ return activationTime;
+ }
public Set<IoSession> getManagedSessions() {
return readOnlyManagedSessions;
}
+
+ public int getManagedSessionCount() {
+ return managedSessions.size();
+ }
+
+ public int getLargestManagedSessionCount() {
+ return largestManagedSessionCount;
+ }
+
+ public long getCumulativeManagedSessionCount() {
+ return cumulativeManagedSessionCount;
+ }
public boolean isActive() {
return activated.get();
@@ -98,14 +117,29 @@
return;
}
- if (service instanceof AbstractIoService) {
- ((AbstractIoService)
service).setActivationTime(System.currentTimeMillis());
- }
+ activationTime = System.currentTimeMillis();
+ largestManagedSessionCount = 0;
+ cumulativeManagedSessionCount = 0;
for (IoServiceListener l : listeners) {
l.serviceActivated(service);
}
}
+
+ /**
+ * Calls [EMAIL PROTECTED] IoServiceListener#serviceIdle(IoService,
IdleStatus)}
+ * for all registered listeners.
+ */
+ public void fireServiceIdle(IdleStatus status) {
+ if (!activated.get()) {
+ return;
+ }
+
+ for (IoServiceListener l : listeners) {
+ l.serviceIdle(service, status);
+ }
+ }
+
/**
* Calls [EMAIL PROTECTED] IoServiceListener#serviceDeactivated(IoService)}
@@ -122,9 +156,6 @@
}
} finally {
disconnectSessions();
- if (service instanceof AbstractIoService) {
- ((AbstractIoService) service).setActivationTime(0);
- }
}
}
@@ -143,7 +174,7 @@
if (!managedSessions.add(session)) {
return;
}
-
+
// If the first connector session, fire a virtual service activation
event.
if (firstSession) {
fireServiceActivated();
@@ -152,6 +183,12 @@
// Fire session events.
session.getFilterChain().fireSessionCreated();
session.getFilterChain().fireSessionOpened();
+
+ int managedSessionCount = managedSessions.size();
+ if (managedSessionCount > largestManagedSessionCount) {
+ largestManagedSessionCount = managedSessionCount;
+ }
+ cumulativeManagedSessionCount ++;
// Fire listener events.
for (IoServiceListener l : listeners) {
Modified: mina/trunk/core/src/main/java/org/apache/mina/common/IoSession.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/IoSession.java?rev=595545&r1=595544&r2=595545&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/common/IoSession.java
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/common/IoSession.java Thu Nov
15 20:34:21 2007
@@ -373,6 +373,26 @@
long getWrittenMessages();
/**
+ * Returns the number of read bytes per second.
+ */
+ double getReadBytesThroughput();
+
+ /**
+ * Returns the number of written bytes per second.
+ */
+ double getWrittenBytesThroughput();
+
+ /**
+ * Returns the number of read messages per second.
+ */
+ double getReadMessagesThroughput();
+
+ /**
+ * Returns the number of written messages per second.
+ */
+ double getWrittenMessagesThroughput();
+
+ /**
* Returns the number of messages which are scheduled to be written to
this session.
*/
int getScheduledWriteMessages();
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/IoSessionConfig.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/IoSessionConfig.java?rev=595545&r1=595544&r2=595545&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/common/IoSessionConfig.java
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/common/IoSessionConfig.java
Thu Nov 15 20:34:21 2007
@@ -70,6 +70,24 @@
* read buffer size to the greater value than this property value.
*/
void setMaxReadBufferSize(int maxReadBufferSize);
+
+ /**
+ * Returns the interval (seconds) between each throughput calculation.
+ * The default value is <tt>3</tt> seconds.
+ */
+ int getThroughputCalculationInterval();
+
+ /**
+ * Returns the interval (milliseconds) between each throughput calculation.
+ * The default value is <tt>3</tt> seconds.
+ */
+ long getThroughputCalculationIntervalInMillis();
+
+ /**
+ * Sets the interval (seconds) between each throughput calculation. The
+ * default value is <tt>3</tt> seconds.
+ */
+ void setThroughputCalculationInterval(int throughputCalculationInterval);
/**
* Returns idle time for the specified type of idleness in seconds.
Modified:
mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.java?rev=595545&r1=595544&r2=595545&view=diff
==============================================================================
---
mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.java
(original)
+++
mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.java
Thu Nov 15 20:34:21 2007
@@ -582,7 +582,7 @@
long currentTime = System.currentTimeMillis();
if (currentTime - lastIdleCheckTime >= 1000) {
lastIdleCheckTime = currentTime;
- IdleStatusChecker.notifyIdleSessions(
+ IdleStatusChecker.notifyIdleness(
getListeners().getManagedSessions().iterator(),
currentTime);
}