當前位置: 首頁>>代碼示例>>Java>>正文


Java ClassResolvers類代碼示例

本文整理匯總了Java中io.netty.handler.codec.serialization.ClassResolvers的典型用法代碼示例。如果您正苦於以下問題:Java ClassResolvers類的具體用法?Java ClassResolvers怎麽用?Java ClassResolvers使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ClassResolvers類屬於io.netty.handler.codec.serialization包,在下文中一共展示了ClassResolvers類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: open

import io.netty.handler.codec.serialization.ClassResolvers; //導入依賴的package包/類
@Override
    public void open() {
        EventLoopGroup eventLoop = new NioEventLoopGroup();
        bootstrap = new Bootstrap();
        bootstrap.group(eventLoop);
        bootstrap.channel(NioSocketChannel.class);
        bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 3 * 1000);
        bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
        bootstrap.handler(new ChannelInitializer<SocketChannel>() {
            @Override
            public void initChannel(SocketChannel ch) throws Exception {
                ch.pipeline()
//                        .addLast("logging",new LoggingHandler(LogLevel.INFO))
                        .addLast("decoder", new ObjectDecoder(ClassResolvers.cacheDisabled(getClass().getClassLoader()))) // in 1
                        .addLast("handler", new ClientReadHandler()) // in 2
                        .addLast("encoder", new ObjectEncoder())// out 3
                        .addLast("idleStateHandler", new IdleStateHandler(0, 1, 0))
                        .addLast(new ClientIdleHandler());

            }
        });
    }
 
開發者ID:justice-code,項目名稱:star-map,代碼行數:23,代碼來源:StarClientProtocol.java

示例2: openServer

import io.netty.handler.codec.serialization.ClassResolvers; //導入依賴的package包/類
@Override
public void openServer(URL url) throws Exception{
    EventLoopGroup eventLoop = new NioEventLoopGroup();
    EventLoopGroup workLoop = new NioEventLoopGroup();
    serverBootstrap = new ServerBootstrap();
    serverBootstrap.group(eventLoop, workLoop);
    serverBootstrap.channel(NioServerSocketChannel.class);
    serverBootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
    serverBootstrap.childHandler(new ChannelInitializer<SocketChannel>(){

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline()
                    .addLast("decoder", new ObjectDecoder(ClassResolvers.cacheDisabled(getClass().getClassLoader()))) // in 1
                    .addLast("handler", new ServerHandler()) // in 2
                    .addLast("encoder", new ObjectEncoder()); // out 3

        }
    });
    serverChannel = serverBootstrap.bind(url.getPort()).sync().sync().channel();
    logger.info("start server at:" + url.getPort());
}
 
開發者ID:justice-code,項目名稱:star-map,代碼行數:23,代碼來源:StarServerProtocol.java

示例3: doOpen

import io.netty.handler.codec.serialization.ClassResolvers; //導入依賴的package包/類
public void doOpen() throws InterruptedException {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try{
        ServerBootstrap serverBootstrap = new ServerBootstrap();
        serverBootstrap.group(bossGroup,workerGroup);
        serverBootstrap.channel(NioServerSocketChannel.class);
        serverBootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
            protected void initChannel(SocketChannel socketChannel) throws Exception {
                ChannelPipeline pipeline = socketChannel.pipeline();
                pipeline.addLast(new ObjectDecoder(1024*1024, ClassResolvers.weakCachingConcurrentResolver(this.getClass().getClassLoader())));
                pipeline.addLast(new ObjectEncoder());
                pipeline.addLast((SimpleChannelInboundHandler)handler);
            }
        });
        serverBootstrap.option(ChannelOption.SO_BACKLOG,1024);
        serverBootstrap.childOption(ChannelOption.SO_KEEPALIVE,true);
        ChannelFuture future = serverBootstrap.bind(address,port).sync();
        //future.channel().closeFuture().sync();
    }finally{
        //workerGroup.shutdownGracefully();
        //bossGroup.shutdownGracefully();
    }
}
 
開發者ID:dachengxi,項目名稱:mini-dubbo,代碼行數:25,代碼來源:NettyServer.java

