Search in sources :

Example 1 with ObjectSerializationCodecFactory

use of org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory in project camel by apache.

the class MinaComponent method configureDefaultCodecFactory.

protected void configureDefaultCodecFactory(String type, IoServiceConfig config, MinaConfiguration configuration) {
    if (configuration.isTextline()) {
        Charset charset = getEncodingParameter(type, configuration);
        LineDelimiter delimiter = getLineDelimiterParameter(configuration.getTextlineDelimiter());
        TextLineCodecFactory codecFactory = new TextLineCodecFactory(charset, delimiter);
        if (configuration.getEncoderMaxLineLength() > 0) {
            codecFactory.setEncoderMaxLineLength(configuration.getEncoderMaxLineLength());
        }
        if (configuration.getDecoderMaxLineLength() > 0) {
            codecFactory.setDecoderMaxLineLength(configuration.getDecoderMaxLineLength());
        }
        addCodecFactory(config, codecFactory);
        if (LOG.isDebugEnabled()) {
            LOG.debug("{}: Using TextLineCodecFactory: {} using encoding: {} line delimiter: {}({})", new Object[] { type, codecFactory, charset, configuration.getTextlineDelimiter(), delimiter });
            LOG.debug("Encoder maximum line length: {}. Decoder maximum line length: {}", codecFactory.getEncoderMaxLineLength(), codecFactory.getDecoderMaxLineLength());
        }
    } else {
        ObjectSerializationCodecFactory codecFactory = new ObjectSerializationCodecFactory();
        addCodecFactory(config, codecFactory);
        LOG.debug("{}: Using ObjectSerializationCodecFactory: {}", type, codecFactory);
    }
}
Also used : ObjectSerializationCodecFactory(org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory) LineDelimiter(org.apache.mina.filter.codec.textline.LineDelimiter) Charset(java.nio.charset.Charset)

Example 2 with ObjectSerializationCodecFactory

use of org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory in project camel by apache.

the class Mina2Consumer method configureDefaultCodecFactory.

protected void configureDefaultCodecFactory(String type, IoService service, Mina2Configuration configuration) {
    if (configuration.isTextline()) {
        Charset charset = getEncodingParameter(type, configuration);
        LineDelimiter delimiter = getLineDelimiterParameter(configuration.getTextlineDelimiter());
        Mina2TextLineCodecFactory codecFactory = new Mina2TextLineCodecFactory(charset, delimiter);
        if (configuration.getEncoderMaxLineLength() > 0) {
            codecFactory.setEncoderMaxLineLength(configuration.getEncoderMaxLineLength());
        }
        if (configuration.getDecoderMaxLineLength() > 0) {
            codecFactory.setDecoderMaxLineLength(configuration.getDecoderMaxLineLength());
        }
        addCodecFactory(service, codecFactory);
        if (LOG.isDebugEnabled()) {
            LOG.debug("{}: Using TextLineCodecFactory: {} using encoding: {} line delimiter: {}({})", new Object[] { type, codecFactory, charset, configuration.getTextlineDelimiter(), delimiter });
            LOG.debug("Encoder maximum line length: {}. Decoder maximum line length: {}", codecFactory.getEncoderMaxLineLength(), codecFactory.getDecoderMaxLineLength());
        }
    } else {
        ObjectSerializationCodecFactory codecFactory = new ObjectSerializationCodecFactory();
        addCodecFactory(service, codecFactory);
        LOG.debug("{}: Using ObjectSerializationCodecFactory: {}", type, codecFactory);
    }
}
Also used : ObjectSerializationCodecFactory(org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory) LineDelimiter(org.apache.mina.filter.codec.textline.LineDelimiter) Charset(java.nio.charset.Charset)

Example 3 with ObjectSerializationCodecFactory

use of org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory in project pancm_project by xuwujing.

the class ClientTestServer method creatClient.

