Java 类org.apache.mina.filter.codec.ProtocolCodecFactory 实例源码

项目:Halo-Turbo    文件:MinaTcpServerSocket.java   
private void init(Config config) {
    address = new InetSocketAddress(config.sourcePort);
    acceptor = new NioSocketAcceptor();
    if (acceptor.getFilterChain().get(LOGGER) == null) {
        acceptor.getFilterChain().addLast(LOGGER, new LoggingFilter());
    }
    if (acceptor.getFilterChain().get(CODEC) == null) {
        ProtocolCodecFactory codecFactory = config.codec == null ?
                MinaUtil.getTextLineCodecFactory() : (ProtocolCodecFactory) config.codec;
        acceptor.getFilterChain().addLast(CODEC, new ProtocolCodecFilter(codecFactory));
    }
    acceptor.setHandler(new MinaServerHandler());
    acceptor.getSessionConfig().setReadBufferSize(config.bufferSize);
    acceptor.getSessionConfig().setIdleTime(IdleStatus.WRITER_IDLE, 10);
    acceptor.setReuseAddress(true); //避免重启时提示地址被占用
    //设置主服务监听端口的监听队列的最大值为50,如果当前已经有50个连接,新的连接将被服务器拒绝
    acceptor.setBacklog(50);

    KeepAliveFilter keepAliveFilter = MinaUtil.initServerKeepAlive(config, this);
    if (keepAliveFilter != null) {
        acceptor.getFilterChain().addLast(HEARTBEAT, keepAliveFilter);
    }
}
项目:Halo-Turbo    文件:MinaUdpClientSocket.java   
private void init(Config config) {
    connector = new NioDatagramConnector();
    connector.setHandler(new MinaClientHandler());
    DefaultIoFilterChainBuilder chain = connector.getFilterChain();
    if (connector.getFilterChain().get(LOGGER) == null) {
        chain.addLast(LOGGER, new LoggingFilter());
    }
    if (connector.getFilterChain().get(CODEC) == null) {
        ProtocolCodecFactory codecFactory = config.codec == null ?
                MinaUtil.getTextLineCodecFactory() : (ProtocolCodecFactory) config.codec;
        chain.addLast(CODEC, new ProtocolCodecFilter(codecFactory));
    }
    connector.getSessionConfig().setReadBufferSize(config.bufferSize);
    connector.getSessionConfig().setIdleTime(IdleStatus.WRITER_IDLE, 10);
    connector.getSessionConfig().setBroadcast(true);
    KeepAliveFilter keepAliveFilter = MinaUtil.initClientKeepAlive(config, this);
    if (keepAliveFilter != null) {
        connector.getFilterChain().addLast(HEARTBEAT, keepAliveFilter);
    }
}
项目:Halo-Turbo    文件:MinaTcpClientSocket.java   
private void init(Config config) {
    address = new InetSocketAddress(config.targetIP, config.targetPort);
    connector = new NioSocketConnector();
    connector.setDefaultRemoteAddress(address);
    if (connector.getFilterChain().get(LOGGER) == null) {
        connector.getFilterChain().addLast(LOGGER, new LoggingFilter());
    }
    if (connector.getFilterChain().get(CODEC) == null) {
        ProtocolCodecFactory codecFactory = config.codec == null ?
                MinaUtil.getTextLineCodecFactory() : (ProtocolCodecFactory) config.codec;
        connector.getFilterChain().addLast(CODEC, new ProtocolCodecFilter(codecFactory));
    }
    connector.setHandler(new MinaClientHandler());
    connector.getSessionConfig().setReadBufferSize(config.bufferSize);
    connector.getSessionConfig().setIdleTime(IdleStatus.WRITER_IDLE, 10);
    KeepAliveFilter keepAliveFilter = MinaUtil.initClientKeepAlive(config, this);
    if (keepAliveFilter != null) {
        connector.getFilterChain().addLast(HEARTBEAT, keepAliveFilter);
    }
}
项目:Halo-Turbo    文件:MinaUdpServerSocket.java   
private void init(Config config) {
    address = new InetSocketAddress(config.sourcePort);

    acceptor = new NioDatagramAcceptor();
    acceptor.setHandler(new MinaServerHandler());
    DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
    if (acceptor.getFilterChain().get(LOGGER) == null) {
        chain.addLast(LOGGER, new LoggingFilter());
    }
    if (acceptor.getFilterChain().get(CODEC) == null) {
        ProtocolCodecFactory codecFactory = config.codec == null ?
                MinaUtil.getTextLineCodecFactory() : (ProtocolCodecFactory) config.codec;
        chain.addLast(CODEC, new ProtocolCodecFilter(codecFactory));
    }
    DatagramSessionConfig dcfg = acceptor.getSessionConfig();
    dcfg.setReuseAddress(true);
    dcfg.setReadBufferSize(config.bufferSize);
    dcfg.setIdleTime(IdleStatus.WRITER_IDLE, 10);
    dcfg.setBroadcast(true);

    KeepAliveFilter keepAliveFilter = MinaUtil.initServerKeepAlive(config, this);
    if (keepAliveFilter != null) {
        acceptor.getFilterChain().addLast(HEARTBEAT, keepAliveFilter);
    }
}
项目:red5-mobileconsole    文件:RTMPMinaIoHandler.java   
/** {@inheritDoc} */
@Override
public void sessionCreated(IoSession session) throws Exception {
    log.debug("Session created");
    // moved protocol state from connection object to RTMP object
    RTMP rtmp = new RTMP();
    session.setAttribute(ProtocolState.SESSION_KEY, rtmp);
    //add rtmpe filter
    session.getFilterChain().addFirst("rtmpeFilter", new RTMPEIoFilter());
    //add protocol filter next
    ProtocolCodecFactory codecFactory = (ProtocolCodecFactory) appCtx.getBean("rtmpCodecFactory");
    session.getFilterChain().addLast("protocolFilter", new ProtocolCodecFilter(codecFactory));
    if (log.isTraceEnabled()) {
        session.getFilterChain().addLast("logger", new LoggingFilter());
    }
    //create a connection
    RTMPMinaConnection conn = createRTMPMinaConnection();
    conn.setIoSession(session);
    conn.setState(rtmp);
    //add the connection
    session.setAttribute(RTMPConnection.RTMP_CONNECTION_KEY, conn);
    //add the inbound handshake
    session.setAttribute(RTMPConnection.RTMP_HANDSHAKE, new InboundHandshake());
}
项目:directory-ldap-api    文件:StandaloneLdapApiService.java   
/**
 * Creates a new instance of StandaloneLdapApiService.
 *
 * @param controls The list of controls to store
 * @param extendedOperations The list of extended operations to store
 * @throws Exception If we had an issue with one of the two lists
 */