示例4: send

import io.netty.handler.codec.serialization.ClassResolvers; //導入依賴的package包/類
public void send() throws InterruptedException {

		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
				protected void initChannel(SocketChannel ch) throws Exception {

					ChannelPipeline p = ch.pipeline();
					p.addLast(new ObjectEncoder());
					p.addLast(new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null)));
					p.addLast(new PojoClientHandler());
				}
			});

			ChannelFuture future = b.connect(Constants.HOST, Constants.PORT).sync();

			future.channel().closeFuture().sync();
		} finally {
			group.shutdownGracefully();
		}
	}
 
開發者ID:TFdream,項目名稱:netty-tutorials,代碼行數:27,代碼來源:PojoClient.java

示例5: start

import io.netty.handler.codec.serialization.ClassResolvers; //導入依賴的package包/類
private void start() throws InterruptedException {
    EventLoopGroup eventLoopGroup=new NioEventLoopGroup();
    Bootstrap bootstrap=new Bootstrap();
    bootstrap.channel(NioSocketChannel.class);
    bootstrap.option(ChannelOption.SO_KEEPALIVE,true);
    bootstrap.group(eventLoopGroup);
    bootstrap.remoteAddress(host,port);
    bootstrap.handler(new ChannelInitializer<SocketChannel>() {
        @Override
        protected void initChannel(SocketChannel socketChannel) throws Exception {
            socketChannel.pipeline().addLast(new IdleStateHandler(20,10,0));
            socketChannel.pipeline().addLast(new ObjectEncoder());
            socketChannel.pipeline().addLast(new ObjectDecoder(ClassResolvers.cacheDisabled(null)));
            socketChannel.pipeline().addLast(new NettyClientHandler());
        }
    });
    ChannelFuture future =bootstrap.connect(host,port).sync();
    if (future.isSuccess()) {
        socketChannel = (SocketChannel)future.channel();
        System.out.println("connect server  成功---------");
    }
}
 
開發者ID:howdyli,項目名稱:netty,代碼行數:23,代碼來源:NettyClientBootstrap.java

示例6: bind

import io.netty.handler.codec.serialization.ClassResolvers; //導入依賴的package包/類
private void bind() throws InterruptedException {
    EventLoopGroup boss=new NioEventLoopGroup();
    EventLoopGroup worker=new NioEventLoopGroup();
    ServerBootstrap bootstrap=new ServerBootstrap();
    bootstrap.group(boss,worker);
    bootstrap.channel(NioServerSocketChannel.class);
    bootstrap.option(ChannelOption.SO_BACKLOG, 128);
    bootstrap.option(ChannelOption.TCP_NODELAY, true);
    bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
    bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
        @Override
        protected void initChannel(SocketChannel socketChannel) throws Exception {
            ChannelPipeline p = socketChannel.pipeline();
            p.addLast(new ObjectEncoder());
            p.addLast(new ObjectDecoder(ClassResolvers.cacheDisabled(null)));
            p.addLast(new NettyServerHandler());
        }
    });
    ChannelFuture f= bootstrap.bind(port).sync();
    if(f.isSuccess()){
        System.out.println("server start---------------");
    }
}
 
開發者ID:howdyli,項目名稱:netty,代碼行數:24,代碼來源:NettyServerBootstrap.java

示例7: channelRegistered