public IoConnector creatClient() {
    IoConnector connector = new NioSocketConnector();
    connector.setConnectTimeoutMillis(30000);
    connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
    connector.setHandler(new MinaClientHandler());
    return connector;
}
Also used : NioSocketConnector(org.apache.mina.transport.socket.nio.NioSocketConnector) MinaClientHandler(com.pancm.test.minatest.demo.MinaClientHandler) ObjectSerializationCodecFactory(org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory) IoConnector(org.apache.mina.core.service.IoConnector) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter)

Example 4 with ObjectSerializationCodecFactory

use of org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory in project pancm_project by xuwujing.

the class MinaClient method main.

/* 
    * 测试服务端与客户端程序!
    a. 启动服务端,然后再启动客户端
    b. 服务端接收消息并处理成功;
    */
@SuppressWarnings("deprecation")
public static void main(String[] args) {
    // 设置链接超时时间
    connector.setConnectTimeout(30000);
    // 添加过滤器  可序列话的对象
    connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
    // 添加业务逻辑处理器类
    connector.setHandler(new MinaClientHandler());
    ConnectFuture future = connector.connect(new InetSocketAddress(HOST, // 创建连接
    PORT));
    // 等待连接创建完成
    future.awaitUninterruptibly();
    // 获得session
    session = future.getSession();
    bindstart();
    pushstart();
}
Also used : ObjectSerializationCodecFactory(org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory) InetSocketAddress(java.net.InetSocketAddress) ConnectFuture(org.apache.mina.core.future.ConnectFuture) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter)

Example 5 with ObjectSerializationCodecFactory

use of org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory in project camel by apache.

the class Mina2Producer method configureDefaultCodecFactory.

protected void configureDefaultCodecFactory(String type, IoService service) {
    if (configuration.isTextline()) {
        Charset charset = getEncodingParameter(type, configuration);
        LineDelimiter delimiter = getLineDelimiterParameter(configuration.getTextlineDelimiter());
        Mina2TextLineCodecFactory codecFactory = new Mina2TextLineCodecFactory(charset, delimiter);
        if (configuration.getEncoderMaxLineLength() > 0) {
            codecFactory.setEncoderMaxLineLength(configuration.getEncoderMaxLineLength());
        }
        if (configuration.getDecoderMaxLineLength() > 0) {
            codecFactory.setDecoderMaxLineLength(configuration.getDecoderMaxLineLength());
        }
        addCodecFactory(service, codecFactory);
        LOG.debug("{}: Using TextLineCodecFactory: {} using encoding: {} line delimiter: {}({})", type, codecFactory, charset, configuration.getTextlineDelimiter(), delimiter);
        LOG.debug("Encoder maximum line length: {}. Decoder maximum line length: {}", codecFactory.getEncoderMaxLineLength(), codecFactory.getDecoderMaxLineLength());
    } else {
        ObjectSerializationCodecFactory codecFactory = new ObjectSerializationCodecFactory();
        addCodecFactory(service, codecFactory);
        LOG.debug("{}: Using ObjectSerializationCodecFactory: {}", type, codecFactory);
    }
}
Also used : ObjectSerializationCodecFactory(org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory) LineDelimiter(org.apache.mina.filter.codec.textline.LineDelimiter) Charset(java.nio.charset.Charset)

Aggregations

ObjectSerializationCodecFactory (org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory)6 Charset (java.nio.charset.Charset)3 ProtocolCodecFilter (org.apache.mina.filter.codec.ProtocolCodecFilter)3 LineDelimiter (org.apache.mina.filter.codec.textline.LineDelimiter)3 InetSocketAddress (java.net.InetSocketAddress)2 MinaClientHandler (com.pancm.test.minatest.demo.MinaClientHandler)1 ConnectFuture (org.apache.mina.core.future.ConnectFuture)1 IoAcceptor (org.apache.mina.core.service.IoAcceptor)1 IoConnector (org.apache.mina.core.service.IoConnector)1 NioSocketAcceptor (org.apache.mina.transport.socket.nio.NioSocketAcceptor)1 NioSocketConnector (org.apache.mina.transport.socket.nio.NioSocketConnector)1