public StandaloneLdapApiService( List<String> controls, List<String> extendedOperations ) throws Exception
{
    CodecFactoryUtil.loadStockControls( getControlFactories(), this );

    CodecFactoryUtil.loadStockExtendedOperations( getExtendedOperationsFactories(), this );

    // Load the controls
    loadControls( controls );

    // Load the extended operations
    loadExtendedOperations( extendedOperations );

    if ( getProtocolCodecFactory() == null )
    {
        try
        {
            @SuppressWarnings("unchecked")
            Class<? extends ProtocolCodecFactory> clazz = ( Class<? extends ProtocolCodecFactory> )
                Class.forName( DEFAULT_PROTOCOL_CODEC_FACTORY );
            Constructor<? extends ProtocolCodecFactory> constructor =
                clazz.getConstructor( LdapApiService.class );
            if ( constructor != null )
            {
                setProtocolCodecFactory( constructor.newInstance( this ) );
            }
            else
            {
                setProtocolCodecFactory( clazz.newInstance() );
            }
        }
        catch ( Exception cause )
        {
            throw new RuntimeException( "Failed to load default codec factory.", cause );
        }
    }
}
项目:directory-ldap-api    文件:DefaultLdapCodecService.java   
/**
 * {@inheritDoc}
 */
@Override
public ProtocolCodecFactory registerProtocolCodecFactory( ProtocolCodecFactory protocolCodecFactory )
{
    ProtocolCodecFactory oldFactory = this.protocolCodecFactory;
    this.protocolCodecFactory = protocolCodecFactory;
    return oldFactory;
}
项目:Camel    文件:MinaComponent.java   
/**
 * For datagrams the entire message is available as a single ByteBuffer so lets just pass those around by default
 * and try converting whatever they payload is into ByteBuffers unless some custom converter is specified
 */
protected void configureDataGramCodecFactory(final String type, final IoServiceConfig config, final MinaConfiguration configuration) {
    ProtocolCodecFactory codecFactory = configuration.getCodec();
    if (codecFactory == null) {
        codecFactory = new MinaUdpProtocolCodecFactory(getCamelContext());

        if (LOG.isDebugEnabled()) {
            LOG.debug("{}: Using CodecFactory: {}", new Object[]{type, codecFactory});
        }
    }

    addCodecFactory(config, codecFactory);
}
项目:Camel    文件:Mina2Producer.java   
/**
 * For datagrams the entire message is available as a single IoBuffer so lets just pass those around by default
 * and try converting whatever they payload is into IoBuffer unless some custom converter is specified
 */