import io.netty.handler.codec.serialization.ClassResolvers; //導入依賴的package包/類
/**
 * Called once the TCP connection is established.
 * Configures the per-connection pipeline that is responsible for handling incoming and outgoing data.
 * After an incoming packet is decrypted, decoded and verified,
 * it will be sent to its target {@link de.unipassau.isl.evs.ssh.core.handler.MessageHandler}
 * by the {@link IncomingDispatcher}.
 */
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
    Log.v(TAG, "channelRegistered " + ctx);
    ctx.attr(ATTR_HANDSHAKE_FINISHED).set(false);

    // Add (de-)serialization Handlers before this Handler
    ctx.pipeline().addBefore(ctx.name(), ObjectEncoder.class.getSimpleName(), new ObjectEncoder());
    ctx.pipeline().addBefore(ctx.name(), ObjectDecoder.class.getSimpleName(), new ObjectDecoder(
            ClassResolvers.weakCachingConcurrentResolver(getClass().getClassLoader())));
    ctx.pipeline().addBefore(ctx.name(), LoggingHandler.class.getSimpleName(), new LoggingHandler(LogLevel.TRACE));

    // Timeout Handler
    ctx.pipeline().addBefore(ctx.name(), IdleStateHandler.class.getSimpleName(),
            new IdleStateHandler(READER_IDLE_TIME, WRITER_IDLE_TIME, ALL_IDLE_TIME));
    ctx.pipeline().addBefore(ctx.name(), TimeoutHandler.class.getSimpleName(), new TimeoutHandler());

    // Add exception handler
    ctx.pipeline().addAfter(ctx.name(), PipelinePlug.class.getSimpleName(), new PipelinePlug());

    super.channelRegistered(ctx);
    Log.v(TAG, "Pipeline after register: " + ctx.pipeline());
}
 
開發者ID:SecureSmartHome,項目名稱:SecureSmartHome,代碼行數:30,代碼來源:ClientHandshakeHandler.java

示例8: initChannel

import io.netty.handler.codec.serialization.ClassResolvers; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {
	ChannelPipeline pipeline = ch.pipeline();
	
	/*
	 * 使用ObjectDecoder和ObjectEncoder
	 * 因為雙向都有寫數據和讀數據,所以這裏需要兩個都設置
	 * 如果隻讀,那麽隻需要ObjectDecoder即可
	 */
	pipeline.addLast("decoder", new ObjectDecoder(ClassResolvers.cacheDisabled(this.getClass().getClassLoader())));
	pipeline.addLast("encoder", new ObjectEncoder());
	
	/*
	 * 這裏隻監聽讀操作
	 * 可以根據需求,監聽寫操作和總得操作
	 */
	pipeline.addLast("idleStateHandler", new IdleStateHandler(0, 0, Constants.ALL_IDLE_TIME, TimeUnit.SECONDS));
	
	pipeline.addLast("handler", new ServerHandler());
}
 
開發者ID:zhaoyangzhou,項目名稱:NPush,代碼行數:21,代碼來源:ServerInitializer.java

示例9: newObjectDecoder

import io.netty.handler.codec.serialization.ClassResolvers; //導入依賴的package包/類
public static ChannelHandlerFactory newObjectDecoder(String protocol) {
    if ("udp".equalsIgnoreCase(protocol)) {
        return new DefaultChannelHandlerFactory() {
            @Override
            public ChannelHandler newChannelHandler() {
                return new DatagramPacketObjectDecoder(ClassResolvers.weakCachingResolver(null));
            }
        };
    } else {
        return new DefaultChannelHandlerFactory() {
            @Override
            public ChannelHandler newChannelHandler() {
                return new ObjectDecoder(ClassResolvers.weakCachingResolver(null));
            }
        };
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:18,代碼來源:ChannelHandlerFactories.java

示例10: channelRead

import io.netty.handler.codec.serialization.ClassResolvers; //導入依賴的package包/類
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

	DatagramPacket packet = (DatagramPacket) msg;
	try {

		InputStream stream = new ByteBufInputStream(packet.content());
		Object data = new CompactObjectInputStream(stream, ClassResolvers.cacheDisabled(null)).readObject();
		MDC.put("id", LogSourceId.getInstance().getId());
		logger.callAppenders(((LoggingEventWrapper) data).event);

	} catch (Throwable e){
		System.out.println(e);
	}
	ReferenceCountUtil.release(msg);
}
 
開發者ID:d0k1,項目名稱:DistributedLog4j,代碼行數:17,代碼來源:Log4jHandler.java

示例11: run

import io.netty.handler.codec.serialization.ClassResolvers; //導入依賴的package包/類
private void run(int port) throws InterruptedException, IOException {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();

    try {
        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    protected void initChannel(SocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO))
                                .addLast(new ObjectEncoder())
                                .addLast(new ObjectDecoder(ClassResolvers.cacheDisabled(null)))
                                .addLast(new ObjectEchoServerHandler());
                    }
                });
        bootstrap.bind(port).sync().channel().closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }

}
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:25,代碼來源:ObjectEchoServer.java

