org.apache.mina.core.filterchain.IoFilterChain Java Examples

The following examples show how to use org.apache.mina.core.filterchain.IoFilterChain. 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: MulticastSocketProcessor.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
boolean removeNow(MulticastSocketSession session) {
//FIXME
      //clearWriteRequestQueue(session);

      try {
          destroy(session);
          return true;
      } catch (Exception e) {
          IoFilterChain filterChain = session.getFilterChain();
          filterChain.fireExceptionCaught(e);
      } finally {
      	//FIXME
          //clearWriteRequestQueue(session);
          ((AbstractIoService) session.getService()).getListeners().fireSessionDestroyed(session);
      }
      return false;
  }
 
Example #2
Source File: SslFilter.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Executed just before the filter is added into the chain, we do :
 * <ul>
 * <li>check that we don't have a SSL filter already present
 * <li>we update the next filter
 * <li>we create the SSL handler helper class
 * <li>and we store it into the session's Attributes
 * </ul>
 */
@Override
public void onPreAdd(IoFilterChain parent, String name, NextFilter nextFilter) throws SSLException {
    // Check that we don't have a SSL filter already present in the chain
    if (parent.contains(SslFilter.class)) {
        String msg = "Only one SSL filter is permitted in a chain.";
        LOGGER.error(msg);
        throw new IllegalStateException(msg);
    }

    LOGGER.debug("Adding the SSL Filter {} to the chain", name);

    IoSession session = parent.getSession();
    session.setAttribute(NEXT_FILTER, nextFilter);

    // Create a SSL handler and start handshake.
    SslHandler handler = new SslHandler(this, session);
    handler.init();
    session.setAttribute(SSL_HANDLER, handler);
}
 
Example #3
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 #4
Source File: CompressionFilter.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void onPostRemove(IoFilterChain parent, String name, NextFilter nextFilter) throws Exception {
    super.onPostRemove(parent, name, nextFilter);
    IoSession session = parent.getSession();
    if (session == null) {
        return;
    }

    Zlib inflater = (Zlib) session.getAttribute(INFLATER);
    Zlib deflater = (Zlib) session.getAttribute(DEFLATER);
    if (deflater != null) {
        deflater.cleanUp();
    }

    if (inflater != null) {
        inflater.cleanUp();
    }
}
 
Example #5
Source File: SslFilter.java    From jane with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Executed just before the filter is added into the chain, we do :
 * <ul>
 * <li>check that we don't have a SSL filter already present
 * <li>we update the next filter
 * <li>we create the SSL handler helper class
 * <li>and we store it into the session's Attributes
 * </ul>
 */
@Override
public void onPreAdd(IoFilterChain chain, String name, NextFilter nextFilter) throws SSLException {
	// Check that we don't have a SSL filter already present in the chain
	if (chain.getEntry(SslFilter.class) != null)
		throw new IllegalStateException("only one SSL filter is permitted in a chain");

	// Adding the supported ciphers in the SSLHandler
	if (enabledCipherSuites == null || enabledCipherSuites.length == 0)
		enabledCipherSuites = sslContext.getServerSocketFactory().getSupportedCipherSuites();

	IoSession session = chain.getSession();

	// Create a SSL handler and start handshake.
	SslHandler sslHandler = new SslHandler(this, session);
	sslHandler.init();

	session.setAttribute(SSL_HANDLER, sslHandler);
}
 
Example #6
Source File: RequestResponseFilter.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onPreAdd(IoFilterChain parent, String name, NextFilter nextFilter) throws Exception {
    if (parent.contains(this)) {
        throw new IllegalArgumentException(
                "You can't add the same filter instance more than once.  Create another instance and add it.");
    }

    IoSession session = parent.getSession();
    session.setAttribute(RESPONSE_INSPECTOR, responseInspectorFactory.getResponseInspector());
    session.setAttribute(REQUEST_STORE, createRequestStore(session));
    session.setAttribute(UNRESPONDED_REQUEST_STORE, createUnrespondedRequestStore(session));
}
 
Example #7
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 #8
Source File: RequestResponseFilter.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onPostRemove(IoFilterChain parent, String name, NextFilter nextFilter) throws Exception {
    IoSession session = parent.getSession();

    destroyUnrespondedRequestStore(getUnrespondedRequestStore(session));
    destroyRequestStore(getRequestStore(session));

    session.removeAttribute(UNRESPONDED_REQUEST_STORE);
    session.removeAttribute(REQUEST_STORE);
    session.removeAttribute(RESPONSE_INSPECTOR);
}
 