protected void configureDataGramCodecFactory(final String type, final IoService service, final Mina2Configuration configuration) {
    ProtocolCodecFactory codecFactory = configuration.getCodec();
    if (codecFactory == null) {
        codecFactory = new Mina2UdpProtocolCodecFactory(this.getEndpoint().getCamelContext());

        if (LOG.isDebugEnabled()) {
            LOG.debug("{}: Using CodecFactory: {}", new Object[]{type, codecFactory});
        }
    }

    addCodecFactory(service, codecFactory);
}
项目:Camel    文件:Mina2Consumer.java   
/**
 * For datagrams the entire message is available as a single IoBuffer so lets just pass those around by default
 * and try converting whatever they payload is into IoBuffer unless some custom converter is specified
 */
protected void configureDataGramCodecFactory(final String type, final IoService service, final Mina2Configuration configuration) {
    ProtocolCodecFactory codecFactory = configuration.getCodec();
    if (codecFactory == null) {
        codecFactory = new Mina2UdpProtocolCodecFactory(this.getEndpoint().getCamelContext());

        if (LOG.isDebugEnabled()) {
            LOG.debug("{}: Using CodecFactory: {}", new Object[]{type, codecFactory});
        }
    }

    addCodecFactory(service, codecFactory);
}
项目:JRemoting    文件:MinaServer.java   
public MinaServer(ServerMonitor serverMonitor, StubRetriever stubRetriever,
                    Authenticator authenticator,
                    ProtocolCodecFactory codecFactory,
                    ServerContextFactory contextFactory,
                    ClassLoader facadesClassLoader, InetSocketAddress addr) {
    this(serverMonitor, defaultServerDelegate(serverMonitor, stubRetriever, authenticator, contextFactory),
            codecFactory, facadesClassLoader, addr);
}
项目:JRemoting    文件:MinaServer.java   
public MinaServer(ServerMonitor serverMonitor, ServerDelegate serverDelegate,
                                       ProtocolCodecFactory codecFactory,
                                       ClassLoader facadesClassLoader, InetSocketAddress addr) {

    super(serverMonitor, serverDelegate);
    this.codecFactory = codecFactory;
    this.facadesClassLoader = facadesClassLoader;
    this.addr = addr;
}
项目:directory-ldap-api    文件:DefaultLdapCodecService.java   
/**
 * {@inheritDoc}
 */
@Override
public ProtocolCodecFactory getProtocolCodecFactory()
{
    return protocolCodecFactory;
}
项目:directory-ldap-api    文件:DefaultLdapCodecService.java   
/**
 * @param protocolCodecFactory the protocolCodecFactory to set
 */
public void setProtocolCodecFactory( ProtocolCodecFactory protocolCodecFactory )
{
    this.protocolCodecFactory = protocolCodecFactory;
}
项目:MyVirtualDirectory    文件:LdapServer.java   
public ProtocolCodecFactory getProtocolCodecFactory()
{
    return codecFactory;
}
项目:MyVirtualDirectory    文件:LdapServer.java   
public ProtocolCodecFactory getProtocolCodecFactory()
{
    return codecFactory;
}
项目:Camel    文件:MinaConfiguration.java   
public ProtocolCodecFactory getCodec() {
    return codec;
}
项目:Camel    文件:MinaConfiguration.java   
/**
 * To use a custom minda codec implementation.
 */
public void setCodec(ProtocolCodecFactory codec) {
    this.codec = codec;
}
项目:Camel    文件:MinaComponent.java   
private void addCodecFactory(IoServiceConfig config, ProtocolCodecFactory codecFactory) {
    config.getFilterChain().addLast("codec", new ProtocolCodecFilter(codecFactory));
}
项目:Camel    文件:Mina2Configuration.java   
public ProtocolCodecFactory getCodec() {
    return codec;
}
项目:Camel    文件:Mina2Configuration.java   
/**
 * To use a custom minda codec implementation.
 */
