当前位置: 首页>>代码示例>>Java>>正文


Java ChannelFactory类代码示例

本文整理汇总了Java中io.netty.bootstrap.ChannelFactory的典型用法代码示例。如果您正苦于以下问题:Java ChannelFactory类的具体用法?Java ChannelFactory怎么用?Java ChannelFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ChannelFactory类属于io.netty.bootstrap包,在下文中一共展示了ChannelFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import io.netty.bootstrap.ChannelFactory; //导入依赖的package包/类
/**
 * Start proxy server
 * */
public void start()
    throws InterruptedException {
  ServerBootstrap serverBootstrap = new ServerBootstrap();
  serverBootstrap.group(_acceptorGroup, _upstreamWorkerGroup);
  serverBootstrap.channelFactory(new ChannelFactory<ServerChannel>() {
    @Override
    public ServerChannel newChannel() {
      return new NioServerSocketChannel();
    }
  });
  serverBootstrap.childHandler(new ProxyInitializer(this));

  //bind
  ChannelFuture future = serverBootstrap.bind(_host, _port);

  //wait for the future
  future.awaitUninterruptibly();
  if (!future.isSuccess()) {
    future.channel().closeFuture().awaitUninterruptibly();
    throw new ChannelException(String.format("Failed to bind to: %s:%d", _host, _port), future.cause());
  } else {
    _allChannels.add(future.channel());
  }
}
 
开发者ID:linkedin,项目名称:flashback,代码行数:28,代码来源:ProxyServer.java

示例2: execute

import io.netty.bootstrap.ChannelFactory; //导入依赖的package包/类
@Override
protected Future<?> execute() {
    Bootstrap cb = new Bootstrap().group(proxyServer.getProxyToServerWorkerFor(transportProtocol));

    switch (transportProtocol) {
    case TCP:
        LOG.debug("Connecting to server with TCP");
        cb.channelFactory(new ChannelFactory<Channel>() {
            @Override
            public Channel newChannel() {
                return new NioSocketChannel();
            }
        });
        break;
    case UDT:
        LOG.debug("Connecting to server with UDT");
        cb.channelFactory(NioUdtProvider.BYTE_CONNECTOR)
                .option(ChannelOption.SO_REUSEADDR, true);
        break;
    default:
        throw new UnknownTransportProtocolException(transportProtocol);
    }

    cb.handler(new ChannelInitializer<Channel>() {
        protected void initChannel(Channel ch) throws Exception {
            initChannelPipeline(ch.pipeline(), initialRequest);
        };
    });
    cb.option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
            proxyServer.getConnectTimeout());

    if (localAddress != null) {
        return cb.connect(remoteAddress, localAddress);
    } else {
        return cb.connect(remoteAddress);
    }
}
 
开发者ID:wxyzZ,项目名称:little_mitm,代码行数:38,代码来源:ProxyToServerConnection.java

示例3: execute

import io.netty.bootstrap.ChannelFactory; //导入依赖的package包/类
@Override
protected Future<?> execute() {
    Bootstrap cb = new Bootstrap().group(proxyServer
            .getProxyToServerWorkerFor(transportProtocol));

    switch (transportProtocol) {
    case TCP:
        LOG.debug("Connecting to server with TCP");
        cb.channelFactory(new ChannelFactory<Channel>() {
            @Override
            public Channel newChannel() {
                return new NioSocketChannel();
            }
        });
        break;
    case UDT:
        LOG.debug("Connecting to server with UDT");
        cb.channelFactory(NioUdtProvider.BYTE_CONNECTOR)
                .option(ChannelOption.SO_REUSEADDR, true);
        break;
    default:
        throw new UnknownTransportProtocolError(transportProtocol);
    }

    cb.handler(new ChannelInitializer<Channel>() {
        protected void initChannel(Channel ch) throws Exception {
            initChannelPipeline(ch.pipeline(), initialRequest);
        };
    });
    cb.option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
            proxyServer.getConnectTimeout());

    if (localAddress != null) {
        return cb.connect(remoteAddress, localAddress);
    } else {
        return cb.connect(remoteAddress);
    }
}
 
开发者ID:Elitward,项目名称:LittleProxy,代码行数:39,代码来源:ProxyToServerConnection.java

示例4: datagram

import io.netty.bootstrap.ChannelFactory; //导入依赖的package包/类
public List<BootstrapComboFactory<Bootstrap, Bootstrap>> datagram() {
    // Make the list of Bootstrap factories.
    List<BootstrapFactory<Bootstrap>> bfs = Arrays.asList(
            new BootstrapFactory<Bootstrap>() {
                @Override
                public Bootstrap newInstance() {
                    return new Bootstrap().group(nioWorkerGroup).channelFactory(new ChannelFactory<Channel>() {
                        @Override
                        public Channel newChannel() {
                            return new NioDatagramChannel(InternetProtocolFamily.IPv4);
                        }

                        @Override
                        public String toString() {
                            return NioDatagramChannel.class.getSimpleName() + ".class";
                        }
                    });
                }
            },
            new BootstrapFactory<Bootstrap>() {
                @Override
                public Bootstrap newInstance() {
                    return new Bootstrap().group(oioWorkerGroup).channel(OioDatagramChannel.class);
                }
            }
    );

    // Populare the combinations.
    return combo(bfs, bfs);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:31,代码来源:SocketTestPermutation.java

示例5: datagram

import io.netty.bootstrap.ChannelFactory; //导入依赖的package包/类
@Override
public List<TestsuitePermutation.BootstrapComboFactory<Bootstrap, Bootstrap>> datagram() {
    // Make the list of Bootstrap factories.
    List<BootstrapFactory<Bootstrap>> bfs = Arrays.asList(
            new BootstrapFactory<Bootstrap>() {
                @Override
                public Bootstrap newInstance() {
                    return new Bootstrap().group(nioWorkerGroup).channelFactory(new ChannelFactory<Channel>() {
                        @Override
                        public Channel newChannel() {
                            return new NioDatagramChannel(InternetProtocolFamily.IPv4);
                        }

                        @Override
                        public String toString() {
                            return NioDatagramChannel.class.getSimpleName() + ".class";
                        }
                    });
                }
            },
            new BootstrapFactory<Bootstrap>() {
                @Override
                public Bootstrap newInstance() {
                    return new Bootstrap().group(EPOLL_WORKER_GROUP).channel(EpollDatagramChannel.class);
                }
            }
    );
    return combo(bfs, bfs);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:30,代码来源:EpollSocketTestPermutation.java

示例6: DataServerThread

import io.netty.bootstrap.ChannelFactory; //导入依赖的package包/类
public DataServerThread() {
    dataBossGroup = new NioEventLoopGroup(DATA_BOSS_THREADS);
    dataWorkerGroup = new NioEventLoopGroup(DATA_WORKER_THREADS);
    try {
        Bootstrap b = new Bootstrap();
        b.group(dataWorkerGroup)
                .channelFactory(new ChannelFactory<Channel>() {
                    @Override
                    public Channel newChannel() {
                        return new NioDatagramChannel(InternetProtocolFamily.IPv4);
                    }

                    @Override
                    public String toString() {
                        return NioDatagramChannel.class.getSimpleName() + ".class";
                    }
                }).handler(new ChannelInitializer<DatagramChannel>() {
                    @Override
                    public void initChannel(DatagramChannel ch) throws Exception {
                        ch.config().setAllocator(UnpooledByteBufAllocator.DEFAULT);
                        ch.pipeline().addLast(new DataMessageHandler());
                        if (LOG.isTraceEnabled()) {
                            ch.pipeline().addLast(new LoggingHandler(LogLevel.TRACE));
                        }
                    }

                    @Override
                    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
                        LOG.error("Cannot initialize data server.", cause);
                    }
                });

        // Bind and start to accept incoming connections.
        f = b.bind(getIp(), getDataPort()).sync();
    } catch (InterruptedException ex) {
        LOG.error("Message data interrupted.", ex);
    }
}
 
开发者ID:Archarithms,项目名称:bigio,代码行数:39,代码来源:MeMemberUDP.java

示例7: execute

import io.netty.bootstrap.ChannelFactory; //导入依赖的package包/类
@Override
protected Future<?> execute() {
    Bootstrap cb = new Bootstrap().group(proxyServer
            .getProxyToServerWorkerFor(transportProtocol));

    switch (transportProtocol) {
    case TCP:
        LOG.debug("Connecting to server with TCP");
        cb.channelFactory(new ChannelFactory<Channel>() {
            @Override
            public Channel newChannel() {
                return new NioSocketChannel();
            }
        });
        break;
    /*case UDT:
        LOG.debug("Connecting to server with UDT");
        cb.channelFactory(NioUdtProvider.BYTE_CONNECTOR)
                .option(ChannelOption.SO_REUSEADDR, true);
        break;*/
    default:
        throw new UnknownTransportProtocolError(transportProtocol);
    }

    cb.handler(new ChannelInitializer<Channel>() {
        protected void initChannel(Channel ch) throws Exception {
            initChannelPipeline(ch.pipeline(), initialRequest);
        };
    });
    cb.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 40 * 1000);

    if (localAddress != null) {
        return cb.connect(remoteAddress, localAddress);
    } else {
        return cb.connect(remoteAddress);
    }
}
 
开发者ID:Mobideck,项目名称:appdeck-android,代码行数:38,代码来源:ProxyToServerConnection.java

示例8: UDPMulticastBeacon

import io.netty.bootstrap.ChannelFactory; //导入依赖的package包/类
/**
 * Creates a new UDPMulticastBeacon.
 * 
 * @param factory
 *            a ChannelFactory
 * @param group
 *            the EventLoopGroup to use for channels and the timer
 * @param executor
 *            the executor for application code and a timer for regularly sending the beacon
 * @param moduleID
 *            the ModuleID to announce
 * @param interval
 *            the interval at which to send beacons
 * @param unit
 *            the unit for interval
 */
public UDPMulticastBeacon(final ChannelFactory<? extends DatagramChannel> factory, final EventLoopGroup group,
		final ScheduledExecutorService executor, final ModuleID moduleID, final long interval, final TimeUnit unit) {
	beacon =
			new AtomicReference<BeaconMessage>(new BeaconMessage(moduleID,
					Collections.<InetSocketAddress> emptyList()));

	executor.scheduleAtFixedRate(new Runnable() {
		@Override
		public void run() {
			sendBeacon();
		}
	}, 0, interval, unit);

	final MessageAdapter messageAdapter = new MessageAdapter();
	messageAdapter.addMessageType(BeaconMessage.class);
	final GsonCodec gsonCodec = new GsonCodec(Message.class);
	gsonCodec.registerTypeAdapter(Message.class, messageAdapter);
	gsonCodec.registerTypeAdapter(InetSocketAddress.class, new InetSocketAddressAdapter());
	gsonCodec.registerTypeAdapter(BeaconMessage.class, new BeaconMessageDeserializer());

	this.channelFactory = new UDPMulticastChannelFactory(factory, group, new ChannelInitializer<DatagramChannel>() {
		private final DatagramPacketWrapper datagramPacketWrapper = new DatagramPacketWrapper();
		private final StringEncoder stringEncoder = new StringEncoder();
		private final StringDecoder stringDecoder = new StringDecoder();
		private final ChannelHandler beaconHandler = new BeaconHandler();

		@Override
		protected void initChannel(final DatagramChannel channel) {
			channel.pipeline().addLast(datagramPacketWrapper).addLast(stringEncoder).addLast(stringDecoder)
					.addLast(gsonCodec).addLast(beaconHandler);

			// Move TARGET_ADDRESS from channel context to handler context
			channel.pipeline().context(DatagramPacketWrapper.class).attr(DatagramPacketWrapper.TARGET_ADDRESS)
					.set(channel.attr(DatagramPacketWrapper.TARGET_ADDRESS).getAndRemove());
		}
	});
}
 
开发者ID:DesignAndDeploy,项目名称:dnd,代码行数:54,代码来源:UDPMulticastBeacon.java

示例9: main

import io.netty.bootstrap.ChannelFactory; //导入依赖的package包/类
public static void main(String[] args) {
	Stopwatch watch = new Stopwatch();
	watch.start();

	GlydarBootstrap bootstrap = new GlydarBootstrap(args);
	server = new GServer(bootstrap);
	ParaGlydar.setServer(server);
	serverThread = new Thread(server);

	serverBootstrap = new ServerBootstrap();
	serverBootstrap.childHandler(new ProtocolInitializer())
			.option(ChannelOption.TCP_NODELAY, true)
			.option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 32 * 1024)
			.option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 64 * 1024)
			.group(new NioEventLoopGroup())
			.channelFactory(new ChannelFactory<ServerChannel>() {
				@Override
				public ServerChannel newChannel() {
					return new NioServerSocketChannel();
				}
			})
			.bind(new InetSocketAddress(server.getConfig().getPort()));

	server.setUpWorlds();

	try {
		server.getPluginLoader().loadPlugins();
	} catch (Exception exc) {
		server.getLogger().warning(exc, "Error while loading plugins");
	}

	server.getLogger().info("Server ready on port {0}", server.getConfig().getPort());
	server.getLogger().info("This server is running {0} version {1}", server.getName(), server.getVersion());

	watch.stop();
	server.getLogger().info("Server started in {0}ms", watch.elapsed(TimeUnit.MILLISECONDS));

	server.getCommandReader().start();
	serverThread.start();
}
 
