本文整理匯總了Java中org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory類的典型用法代碼示例。如果您正苦於以下問題:Java NioClientSocketChannelFactory類的具體用法?Java NioClientSocketChannelFactory怎麽用?Java NioClientSocketChannelFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
NioClientSocketChannelFactory類屬於org.jboss.netty.channel.socket.nio包,在下文中一共展示了NioClientSocketChannelFactory類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: start
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; //導入依賴的package包/類
public void start(String ip, int port) {
// Configure the client.
System.setProperty("java.net.preferIPv4Stack", "true");
System.setProperty("java.net.preferIPv6Addresses", "false");
bootstrap = new ClientBootstrap(
new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
// Set up the event pipeline factory.
// bootstrap.setPipelineFactory(new MessageServerPipelineFactory());
bootstrap.getPipeline().addLast("decoder", new PackageDecoder());
bootstrap.getPipeline().addLast("encoder", new PackageEncoder());
bootstrap.getPipeline().addLast("handler", new ClientHandler());
bootstrap.setOption("tcpNoDelay", true);
bootstrap.setOption("keepAlive", true);
bootstrap.setOption("child.linger", 1);
// Start the connection attempt.
channelFuture = bootstrap.connect(new InetSocketAddress(ip, port));
// Wait until the connection is closed or the connection attempt fails.
channelFuture.awaitUninterruptibly();
channel = channelFuture.awaitUninterruptibly().getChannel();
}
示例2: run
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; //導入依賴的package包/類
public void run() {
// Configure the client.
ChannelFactory factory = new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(), Executors.newCachedThreadPool(), 1, 1);
ClientBootstrap bootstrap = new ClientBootstrap(factory);
// Set up the pipeline factory.
bootstrap.setPipelineFactory(setPipelineFactory());
bootstrap.setOption("tcpNoDelay", true);
bootstrap.setOption("keepAlive", true);
// Start the connection attempt.
ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));
if (oneShot) {
// Wait until the connection is closed or the connection attempt fails.
future.getChannel().getCloseFuture().awaitUninterruptibly();
// Shut down thread pools to exit.
bootstrap.releaseExternalResources();
}
}
示例3: connect
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; //導入依賴的package包/類
/**
* Starts the BGP peer.
*
* @param connectToSocket the socket to connect to
*/
private void connect(InetSocketAddress connectToSocket)
throws InterruptedException {
ChannelFactory channelFactory =
new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool());
ChannelPipelineFactory pipelineFactory = () -> {
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("BgpPeerFrameDecoderTest",
peerFrameDecoder);
pipeline.addLast("BgpPeerChannelHandlerTest",
peerChannelHandler);
return pipeline;
};
peerBootstrap = new ClientBootstrap(channelFactory);
peerBootstrap.setOption("child.keepAlive", true);
peerBootstrap.setOption("child.tcpNoDelay", true);
peerBootstrap.setPipelineFactory(pipelineFactory);
peerBootstrap.connect(connectToSocket);
}
示例4: connectFrom
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; //導入依賴的package包/類
private Channel connectFrom(InetSocketAddress connectToSocket, SocketAddress localAddress)
throws InterruptedException {
ChannelFactory channelFactory =
new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool());
ChannelPipelineFactory pipelineFactory = () -> {
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("BgpPeerFrameDecoderTest",
peerFrameDecoder);
pipeline.addLast("BgpPeerChannelHandlerTest",
peerChannelHandler);
return pipeline;
};
peerBootstrap = new ClientBootstrap(channelFactory);
peerBootstrap.setOption("child.keepAlive", true);
peerBootstrap.setOption("child.tcpNoDelay", true);
peerBootstrap.setPipelineFactory(pipelineFactory);
Channel channel = peerBootstrap.connect(connectToSocket, localAddress).getChannel();
return channel;
}
示例5: startClients
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; //導入依賴的package包/類
/**
* Connect to remote servers. We'll initiate the connection to
* any nodes with a lower ID so that there will be a single connection
* between each pair of nodes which we'll use symmetrically
*/
protected void startClients(ChannelPipelineFactory pipelineFactory) {
final ClientBootstrap bootstrap =
new ClientBootstrap(
new NioClientSocketChannelFactory(bossExecutor,
workerExecutor));
bootstrap.setOption("child.reuseAddr", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.sendBufferSize", SEND_BUFFER_SIZE);
bootstrap.setOption("child.connectTimeoutMillis", CONNECT_TIMEOUT);
bootstrap.setPipelineFactory(pipelineFactory);
clientBootstrap = bootstrap;
ScheduledExecutorService ses =
syncManager.getThreadPool().getScheduledExecutor();
reconnectTask = new SingletonTask(ses, new ConnectTask());
reconnectTask.reschedule(0, TimeUnit.SECONDS);
}
示例6: init
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; //導入依賴的package包/類
public void init() throws SyncException {
cg = new DefaultChannelGroup("Cluster Bootstrap");
bossExecutor = Executors.newCachedThreadPool();
workerExecutor = Executors.newCachedThreadPool();
bootstrap =
new ClientBootstrap(new NioClientSocketChannelFactory(bossExecutor,
workerExecutor));
bootstrap.setOption("child.reuseAddr", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.sendBufferSize",
RPCService.SEND_BUFFER_SIZE);
bootstrap.setOption("child.receiveBufferSize",
RPCService.SEND_BUFFER_SIZE);
bootstrap.setOption("child.connectTimeoutMillis",
RPCService.CONNECT_TIMEOUT);
pipelineFactory = new BootstrapPipelineFactory(this);
bootstrap.setPipelineFactory(pipelineFactory);
}
示例7: startUp
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; //導入依賴的package包/類
@Override
public void startUp(FloodlightModuleContext context)
throws FloodlightModuleException {
shutdown = false;
bossExecutor = Executors.newCachedThreadPool();
workerExecutor = Executors.newCachedThreadPool();
final ClientBootstrap bootstrap =
new ClientBootstrap(
new NioClientSocketChannelFactory(bossExecutor,
workerExecutor));
bootstrap.setOption("child.reuseAddr", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.sendBufferSize",
RPCService.SEND_BUFFER_SIZE);
bootstrap.setOption("child.receiveBufferSize",
RPCService.SEND_BUFFER_SIZE);
bootstrap.setOption("child.connectTimeoutMillis",
RPCService.CONNECT_TIMEOUT);
pipelineFactory = new RemoteSyncPipelineFactory(this);
bootstrap.setPipelineFactory(pipelineFactory);
clientBootstrap = bootstrap;
}
示例8: BookKeeper
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; //導入依賴的package包/類
/**
* Create a bookkeeper client. A zookeeper client and a client socket factory
* will be instantiated as part of this constructor.
*
* @param servers
* A list of one of more servers on which zookeeper is running. The
* client assumes that the running bookies have been registered with
* zookeeper under the path
* {@link BookieWatcher#BOOKIE_REGISTRATION_PATH}
* @throws IOException
* @throws InterruptedException
* @throws KeeperException
*/
public BookKeeper(String servers) throws IOException, InterruptedException,
KeeperException {
this(new ZooKeeper(servers, 10000, new Watcher() {
@Override
public void process(WatchedEvent event) {
// TODO: handle session disconnects and expires
if (LOG.isDebugEnabled()) {
LOG.debug("Process: " + event.getType() + " " + event.getPath());
}
}
}), new NioClientSocketChannelFactory(Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
ownZKHandle = true;
ownChannelFactory = true;
}
示例9: NiftyClient
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; //導入依賴的package包/類
public NiftyClient(NettyClientConfig nettyClientConfig, boolean local) {
this.nettyClientConfig = nettyClientConfig;
if (local) {
log.warn("Using local client");
this.channelFactory = new DefaultLocalClientChannelFactory();
this.timer = null;
this.bossExecutor = null;
this.workerExecutor = null;
this.defaultSocksProxyAddress = null;
} else {
this.timer = nettyClientConfig.getTimer();
this.bossExecutor = nettyClientConfig.getBossExecutor();
this.workerExecutor = nettyClientConfig.getWorkerExecutor();
this.defaultSocksProxyAddress = nettyClientConfig.getDefaultSocksProxyAddress();
int bossThreadCount = nettyClientConfig.getBossThreadCount();
int workerThreadCount = nettyClientConfig.getWorkerThreadCount();
NioWorkerPool workerPool = new NioWorkerPool(workerExecutor, workerThreadCount, ThreadNameDeterminer.CURRENT);
NioClientBossPool bossPool = new NioClientBossPool(bossExecutor, bossThreadCount, timer, ThreadNameDeterminer.CURRENT);
this.channelFactory = new NioClientSocketChannelFactory(bossPool, workerPool);
}
}
示例10: start
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; //導入依賴的package包/類
public synchronized void start() {
final Executor bossPool = Executors.newCachedThreadPool();
final Executor workerPool = Executors.newCachedThreadPool();
bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(bossPool, workerPool));
final ClientSocketChannelFactory clientSocketChannelFactory = new NioClientSocketChannelFactory(bossPool, workerPool);
bootstrap.setOption("child.tcpNoDelay", true);
allChannels = new DefaultChannelGroup("handler");
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(new FrontendHandler(allChannels, clientSocketChannelFactory, serverPool, statistics));
}
});
log.info("Starting on port {}", port);
acceptor = bootstrap.bind(new InetSocketAddress(port));
if (acceptor.isBound()) {
log.info("Server started successfully");
}
}
示例11: connectMasterServer
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; //導入依賴的package包/類
/**
* Connect master server for message communication.
*/
private void connectMasterServer() {
this.messageClient = new ClientBootstrap(new NioClientSocketChannelFactory(Executors.newSingleThreadExecutor(),
Executors.newSingleThreadExecutor()));
// Set up the pipeline factory.
this.messageClient.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(new NettyBytableEncoder(), new NettyBytableDecoder(), new ClientHandler());
}
});
String[] namePortGroup = this.masterServerAddress.split(":");
String masterServerName = namePortGroup[0];
int masterServerPort = NumberFormatUtils.getInt(namePortGroup[1]);
// Start the connection attempt.
ChannelFuture future = this.messageClient.connect(new InetSocketAddress(masterServerName, masterServerPort));
this.clientChannel = future.awaitUninterruptibly().getChannel();
LOG.info("Connect to {}:{}", masterServerName, masterServerPort);
}
示例12: initRPCClient
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; //導入依賴的package包/類
/**
* Connect to app master for status RPC report.
*/
private void initRPCClient() {
this.rpcClient = new ClientBootstrap(new NioClientSocketChannelFactory(Executors.newSingleThreadExecutor(),
Executors.newSingleThreadExecutor()));
// Set up the pipeline factory.
this.rpcClient.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(new ObjectEncoder(),
new ObjectDecoder(ClassResolvers.cacheDisabled(getClass().getClassLoader())),
new ClientHandler());
}
});
// Start the connection attempt.
ChannelFuture future = this.rpcClient.connect(new InetSocketAddress(this.rpcHostName, this.rpcPort));
LOG.info("Connect to {}:{}", this.rpcHostName, this.rpcPort);
this.rpcClientChannel = future.awaitUninterruptibly().getChannel();
}
示例13: connect
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; //導入依賴的package包/類
public void connect() throws IOException {
this.bootstrap = new ClientBootstrap(
new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
this.bootstrap.setPipelineFactory(new NettyTCPWriterPipelineFactory(this.bootstrap, this.channel, this.timer));
//this.bootstrap.setOption("tcpNoDelay", true);
// TODO: do some exception handling here
bootstrap.setOption("remoteAddress", new InetSocketAddress(this.host, this.port));
this.future = this.bootstrap.connect();
this.channel = this.future.awaitUninterruptibly().getChannel();
this.channel.setReadable(false);
if(!this.future.isSuccess()){
logger.info("NettyTCP: future unsuccessful");
}
}