public void setCodec(ProtocolCodecFactory codec) {
    this.codec = codec;
}
项目:Camel    文件:Mina2Producer.java   
private void addCodecFactory(IoService service, ProtocolCodecFactory codecFactory) {
    LOG.debug("addCodecFactory name: {}", codecFactory.getClass().getName());

    service.getFilterChain().addLast("codec", new ProtocolCodecFilter(codecFactory));
}
项目:Camel    文件:Mina2Consumer.java   
private void addCodecFactory(IoService service, ProtocolCodecFactory codecFactory) {
    service.getFilterChain().addLast("codec", new ProtocolCodecFilter(codecFactory));
}
项目:xxl-rpc    文件:MinaServer.java   
@Override
public void start(final int port, final Serializer serializer) throws Exception {
       thread = new Thread(new Runnable() {
        @Override
        public void run() {
            NioSocketAcceptor acceptor = new NioSocketAcceptor();
            try {
                acceptor.getFilterChain().addLast("threadPool", new ExecutorFilter(Executors.newCachedThreadPool()));
                acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ProtocolCodecFactory() {
                    @Override
                    public ProtocolEncoder getEncoder(IoSession session) throws Exception {
                        return new MinaEncoder(RpcResponse.class, serializer);
                    }
                    @Override
                    public ProtocolDecoder getDecoder(IoSession session) throws Exception {
                        return new MinaDecoder(RpcRequest.class, serializer);
                    }
                }));
                acceptor.setHandler(new MinaServerHandler());

                SocketSessionConfig config = (SocketSessionConfig) acceptor.getSessionConfig();
                config.setReuseAddress(true);
                config.setTcpNoDelay(true); // TCP_NODELAY和TCP_CORK基本上控制了包的“Nagle化”,这里我们主要讲TCP_NODELAY.Nagle化在这里的含义是采用Nagle算法把较小的包组装为更大的帧。
                config.setSoLinger(0);      // 执行Socket的close方法,该方法也会立即返回
                config.setReadBufferSize(1024 * 2);
                config.setIdleTime(IdleStatus.BOTH_IDLE, 10);

                acceptor.bind(new InetSocketAddress(port));
                logger.info(">>>>>>>>>>> xxl-rpc server start success, netcon={}, port={}", MinaServer.class.getName(), port);
            } catch (IOException e) {
                logger.error("", e);
                if (acceptor != null && acceptor.isActive()) {
                    acceptor.unbind();
                    acceptor.dispose();
                }
            }
        }
    });
       thread.setDaemon(true);
       thread.start();

}
项目:JRemoting    文件:MinaServer.java   
public MinaServer(ServerMonitor serverMonitor, ProtocolCodecFactory codecFactory, InetSocketAddress addr) {
    this(serverMonitor, defaultStubRetriever(), defaultAuthenticator(), codecFactory, defaultContextFactory(), defaultClassLoader(), addr);
}
项目:JRemoting    文件:MinaServer.java   
public MinaServer(ServerMonitor serverMonitor, StubRetriever stubRetriever, Authenticator authenticator, ProtocolCodecFactory codecFactory, ServerContextFactory serverContextFactory, InetSocketAddress addr) {
    this(serverMonitor, stubRetriever, authenticator, codecFactory, serverContextFactory, defaultClassLoader(), addr);
}
项目:JRemoting    文件:MinaServer.java   
private static ProtocolCodecFactory defaultProtocolCodecFactory() {
    return new ByteStreamProtocolCodecFactory();
}
项目:red5-server    文件:RTMPChannelFilter.java   
public RTMPChannelFilter(ProtocolCodecFactory factory) {
    super(factory);
}
项目:red5-server    文件:RTMPMinaIoHandler.java   
/**
 * @param codecFactory
 *            the codecFactory to set
 */
@Deprecated
public void setCodecFactory(ProtocolCodecFactory codecFactory) {
    log.warn("This option is deprecated, the codec factory is now contained within the RTMPEIoFilter");
}
项目:directory-ldap-api    文件:LdapApiService.java   
/**
 * Creates a new LDAP {@link ProtocolCodecFactory}.
 *
 * @return the {@link ProtocolCodecFactory}
 */
ProtocolCodecFactory getProtocolCodecFactory();
项目:directory-ldap-api    文件:LdapApiService.java   
/**
 * Registers a ProtocolCodecFactory with this LdapCodecService.
 *
 * @param factory The factory being registered.
 * @return The previously set {@link ProtocolCodecFactory}, or null if 
 * none had been set earlier.
 */
ProtocolCodecFactory registerProtocolCodecFactory( ProtocolCodecFactory factory );
项目:red5-server    文件:DebugProxyHandler.java   
/**
 * Setter for property 'codecFactory'.
 *
 * @param codecFactory
 *            Value to set for property 'codecFactory'.
 */
public void setCodecFactory(ProtocolCodecFactory codecFactory) {
    this.codecFactory = codecFactory;
}
项目:red5-mobileconsole    文件:DebugProxyHandler.java   
/**
 * Setter for property 'codecFactory'.
 *
 * @param codecFactory Value to set for property 'codecFactory'.
 */
public void setCodecFactory(ProtocolCodecFactory codecFactory) {
    this.codecFactory = codecFactory;
}