Created
May 18, 2012 00:41
-
-
Save nickman/2722474 to your computer and use it in GitHub Desktop.
Simple Channel Factory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Executor bossPool = Executors.newCachedThreadPool(); | |
| Executor workerPool = Executors.newCachedThreadPool(); | |
| ChannelFactory channelFactory = new NioClientSocketChannelFactory(boosPool, workerPool); | |
| ChannelPipelineFactory pipelineFactory = new ChannelPipelineFactory() { | |
| public ChannelPipeline getPipeline() throws Exception { | |
| return Channels.pipeline( | |
| new ObjectEncoder() | |
| } | |
| }; | |
| Bootstrap boostrap = new ClientBootstrap(channelFactory); | |
| boostrap.setPipelineFactory(pipelineFactory); | |
| // Phew. Ok. We built all that. Now what ? | |
| InetSocketAddress addressToConnectTo = new InetSocketAddress(remoteHost, remotePort); | |
| bootstrap.connect(addressToConnectTo); | |
| // Alright ! Now we're done, but remeber, that connect call is asynchronous | |
| // so if this line was code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment