public LocalServerChannel newChannel(ChannelPipeline pipeline) { LocalServerChannel channel = new DefaultLocalServerChannel(this, pipeline, sink); group.add(channel); return channel; }
public synchronized boolean add(Channel channel) { if (channel != null) { if (channel.getRemoteAddress() != null) { channelMap.put(channel.getRemoteAddress().toString(), channel); } return super.add(channel); } else { return false; } }
@Override public boolean add(Channel channel) { // Synchronization must occur to avoid add() and close() overlap (thus potentially leaving one channel open). // This could also be done by synchronizing the method itself but using a read lock here (rather than a // synchronized() block) allows multiple concurrent calls to add(). this.lock.readLock().lock(); try { if (this.closed.get()) { // Immediately close channel, as close() was already called. Channels.silentlyCloseChannel(channel); return false; } return super.add(channel); } finally { this.lock.readLock().unlock(); } } }
/** * On open we manage some statistics, and add this connection to the channel group. * * @param channelHandlerContext * @param channelStateEvent * @throws Exception */ @Override public void channelOpen(ChannelHandlerContext channelHandlerContext, ChannelStateEvent channelStateEvent) throws Exception { total_conns.incrementAndGet(); curr_conns.incrementAndGet(); channelGroup.add(channelHandlerContext.getChannel()); }
@Override public void channelOpen(final ChannelHandlerContext ctx, final ChannelStateEvent e) { channels.add(e.getChannel()); connections_established.incrementAndGet(); }
@Override public void childChannelOpen(ChannelHandlerContext ctx, ChildChannelStateEvent e) throws Exception { closeableChannels.add(e.getChildChannel()); }
public boolean addConnection(Connection c) { return channel.add(c.getChannel()); }
@Override public boolean add(Channel channel) { if (channel instanceof ServerChannel) return super.add(channel); else { final NodeInfo node = getNodeInfo(channel); if (node == null) { LOG.warn("Received connection from an unknown address {}.", channel.getRemoteAddress()); throw new RuntimeException("Unknown node for address " + channel.getRemoteAddress()); } final boolean added = super.add(channel); if (added) channels.put(node, channel); return added; } }
public synchronized boolean add(Channel channel) { if (channel != null) { if (channel.getRemoteAddress() != null) { channelMap.put(channel.getRemoteAddress().toString(), channel); } return super.add(channel); } else { return false; } }
@Override public boolean add(Channel channel) { // Synchronization must occur to avoid add() and close() overlap (thus potentially leaving one channel open). // This could also be done by synchronizing the method itself but using a read lock here (rather than a // synchronized() block) allows multiple concurrent calls to add(). this.lock.readLock().lock(); try { if (this.closed.get()) { // Immediately close channel, as close() was already called. channel.close(); return false; } return super.add(channel); } finally { this.lock.readLock().unlock(); } } }
@Override public boolean add(Channel channel) { // Synchronization must occur to avoid add() and close() overlap (thus potentially leaving one channel open). // This could also be done by synchronizing the method itself but using a read lock here (rather than a // synchronized() block) allows multiple concurrent calls to add(). this.lock.readLock().lock(); try { if (this.closed.get()) { // Immediately close channel, as close() was already called. Channels.silentlyCloseChannel(channel); return false; } return super.add(channel); } finally { this.lock.readLock().unlock(); } } }
@Override public boolean add(Channel channel) { // Synchronization must occur to avoid add() and close() overlap (thus potentially leaving one channel open). // This could also be done by synchronizing the method itself but using a read lock here (rather than a // synchronized() block) allows multiple concurrent calls to add(). this.lock.readLock().lock(); try { if (this.closed.get()) { // Immediately close channel, as close() was already called. Channels.silentlyCloseChannel(channel); return false; } return super.add(channel); } finally { this.lock.readLock().unlock(); } } }
protected void bind() { Channel channel = bootstrap.bind(new InetSocketAddress(port)); channels.add(channel); LOG.info("Channel {} listening on port {}", channel, port); setReady(true); }
@Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { channelGroup.add(future.getChannel()); } } });
@Override public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { if (channelGroup != null) channelGroup.add(e.getChannel()); super.channelConnected(ctx, e); }
@Override public boolean add(Channel channel) { if (channel instanceof ServerChannel) return super.add(channel); else { final NodeInfo node = ChannelNodeInfo.nodeInfo.get(channel); if (node == null) { LOG.warn("Received connection from an unknown address {}.", channel.getRemoteAddress()); throw new RuntimeException("Unknown node for address " + channel.getRemoteAddress()); } final short nodeId = node.getNodeId(); if (channels.containsKey(nodeId)) { LOG.warn("Received connection from address {} of node {}, but this node is already connected.", channel.getRemoteAddress(), nodeId); throw new RuntimeException("Node " + nodeId + " already connected."); } final boolean added = super.add(channel); if (added) channels.put(nodeId, channel); return added; } }
public void broadcast(Connection except, GameDownBuffer buffer) throws Exception { channel.remove(except.getChannel()); broadcast(buffer); channel.add(except.getChannel()); }
/** * Bind the network connection and start the network processing threads. */ public void start() { // TODO provide tweakable options here for passing in custom executors. channelFactory = new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); allChannels = new DefaultChannelGroup("jmemcachedChannelGroup"); ServerBootstrap bootstrap = new ServerBootstrap(channelFactory); ChannelPipelineFactory pipelineFactory; if (binary) pipelineFactory = createMemcachedBinaryPipelineFactory(cache, memcachedVersion, verbose, idleTime, allChannels); else pipelineFactory = createMemcachedPipelineFactory(cache, memcachedVersion, verbose, idleTime, frameSize, allChannels); bootstrap.setPipelineFactory(pipelineFactory); bootstrap.setOption("sendBufferSize", 65536 ); bootstrap.setOption("receiveBufferSize", 65536); Channel serverChannel = bootstrap.bind(addr); allChannels.add(serverChannel); log.info("Listening on " + String.valueOf(addr.getHostName()) + ":" + addr.getPort()); running = true; }
private void connectClient(ClientBootstrapResolver clientResolver) throws Exception { final RegionInfo regionInfo = clientResolver.getRegionInfo(); ClientBootstrap client = clientResolver.resolve(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("[id: ] connect " + client.getOption("remoteAddress")); } ChannelFuture connectFuture = client.connect(); connectFutures.add(connectFuture); closeableChannels.add(connectFuture.getChannel()); connectFuture.addListener(createConnectCompleteListener(regionInfo)); }
public boolean start() { this.serverFactory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); this.channelGroup = new DefaultChannelGroup(this + "-channelGroup"); ChannelPipelineFactory pipelineFactory = new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("encoder", new ObjectEncoder()); pipeline.addLast("decoder", new ObjectDecoder()); pipeline.addLast("handler", new ServerHandler(channelGroup)); return pipeline; } }; ServerBootstrap bootstrap = new ServerBootstrap(this.serverFactory); bootstrap.setOption("reuseAddress", true); bootstrap.setOption("child.tcpNoDelay", true); bootstrap.setOption("child.keepAlive", true); bootstrap.setPipelineFactory(pipelineFactory); Channel channel = bootstrap.bind(new InetSocketAddress(this.host, this.port)); if (!channel.isBound()) { this.stop(); return false; } this.channelGroup.add(channel); return true; }