Java Code Examples for org.apache.mina.core.session.IoSession#getWrittenBytes()
The following examples show how to use
org.apache.mina.core.session.IoSession#getWrittenBytes() .
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 written bytes. This information is used by the outgoing * bytes statistic. * * @param session the session that wrote more bytes to the socket. */ private void updateWrittenBytesCounter(IoSession session) { long currentBytes = session.getWrittenBytes(); Long prevBytes = (Long) session.getAttribute("_written_bytes"); long delta; if (prevBytes == null) { delta = currentBytes; } else { delta = currentBytes - prevBytes; } session.setAttribute("_written_bytes", currentBytes); ServerTrafficCounter.incrementOutgoingCounter(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); } }