Example #9
Source File: NIOConnection.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@Override
public void addCompression() {
    IoFilterChain chain = ioSession.getFilterChain();
    String baseFilter = EXECUTOR_FILTER_NAME;
    if (chain.contains(TLS_FILTER_NAME)) {
        baseFilter = TLS_FILTER_NAME;
    }
    chain.addAfter(baseFilter, COMPRESSION_FILTER_NAME, new CompressionFilter(true, false, CompressionFilter.COMPRESSION_MAX));
}
 
Example #10
Source File: SslFilter.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onPreRemove(IoFilterChain parent, String name, NextFilter nextFilter) throws SSLException {
    IoSession session = parent.getSession();
    stopSsl(session);
    session.removeAttribute(NEXT_FILTER);
    session.removeAttribute(SSL_HANDLER);
}
 
Example #11
Source File: ProtocolCodecFilter.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onPreAdd(IoFilterChain parent, String name, NextFilter nextFilter) throws Exception {
    if (parent.contains(this)) {
        throw new IllegalArgumentException(
                "You can't add the same filter instance more than once.  Create another instance and add it.");
    }
}
 
Example #12
Source File: ReferenceCountingFilter.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public synchronized void onPreAdd(IoFilterChain parent, String name, NextFilter nextFilter) throws Exception {
    if (0 == count) {
        filter.init();
    }

    ++count;

    filter.onPreAdd(parent, name, nextFilter);
}
 
Example #13
Source File: ReferenceCountingFilter.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public synchronized void onPostRemove(IoFilterChain parent, String name, NextFilter nextFilter) throws Exception {
    filter.onPostRemove(parent, name, nextFilter);

    --count;

    if (0 == count) {
        filter.destroy();
    }
}
 
Example #14
Source File: FilterChainBuilder.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void buildFilterChain ( final IoFilterChain chain )
{
    if ( this.loggerName != null && Boolean.getBoolean ( "org.eclipse.scada.protocol.sfp.common.logger.raw" ) )
    {
        chain.addFirst ( "logger.raw", new LoggingFilter ( this.loggerName ) );
    }

    if ( !Boolean.getBoolean ( "org.eclipse.scada.protocol.sfp.common.disableStats" ) )
    {
        chain.addFirst ( StatisticsFilter.DEFAULT_NAME, new StatisticsFilter () );
    }

    if ( this.loggerName != null && Boolean.getBoolean ( "org.eclipse.scada.protocol.sfp.common.logger" ) )
    {
        chain.addFirst ( "logger", new LoggingFilter ( this.loggerName ) );
    }

    chain.addLast ( "closeidle", new IoFilterAdapter () {
        @Override
        public void sessionIdle ( final NextFilter nextFilter, final IoSession session, final IdleStatus status ) throws Exception
        {
            session.close ( true );
        }
    } );
    chain.addLast ( "codec", new ProtocolCodecFilter ( new ProtocolEncoderImpl (), new ProtocolDecoderImpl () ) );
}
 
Example #15
Source File: HackedProtocolCodecFilter.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onPreAdd(IoFilterChain parent, String name, NextFilter nextFilter) throws Exception {
    if (parent.contains(this)) {
        throw new IllegalArgumentException(
                "You can't add the same filter instance more than once.  Create another instance and add it.");
    }
}
 
Example #16
Source File: ExecutorFilter.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void onPreAdd(IoFilterChain parent, String name, NextFilter nextFilter) throws Exception {
    if (parent.contains(this)) {
        throw new IllegalArgumentException(
                "You can't add the same filter instance more than once.  Create another instance and add it.");
    }
}
 
Example #17
Source File: AbstractPollingIoProcessor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private boolean removeNow(S session) {
    clearWriteRequestQueue(session);

    try {
        destroy(session);
        return true;
    } catch (Exception e) {
        IoFilterChain filterChain = session.getFilterChain();
        filterChain.fireExceptionCaught(e);
    } finally {
        clearWriteRequestQueue(session);
        ((AbstractIoService) session.getService()).getListeners().fireSessionDestroyed(session);
    }
    return false;
}
 
