private synchronized void initConnection (String host, int port, int 
numberOfThreads, int numberOfConnections,String userGroup) {

if(userGroup=="A"){
 channelPoolA = new FixedChannelPool(.....);
}else if(userGroup=="B"){
 channelPoolB = new FixedChannelPool(.....);
}
}

2017년 6월 13일 화요일 오후 5시 47분 57초 UTC+9, Norman Maurer 님의 말:

> Sorry but I don’t understand what exactly you are asking for.
>
> Can you please try to re-phrase ?
>
>
> On 13. June 2017 at 10:06:55, James Kim ([email protected] <javascript:>) 
> wrote:
>
> i am new to netty and i have a problem using my netty program
>
>
> 1. sendToMessage(String message,String GroupId)
> when user group A come in my sendToMessage i want to create channelPool A
> like this way  user group B come in my sendToMessage i want to create 
> channelPool B
> and next time if user group A come in again, i will return channelPool A
> how can i solve this problem? am i righth?
>
>
> 2. is there Bootstrap option required?
> Bootstrap bootstrap = new Bootstrap();
> bootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
> bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
>
> 3.FixedChannelPool error handling
> => tell me how can i FixedChannelPool error handling?
> ex)acquireTimeoutMillis over time.how?
>
> @Service
> public class NettyPoolService {
>  
>  public static final AttributeKey<CompletableFuture<String>> FUTURE = 
> AttributeKey.valueOf("future");
>  private static final StringDecoder stringDecoder = new 
> StringDecoder(CharsetUtil.UTF_8);
>     private static final StringEncoder stringEncoder = new 
> StringEncoder(CharsetUtil.UTF_8);
>  private static ChannelPool channelPool;
>  private static EventLoopGroup eventLoopGroup;
>  
>  @Value("${host}")
>  private String host;
>  
>  @Value("${port}")
>  private String port;
>  
>  @Value("${connection.count}")
>  private String numberOfConnections;
>  
>  @Value("${thread.count}")
>  private String numberOfThreads;
>  
>  
>  private synchronized void initConnection (String host, int port, int 
> numberOfThreads, int numberOfConnections) {
>   
>   if ( (channelPool != null) && (eventLoopGroup != null) ) {
>    return;
>   }
>   System.out.println("#############################################");
>   System.out.println("initConnection start");
>   
>   eventLoopGroup = new NioEventLoopGroup(numberOfThreads);
>   
>   Bootstrap bootstrap = new Bootstrap();
>         bootstrap.option(ChannelOption.ALLOCATOR, 
> PooledByteBufAllocator.DEFAULT);
>         bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
>         //bootstrap.option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 
> * 1024);
>         //bootstrap.option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 
> 1024);
>         //bootstrap.option(ChannelOption.TCP_NODELAY, true);
>        
>         
> bootstrap.group(eventLoopGroup).channel(NioSocketChannel.class).remoteAddress(host,
>  
> port);
>        
>         int acquireTimeoutMillis = 10000;
>         int maxPendingAcquires = Integer.MAX_VALUE;
>        
>         channelPool = new FixedChannelPool(bootstrap,  
>           new AbstractChannelPoolHandler() {  
>    
>      public void channelCreated(Channel ch) throws Exception {
>       ChannelPipeline pipeline = ch.pipeline();
>                   // decoders
>                   pipeline.addLast("framer", new 
> DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
>                   pipeline.addLast("stringDecoder", stringDecoder);
>   
>                   // encoders
>                   pipeline.addLast("stringEncoder", stringEncoder);
>   
>                   // business logic handler
>                   pipeline.addLast("clientHandler", new 
> ClientPoolHandler(channelPool));
>      }
>     },
>           ChannelHealthChecker.ACTIVE,//eventloop
>           AcquireTimeoutAction.NEW,  //timeout
>           acquireTimeoutMillis,   //
>           numberOfConnections,   //
>           maxPendingAcquires);  //
>        
>         System.out.println("initConnection End");
>         
> System.out.println("#############################################");
>   
>        
>       
>  }//initConnection
>  
>  
>   
>  public void sendToMessage(String message,String GroupId) {
>   
>   System.out.println("=============GroupId=============:"+GroupId);
>   if (channelPool == null) {
>    initConnection(host, Integer.parseInt(port.trim()), 
> Integer.parseInt(numberOfThreads.trim()), 
> Integer.parseInt(numberOfConnections.trim()) );
>   }
>   
>   final CompletableFuture<String> future = new CompletableFuture<String>();
>   Future<Channel> channelFuture = channelPool.acquire();
>   
>   
>
>   
> System.out.println("=============channelFuture.get()=============:"+channelFuture.toString());
>         channelFuture.addListener(new FutureListener<Channel>() {
>             public void operationComplete(Future<Channel> f) {
>                 if (f.isSuccess()) {
>                     Channel channel = f.getNow();
>                     
> channel.attr(NettyPoolClientService.FUTURE).set(future);
>                     channel.writeAndFlush(message, channel.voidPromise());
>                 }
>             }
>         });
>        
>       
>         channelFuture.syncUninterruptibly();
>              
>        
>  }//sendToBnp
> }
> --
> You received this message because you are subscribed to the Google Groups 
> "Netty discussions" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] <javascript:>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/netty/546ab6b1-9277-4c8a-94ea-acaaccea3d42%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/netty/546ab6b1-9277-4c8a-94ea-acaaccea3d42%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/netty/c13ed6c3-7db8-4cc2-8b89-21809a525eaa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to