Example usage for io.netty.handler.codec.serialization ClassResolvers cacheDisabled

List of usage examples for io.netty.handler.codec.serialization ClassResolvers cacheDisabled

Introduction

In this page you can find the example usage for io.netty.handler.codec.serialization ClassResolvers cacheDisabled.

Prototype

public static ClassResolver cacheDisabled(ClassLoader classLoader) 

Source Link

Document

cache disabled

Usage

From source file:afred.javademo.proxy.rpc.ObjectEchoClient.java

License:Apache License

public void start(String host, int port) throws Exception {
    EventLoopGroup group = new NioEventLoopGroup();
    try {/*from  www.  ja va2 s . co m*/
        Bootstrap b = new Bootstrap();
        b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {
            @Override
            public void initChannel(SocketChannel ch) throws Exception {
                ChannelPipeline p = ch.pipeline();
                p.addLast(new ObjectEncoder(), new ObjectDecoder(ClassResolvers.cacheDisabled(null)),
                        new ObjectEchoClientHandler());
            }
        });

        channel = b.connect(host, port).sync().channel();
    } finally {

    }
}

From source file:afred.javademo.proxy.rpc.ObjectEchoServer.java

License:Apache License

public static void main(String[] args) throws Exception {

    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {//  ww w.ja  v a  2  s .com
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ChannelPipeline p = ch.pipeline();
                        p.addLast(new ObjectEncoder(), new ObjectDecoder(ClassResolvers.cacheDisabled(null)),
                                new ObjectEchoServerHandler());
                    }
                });

        // Bind and start to accept incoming connections.
        b.bind(8080).sync().channel().closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:books.netty.codec.serializable.netty.SubReqClient.java

License:Apache License

public void connect(int port, String host) throws Exception {
    // ?NIO/*  www .  j a  v a2s  .  c o  m*/
    EventLoopGroup group = new NioEventLoopGroup();
    try {
        Bootstrap b = new Bootstrap();
        b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true)
                .handler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) {
                        ch.pipeline().addLast(new ObjectDecoder(1024,
                                ClassResolvers.cacheDisabled(this.getClass().getClassLoader())));
                        ch.pipeline().addLast(new ObjectEncoder());
                        ch.pipeline().addLast(new SubReqClientHandler());
                    }
                });

        // ??
        ChannelFuture f = b.connect(host, port).sync();

        // 
        f.channel().closeFuture().sync();
    } finally {
        // NIO
        group.shutdownGracefully();
    }
}

From source file:ChatClient.ChatClientInitializer.java

@Override
protected void initChannel(SocketChannel c) throws Exception {
    ChannelPipeline pipeline = c.pipeline();

    pipeline.addLast("decoder", new ObjectDecoder(ClassResolvers.cacheDisabled(getClass().getClassLoader())));
    pipeline.addLast("encoder", new ObjectEncoder());

    pipeline.addLast("handler", new ChatClientHandler());
}

From source file:ChatServer.ChatServerInitializer.java

@Override
protected void initChannel(SocketChannel c) throws Exception {
    ChannelPipeline pipeline = c.pipeline();

    pipeline.addLast("decoder", new ObjectDecoder(ClassResolvers.cacheDisabled(getClass().getClassLoader())));
    pipeline.addLast("encoder", new ObjectEncoder());
    pipeline.addLast("handler", new ChatServerHandler());
}

From source file:cn.savor.small.netty.NettyClient.java

License:Open Source License

public void start() {
    try {//from w w  w.ja v  a2  s  . c  om
        bootstrap = new Bootstrap();
        bootstrap.group(workGroup).channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<SocketChannel>() {
                    protected void initChannel(SocketChannel ch) throws Exception {
                        System.out.println("client SocketChannel.....................................");
                        ch.pipeline().addLast("ping", new IdleStateHandler(60, 60, 80, TimeUnit.SECONDS));
                        //POJO? ?
                        ch.pipeline().addLast(new ObjectDecoder(1024 * 5,
                                ClassResolvers.cacheDisabled(this.getClass().getClassLoader())));
                        //????
                        ch.pipeline().addLast(new ObjectEncoder());

                        ch.pipeline().addLast(new NettyClientHandler(NettyClient.this, callback, mContext));
                    }
                });
        connect();

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.athena.meerkat.agent.netty.MeerkatClientInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    // Create a default pipeline implementation.
    LOGGER.debug("**************************Tran - Init *****************************");
    ChannelPipeline pipeline = ch.pipeline();

    pipeline.addLast("decoder", new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null)));
    pipeline.addLast("encoder", new ObjectEncoder());
    pipeline.addLast("handler", handler);
}

From source file:com.athena.peacock.agent.netty.PeacockClientInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = ch.pipeline();

    pipeline.addLast("decoder", new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null)));
    pipeline.addLast("encoder", new ObjectEncoder());
    pipeline.addLast("handler", handler);
}

From source file:com.athena.peacock.controller.netty.PeacockServerInitializer.java

License:Open Source License

@Override
public void initChannel(SocketChannel ch) throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = ch.pipeline();

    pipeline.addLast("decoder", new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null)));
    pipeline.addLast("encoder", new ObjectEncoder());
    pipeline.addLast("handler", new PeacockServerHandler());
}

From source file:com.avanza.astrix.netty.client.NettyRemotingClient.java

License:Apache License

public void connect(String host, int port) {
    Bootstrap b = new Bootstrap();
    b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {
        @Override/*w w w .j ava2  s.  co m*/
        public void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            p.addLast(new ObjectEncoder(), new ObjectDecoder(ClassResolvers.cacheDisabled(null)),
                    nettyRemotingClientHandler);
        }
    });

    // Start the connection attempt.
    ChannelFuture channel = b.connect(host, port);
    try {
        if (channel.await(1, TimeUnit.SECONDS)) {
            if (channel.isSuccess()) {
                return;
            }
        }
    } catch (InterruptedException e) {
    }
    destroy();
    throw new IllegalArgumentException(
            String.format("Failed to connect to remoting server: %s:%d", host, port));
}