Example #18
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 #19
Source File: KeepAliveFilter.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onPreAdd(IoFilterChain parent, String name, NextFilter nextFilter) throws Exception {
    if (parent.contains(this)) {
        throw new IllegalArgumentException("You can't add the same filter instance more than once. "
                + "Create another instance and add it.");
    }
}
 
Example #20
Source File: AbstractStreamWriteFilter.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onPreAdd(IoFilterChain parent, String name, NextFilter nextFilter) throws Exception {
    Class<? extends IoFilterAdapter> clazz = getClass();
    if (parent.contains(clazz)) {
        throw new IllegalStateException("Only one " + clazz.getName() + " is permitted.");
    }
}
 
Example #21
Source File: CompressionFilter.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onPreAdd(IoFilterChain parent, String name, NextFilter nextFilter) throws Exception {
    if (parent.contains(CompressionFilter.class)) {
        throw new IllegalStateException("Only one " + CompressionFilter.class + " is permitted.");
    }

    Zlib deflater = new Zlib(compressionLevel, Zlib.MODE_DEFLATER);
    Zlib inflater = new Zlib(compressionLevel, Zlib.MODE_INFLATER);

    IoSession session = parent.getSession();

    session.setAttribute(DEFLATER, deflater);
    session.setAttribute(INFLATER, inflater);
}
 
Example #22
Source File: FilterChainBuilder.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void buildFilterChain ( final IoFilterChain chain )
{
    for ( final Entry entry : this.filters )
    {
        final IoFilter filter = entry.getFactory ().create ();
        if ( filter != null )
        {
            chain.addLast ( entry.getName (), filter );
        }
    }

}
 
Example #23
Source File: MulticastSocketProcessor.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
private boolean addNow(MulticastSocketSession session) {

        boolean registered = false;
        boolean notified = false;
        try {
            registered = true;

            // Build the filter chain of this session.
            session.getService().getFilterChainBuilder().buildFilterChain(
                    session.getFilterChain());

            // DefaultIoFilterChain.CONNECT_FUTURE is cleared inside here
            // in AbstractIoFilterChain.fireSessionOpened().
            ((AbstractIoService) session.getService()).getListeners().fireSessionCreated(session);
            notified = true;
            bufSize = session.getConfig().getReadBufferSize();
        } catch (Exception e) {
            if (notified)
            {
                // Clear the DefaultIoFilterChain.CONNECT_FUTURE attribute
                // and call ConnectFuture.setException().
                remove(session);
                IoFilterChain filterChain = session.getFilterChain();
                filterChain.fireExceptionCaught(e);
                wakeup();
            } else {
                ExceptionMonitor.getInstance().exceptionCaught(e);
                try {
                    destroy(session);
                } catch (Exception e1) {
                    ExceptionMonitor.getInstance().exceptionCaught(e1);
                } finally {
                    registered = false;
                }
            }
        }
        return registered;
    }
 
Example #24
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 #25
Source File: ReferenceCountingFilter.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
public void onPreRemove(IoFilterChain parent, String name, NextFilter nextFilter) throws Exception {
    filter.onPreRemove(parent, name, nextFilter);
}
 
Example #26
Source File: NioSession.java    From jane with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public IoFilterChain getFilterChain() {
	return filterChain;
}
 
Example #27
Source File: SslHandler.java    From jane with GNU Lesser General Public License v3.0 4 votes vote down vote up
NextFilter getNextFilter() {
	IoFilterChain.Entry entry = session.getFilterChain().getEntry(sslFilter);
	return entry != null ? entry.getNextFilter() : null;
}
 
Example #28
Source File: WebSocketServerTest.java    From red5-websocket with Apache License 2.0 4 votes vote down vote up
@Override
public IoFilterChain getFilterChain() {
    // TODO Auto-generated method stub
    return null;
}
 
Example #29
Source File: SslFilter.java    From jane with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void onPostAdd(IoFilterChain chain, String name, NextFilter nextFilter) throws Exception {
	if (autoStart)
		initiateHandshake(nextFilter, chain.getSession());
}
 
Example #30
Source File: SslFilter.java    From jane with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void onPreRemove(IoFilterChain chain, String name, NextFilter nextFilter) throws Exception {
	IoSession session = chain.getSession();
	stopSsl(session, false);
	session.removeAttribute(SSL_HANDLER);
}