Java Code Examples for org.apache.mina.core.session.IoSession#getFilterChain()

The following examples show how to use org.apache.mina.core.session.IoSession#getFilterChain() . 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: NetManager.java    From jane with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 发送对象的底层入口. 可带监听器,并返回WriteFuture
 */
public static WriteFuture write(IoSession session, Object obj, IoFutureListener<?> listener)
{
	if (session.isClosing() || obj == null)
		return null;
	IoFilterChain ifc = session.getFilterChain();
	WriteFuture wf = new DefaultWriteFuture(session);
	if (listener != null)
		wf.addListener(listener);
	DefaultWriteRequest dwr = new DefaultWriteRequest(obj, wf);
	synchronized (session)
	{
		ifc.fireFilterWrite(dwr);
	}
	return wf;
}
 
Example 2
Source File: NetManager.java    From jane with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 发送对象的底层入口
 */
public static boolean write(IoSession session, WriteRequest wr)
{
	if (session.isClosing() || wr == null)
		return false;
	IoFilterChain ifc = session.getFilterChain();
	synchronized (session)
	{
		ifc.fireFilterWrite(wr);
	}
	return true;
}
 
Example 3
Source File: NetManager.java    From jane with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static boolean write(IoSession session, Object obj)
{
	if (session.isClosing() || obj == null)
		return false;
	IoFilterChain ifc = session.getFilterChain();
	WriteRequest wr = (obj instanceof WriteRequest ? (WriteRequest)obj : new SimpleWriteRequest(obj));
	synchronized (session)
	{
		ifc.fireFilterWrite(wr);
	}
	return true;
}
 
Example 4
Source File: AbstractIoService.java    From jane with GNU Lesser General Public License v3.0 5 votes vote down vote up
public final void fireSessionCreated(IoSession session) {
	if (managedSessions.putIfAbsent(session.getId(), session) == null) {
		IoFilterChain filterChain = session.getFilterChain();
		filterChain.fireSessionCreated();
		filterChain.fireSessionOpened();
	}
}
 
Example 5
Source File: IoServiceListenerSupport.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Calls {@link IoServiceListener#sessionCreated(IoSession)} for all registered listeners.
 * 
 * @param session The session which has been created
 */
public void fireSessionCreated(IoSession session) {
    boolean firstSession = false;

    if (session.getService() instanceof IoConnector) {
        synchronized (managedSessions) {
            firstSession = managedSessions.isEmpty();
        }
    }

    // If already registered, ignore.
    if (managedSessions.putIfAbsent(session.getId(), session) != null) {
        return;
    }

    // If the first connector session, fire a virtual service activation event.
    if (firstSession) {
        fireServiceActivated();
    }

    // Fire session events.
    IoFilterChain filterChain = session.getFilterChain();
    filterChain.fireSessionCreated();
    filterChain.fireSessionOpened();

    int managedSessionCount = managedSessions.size();

    if (managedSessionCount > largestManagedSessionCount) {
        largestManagedSessionCount = managedSessionCount;
    }

    cumulativeManagedSessionCount++;

    // Fire listener events.
    for (IoServiceListener l : listeners) {
        try {
            l.sessionCreated(session);
        } catch (Throwable e) {
            ExceptionMonitor.getInstance().exceptionCaught(e);
        }
    }
}