开发者ID:Glydar,项目名称:Glydar,代码行数:41,代码来源:Glydar.java

示例10: getChannelFactory

import io.netty.bootstrap.ChannelFactory; //导入依赖的package包/类
public ChannelFactory<Channel> getChannelFactory() {
    return channelFactory;
}
 
开发者ID:epsilony,项目名称:codec-modbus,代码行数:4,代码来源:ModbusClientMaster.java

示例11: setChannelFactory

import io.netty.bootstrap.ChannelFactory; //导入依赖的package包/类
public void setChannelFactory(ChannelFactory<Channel> channelFactory) {
    this.channelFactory = channelFactory;
}
 
开发者ID:epsilony,项目名称:codec-modbus,代码行数:4,代码来源:ModbusClientMaster.java

示例12: datagram

import io.netty.bootstrap.ChannelFactory; //导入依赖的package包/类
static List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> datagram() {
    List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> list =
            new ArrayList<Entry<Factory<Bootstrap>, Factory<Bootstrap>>>();

    // Make the list of Bootstrap factories.
    List<Factory<Bootstrap>> bfs =
            new ArrayList<Factory<Bootstrap>>();
    bfs.add(new Factory<Bootstrap>() {
        @Override
        public Bootstrap newInstance() {
            return new Bootstrap().group(nioWorkerGroup).channelFactory(new ChannelFactory<Channel>() {
                @Override
                public Channel newChannel() {
                   return new NioDatagramChannel(InternetProtocolFamily.IPv4);
                }

                @Override
                public String toString() {
                    return NioDatagramChannel.class.getSimpleName() + ".class";
                }
            });
        }
    });
    bfs.add(new Factory<Bootstrap>() {
        @Override
        public Bootstrap newInstance() {
            return new Bootstrap().group(oioWorkerGroup).channel(OioDatagramChannel.class);
        }
    });

    // Populate the combinations
    for (Factory<Bootstrap> sbf: bfs) {
        for (Factory<Bootstrap> cbf: bfs) {
            final Factory<Bootstrap> sbf0 = sbf;
            final Factory<Bootstrap> cbf0 = cbf;
            list.add(new Entry<Factory<Bootstrap>, Factory<Bootstrap>>() {
                @Override
                public Factory<Bootstrap> getKey() {
                    return sbf0;
                }

                @Override
                public Factory<Bootstrap> getValue() {
                    return cbf0;
                }

                @Override
                public Factory<Bootstrap> setValue(Factory<Bootstrap> value) {
                    throw new UnsupportedOperationException();
                }
            });
        }
    }

    return list;
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:57,代码来源:SocketTestPermutation.java

示例13: doStart

import io.netty.bootstrap.ChannelFactory; //导入依赖的package包/类
private void doStart() {
    ServerBootstrap serverBootstrap = new ServerBootstrap().group(
            serverGroup.clientToProxyBossPools.get(transportProtocol),
            serverGroup.clientToProxyWorkerPools.get(transportProtocol));

    ChannelInitializer<Channel> initializer = new ChannelInitializer<Channel>() {
        protected void initChannel(Channel ch) throws Exception {
            new ClientToProxyConnection(
                    DefaultHttpProxyServer.this,
                    sslEngineSource,
                    authenticateSslClients,
                    ch.pipeline());
        };
    };
    switch (transportProtocol) {
    case TCP:
        Log.i(TAG, "Proxy listening with TCP transport");
        serverBootstrap.channelFactory(new ChannelFactory<ServerChannel>() {
            @Override
            public ServerChannel newChannel() {
                return new NioServerSocketChannel();
            }
        });
        break;
    /*case UDT:
        LOG.info("Proxy listening with UDT transport");
        serverBootstrap.channelFactory(NioUdtProvider.BYTE_ACCEPTOR)
                .option(ChannelOption.SO_BACKLOG, 10)
                .option(ChannelOption.SO_REUSEADDR, true);
        break;*/
    default:
        throw new UnknownTransportProtocolError(transportProtocol);
    }
    serverBootstrap.childHandler(initializer);
    serverBootstrap.bind(address).addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future)
                throws Exception {
            registerChannel(future.channel());
        }
    }).awaitUninterruptibly();
}
 
