org.apache.mina.core.session.AbstractIoSession Java Examples

The following examples show how to use org.apache.mina.core.session.AbstractIoSession. 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: DefaultIoFilterChain.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void sessionClosed(NextFilter nextFilter, IoSession session) throws Exception {
    AbstractIoSession s = (AbstractIoSession) session;
    try {
        s.getHandler().sessionClosed(session);
    } finally {
        try {
            s.getWriteRequestQueue().dispose(session);
        } finally {
            try {
                s.getAttributeMap().dispose(session);
            } finally {
                try {
                    // Remove all filters.
                    session.getFilterChain().clear();
                } finally {
                    if (s.getConfig().isUseReadOperation()) {
                        s.offerClosedReadFuture();
                    }
                }
            }
        }
    }
}
 
Example #2
Source File: DefaultIoFilterChain.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception {
    AbstractIoSession s = (AbstractIoSession) session;
    if (!(message instanceof IoBuffer)) {
        s.increaseReadMessages(System.currentTimeMillis());
    } else if (!((IoBuffer) message).hasRemaining()) {
        s.increaseReadMessages(System.currentTimeMillis());
    }

    try {
        session.getHandler().messageReceived(s, message);
    } finally {
        if (s.getConfig().isUseReadOperation()) {
            s.offerReadFuture(message);
        }
    }
}
 
Example #3
Source File: PrepareOnlyThisForTestAnnotationTest.java    From powermock-examples-maven with Apache License 2.0 6 votes vote down vote up
@Test
@PrepareOnlyThisForTest( { NioDatagramSession.class, NioProcessor.class, AbstractIoSession.class })
public void assertThatPrepareOnlyThisForTestWorks() throws Exception {
    final String scheduleRemoveMethodName = "scheduleRemove";

    Executor executor = createMock(Executor.class);
    NioProcessor objectUnderTest = createPartialMock(NioProcessor.class, new String[] { scheduleRemoveMethodName }, executor);
    NioDatagramSession session = createMock(NioDatagramSession.class);

    expect(session.isConnected()).andReturn(false);
    expectPrivate(objectUnderTest, scheduleRemoveMethodName, session).once();

    replay(objectUnderTest, executor, session);

    assertFalse(Whitebox.<Boolean> invokeMethod(objectUnderTest, "flushNow", session, 20L));

    verify(objectUnderTest, executor, session);
}
 
Example #4
Source File: AbstractPollingConnectionlessIoAcceptor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void notifyIdleSessions( long currentTime )
{
    // process idle sessions
    if ( currentTime - lastIdleCheckTime >= 1000 )
    {
        lastIdleCheckTime = currentTime;
        AbstractIoSession.notifyIdleness( getListeners().getManagedSessions().values().iterator(), currentTime );
    }
}
 
Example #5
Source File: AbstractPollingIoProcessor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void notifyIdleSessions(long currentTime) throws Exception {
    // process idle sessions
    if (currentTime - lastIdleCheckTime >= SELECT_TIMEOUT) {
        lastIdleCheckTime = currentTime;
        AbstractIoSession.notifyIdleness(allSessions(), currentTime);
    }
}
 
Example #6
Source File: DefaultIoFilterChain.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Create a new default chain, associated with a session. It will only contain a
 * HeadFilter and a TailFilter.
 *
 * @param session The session associated with the created filter chain
 */
public DefaultIoFilterChain(AbstractIoSession session) {
    if (session == null) {
        throw new IllegalArgumentException("session");
    }

    this.session = session;
    head = new EntryImpl(null, null, "head", new HeadFilter());
    tail = new EntryImpl(head, null, "tail", new TailFilter());
    head.nextEntry = tail;
}
 
Example #7
Source File: DefaultIoFilterChain.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception {

    AbstractIoSession s = (AbstractIoSession) session;

    // Maintain counters.
    if (writeRequest.getMessage() instanceof IoBuffer) {
        IoBuffer buffer = (IoBuffer) writeRequest.getMessage();
        // I/O processor implementation will call buffer.reset()
        // it after the write operation is finished, because
        // the buffer will be specified with messageSent event.
        buffer.mark();
        int remaining = buffer.remaining();

        if (remaining == 0) {
            // Zero-sized buffer means the internal message
            // delimiter.
            s.increaseScheduledWriteMessages();
        } else {
            s.increaseScheduledWriteBytes(remaining);
        }
    } else {
        s.increaseScheduledWriteMessages();
    }

    WriteRequestQueue writeRequestQueue = s.getWriteRequestQueue();

    if (!s.isWriteSuspended()) {
        if (writeRequestQueue.size() == 0) {
            // We can write directly the message
            s.getProcessor().write(s, writeRequest);
        } else {
            s.getWriteRequestQueue().offer(s, writeRequest);
            s.getProcessor().flush(s);
        }
    } else {
        s.getWriteRequestQueue().offer(s, writeRequest);
    }
}
 
Example #8
Source File: DefaultIoFilterChain.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable cause) throws Exception {
    AbstractIoSession s = (AbstractIoSession) session;
    try {
        s.getHandler().exceptionCaught(s, cause);
    } finally {
        if (s.getConfig().isUseReadOperation()) {
            s.offerFailedReadFuture(cause);
        }
    }
}
 
Example #9
Source File: VmPipeFilterChain.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
VmPipeFilterChain(AbstractIoSession session) {
    super(session);
}
 
Example #10
Source File: DefaultIoFilterChain.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void filterClose(NextFilter nextFilter, IoSession session) throws Exception {
    ((AbstractIoSession) session).getProcessor().remove(session);
}