Java Code Examples for org.apache.mina.core.session.IoSession#getReadBytes()
The following examples show how to use
org.apache.mina.core.session.IoSession#getReadBytes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConnectionHandler.java From Openfire with Apache License 2.0 | 5 votes |
/** * Updates the system counter of read bytes. This information is used by the incoming * bytes statistic. * * @param session the session that read more bytes from the socket. */ private void updateReadBytesCounter(IoSession session) { long currentBytes = session.getReadBytes(); Long prevBytes = (Long) session.getAttribute("_read_bytes"); long delta; if (prevBytes == null) { delta = currentBytes; } else { delta = currentBytes - prevBytes; } session.setAttribute("_read_bytes", currentBytes); ServerTrafficCounter.incrementIncomingCounter(delta); }
Example 2
Source File: MINAStatCollector.java From Openfire with Apache License 2.0 | 4 votes |
@Override public void run() { while ( !stop ) { // wait polling time try { Thread.sleep( pollingInterval ); } catch ( InterruptedException e ) { Log.trace("Sleep interrupted"); } long tmpMsgWritten = 0L; long tmpMsgRead = 0L; long tmpBytesWritten = 0L; long tmpBytesRead = 0L; long tmpScheduledWrites = 0L; long tmpQueuevedEvents = 0L; for (IoSession session : polledSessions) { // upadating individual session statistics IoSessionStat sessStat = ( IoSessionStat ) session.getAttribute( KEY ); long currentTimestamp = System.currentTimeMillis(); // Calculate delta float pollDelta = (currentTimestamp - sessStat.lastPollingTime) / 1000f; // Store last polling time of this session sessStat.lastPollingTime = currentTimestamp; long readBytes = session.getReadBytes(); long writtenBytes = session.getWrittenBytes(); long readMessages = session.getReadMessages(); long writtenMessages = session.getWrittenMessages(); sessStat.byteReadThroughput = (readBytes - sessStat.lastByteRead) / pollDelta; sessStat.byteWrittenThroughput = (writtenBytes - sessStat.lastByteWrite) / pollDelta; sessStat.messageReadThroughput = (readMessages - sessStat.lastMessageRead) / pollDelta; sessStat.messageWrittenThroughput = (writtenMessages - sessStat.lastMessageWrite) / pollDelta; tmpMsgWritten += (writtenMessages - sessStat.lastMessageWrite); tmpMsgRead += (readMessages - sessStat.lastMessageRead); tmpBytesWritten += (writtenBytes - sessStat.lastByteWrite); tmpBytesRead += (readBytes - sessStat.lastByteRead); tmpScheduledWrites += session.getScheduledWriteMessages(); ExecutorFilter executorFilter = (ExecutorFilter) session.getFilterChain().get(EXECUTOR_FILTER_NAME); if (executorFilter != null) { Executor executor = executorFilter.getExecutor(); if (executor instanceof OrderedThreadPoolExecutor) { tmpQueuevedEvents += ((OrderedThreadPoolExecutor) executor).getActiveCount(); } } sessStat.lastByteRead = readBytes; sessStat.lastByteWrite = writtenBytes; sessStat.lastMessageRead = readMessages; sessStat.lastMessageWrite = writtenMessages; } totalMsgWritten.addAndGet(tmpMsgWritten); totalMsgRead.addAndGet(tmpMsgRead); totalBytesWritten.addAndGet(tmpBytesWritten); totalBytesRead.addAndGet(tmpBytesRead); totalScheduledWrites.set(tmpScheduledWrites); totalQueuedEvents.set(tmpQueuevedEvents); } }