示例12: run

import io.netty.handler.codec.serialization.ClassResolvers; //導入依賴的package包/類
public void run(String host, int port) throws Exception {

        EventLoopGroup group = new NioEventLoopGroup();
        try {
            Bootstrap bootstrap = new Bootstrap();
            bootstrap.group(group)
                    .channel(NioSocketChannel.class)
                    .handler(new ChannelInitializer<SocketChannel>() {
                        @Override
                        protected void initChannel(SocketChannel ch) throws Exception {
                            ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO))
                                    .addLast(new ObjectEncoder())
                                    .addLast(new ObjectDecoder(ClassResolvers.cacheDisabled(null)))
                                    .addLast(new ObjectEchoClientHandler());
                        }
                    });

            bootstrap.connect(host, port).sync().channel().closeFuture().sync();
        } finally {
            group.shutdownGracefully();
        }
    }
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:23,代碼來源:ObjectEchoClient.java

示例13: run

import io.netty.handler.codec.serialization.ClassResolvers; //導入依賴的package包/類
private void run(int port) throws InterruptedException, IOException {
        EventLoopGroup bossGroup = new NioEventLoopGroup();
        EventLoopGroup workerGroup = new NioEventLoopGroup();

        try {
            ServerBootstrap bootstrap = new ServerBootstrap();
            bootstrap.group(bossGroup, workerGroup)
                    .channel(NioServerSocketChannel.class)
                    .childHandler(new ChannelInitializer<SocketChannel>() {
                        @Override
                        protected void initChannel(SocketChannel ch) throws Exception {
                            ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO))
//                                    .addLast(new LengthFieldBasedFrameDecoder(200, 0, 4, 0, 4))
                                    .addLast(new ObjectEncoder())
                                    .addLast(new ObjectDecoder(ClassResolvers.cacheDisabled(null)))
                                    .addLast(new ObjectEchoServerHandler());
                        }
                    });
            bootstrap.bind(port).sync().channel().closeFuture().sync();
        } finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }

    }
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:26,代碼來源:ObjectEchoServer.java

示例14: run

import io.netty.handler.codec.serialization.ClassResolvers; //導入依賴的package包/類
public void run(String host, int port) throws Exception {

        EventLoopGroup group = new NioEventLoopGroup();
        try {
            Bootstrap bootstrap = new Bootstrap();
            bootstrap.group(group)
                    .channel(NioSocketChannel.class)
                    .handler(new ChannelInitializer<SocketChannel>() {
                        @Override
                        protected void initChannel(SocketChannel ch) throws Exception {
                            ch.pipeline().addLast(new LoggingHandler(LogLevel.DEBUG))
//                                    .addLast(new LengthFieldPrepender(4))
                                    .addLast(new ObjectEncoder())
                                    .addLast(new ObjectDecoder(ClassResolvers.cacheDisabled(null)))
                                    .addLast(new ObjectEchoClientHandler());
                        }
                    });

            bootstrap.connect(host, port).sync().channel().closeFuture().sync();
        } finally {
            group.shutdownGracefully();
        }
    }
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:24,代碼來源:ObjectEchoClient.java

示例15: run

import io.netty.handler.codec.serialization.ClassResolvers; //導入依賴的package包/類
public void run() throws Exception {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup)
         .channel(NioServerSocketChannel.class)
         .childHandler(new ChannelInitializer<SocketChannel>() {
            @Override
            public void initChannel(SocketChannel ch) throws Exception {
                ch.pipeline().addLast(
                        new ObjectEncoder(),
                        new ObjectDecoder(ClassResolvers.cacheDisabled(null)),
                        new ObjectEchoServerHandler());
            }
         });

        // Bind and start to accept incoming connections.
        b.bind(port).sync().channel().closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
開發者ID:kyle-liu,項目名稱:netty4study,代碼行數:25,代碼來源:ObjectEchoServer.java


注:本文中的io.netty.handler.codec.serialization.ClassResolvers類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。