开发者ID:Mobideck,项目名称:appdeck-android,代码行数:43,代码来源:DefaultHttpProxyServer.java

示例14: doStart

import io.netty.bootstrap.ChannelFactory; //导入依赖的package包/类
private void doStart() {
    ServerBootstrap serverBootstrap = new ServerBootstrap().group(
            serverGroup.clientToProxyBossPools.get(transportProtocol),
            serverGroup.clientToProxyWorkerPools.get(transportProtocol));

    ChannelInitializer<Channel> initializer = new ChannelInitializer<Channel>() {
        protected void initChannel(Channel ch) throws Exception {
            new ClientToProxyConnection(
                    DefaultHttpProxyServer.this,
                    sslEngineSource,
                    authenticateSslClients,
                    ch.pipeline());
        };
    };
    switch (transportProtocol) {
    case TCP:
        LOG.info("Proxy listening with TCP transport");
        serverBootstrap.channelFactory(new ChannelFactory<ServerChannel>() {
            @Override
            public ServerChannel newChannel() {
                return new NioServerSocketChannel();
            }
        });
        break;
    /*case UDT:
        LOG.info("Proxy listening with UDT transport");
        serverBootstrap.channelFactory(NioUdtProvider.BYTE_ACCEPTOR)
                .option(ChannelOption.SO_BACKLOG, 10)
                .option(ChannelOption.SO_REUSEADDR, true);
        break;*/
    default:
        throw new UnknownTransportProtocolError(transportProtocol);
    }
    serverBootstrap.childHandler(initializer);
    serverBootstrap.bind(address).addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future)
                throws Exception {
            registerChannel(future.channel());
        }
    }).awaitUninterruptibly();
}
 
开发者ID:Mobideck,项目名称:appdeck-android,代码行数:43,代码来源:DefaultHttpProxyServer.java

示例15: datagram

import io.netty.bootstrap.ChannelFactory; //导入依赖的package包/类
static List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> datagram() {
    List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> list =
            new ArrayList<Entry<Factory<Bootstrap>, Factory<Bootstrap>>>();

    // Make the list of Bootstrap factories.
    List<Factory<Bootstrap>> bfs = new ArrayList<Factory<Bootstrap>>();
    bfs.add(new Factory<Bootstrap>() {
        @Override
        public Bootstrap newInstance() {
            return new Bootstrap().group(nioWorkerGroup).channelFactory(new ChannelFactory<Channel>() {
                @Override
                public Channel newChannel(EventLoop eventLoop) {
                   return new NioDatagramChannel(eventLoop, InternetProtocolFamily.IPv4);
                }

                @Override
                public String toString() {
                    return NioDatagramChannel.class.getSimpleName() + ".class";
                }
            });
        }
    });
    bfs.add(new Factory<Bootstrap>() {
        @Override
        public Bootstrap newInstance() {
            return new Bootstrap().group(oioWorkerGroup).channel(OioDatagramChannel.class);
        }
    });

    // Populate the combinations
    for (Factory<Bootstrap> sbf: bfs) {
        for (Factory<Bootstrap> cbf: bfs) {
            final Factory<Bootstrap> sbf0 = sbf;
            final Factory<Bootstrap> cbf0 = cbf;
            list.add(new Entry<Factory<Bootstrap>, Factory<Bootstrap>>() {
                @Override
                public Factory<Bootstrap> getKey() {
                    return sbf0;
                }

                @Override
                public Factory<Bootstrap> getValue() {
                    return cbf0;
                }

                @Override
                public Factory<Bootstrap> setValue(Factory<Bootstrap> value) {
                    throw new UnsupportedOperationException();
                }
            });
        }
    }

    return list;
}
 
开发者ID:nathanchen,项目名称:netty-netty-5.0.0.Alpha1,代码行数:56,代码来源:SocketTestPermutation.java


注:本文中的io.netty.bootstrap.ChannelFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。