OioAcceptedSocketChannel( Channel parent, ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink, Socket socket) { super(parent, factory, pipeline, sink, socket); try { in = new PushbackInputStream(socket.getInputStream(), 1); } catch (IOException e) { throw new ChannelException("Failed to obtain an InputStream.", e); } try { out = socket.getOutputStream(); } catch (IOException e) { throw new ChannelException("Failed to obtain an OutputStream.", e); } fireChannelOpen(this); fireChannelBound(this, getLocalAddress()); }
/** * Creates a new channel which is bound to the specified local address. This operation will block until * the channel is bound. * * @return a new bound channel which accepts incoming connections * * @throws ChannelException * if failed to create a new channel and * bind it to the local address */ public Channel bind(final SocketAddress localAddress) { ChannelFuture future = bindAsync(localAddress); // Wait for the future. future.awaitUninterruptibly(); if (!future.isSuccess()) { future.getChannel().close().awaitUninterruptibly(); throw new ChannelException("Failed to bind to: " + localAddress, future.getCause()); } return future.getChannel(); }
OioSocketChannel( Channel parent, ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink, Socket socket) { super(parent, factory, pipeline, sink); this.socket = socket; try { socket.setSoTimeout(1000); } catch (SocketException e) { throw new ChannelException( "Failed to configure the OioSocketChannel socket timeout.", e); } config = new DefaultSocketChannelConfig(socket); }
public void setTcpNoDelay(boolean tcpNoDelay) { try { socket.setTcpNoDelay(tcpNoDelay); } catch (SocketException e) { throw new ChannelException(e); } }
@Override public void operationComplete(ChannelFuture f) if (f.isSuccess()) { sslHandler.handshake().addListener( new ChannelFutureListener() } else { handshakeFuture.setFailure( new ChannelException( StringUtils.format("Failed to handshake with host[%s]", hostname), f2.getCause() handshakeFuture.setFailure( new ChannelException( StringUtils.format("Failed to connect to host[%s]", hostname), f.getCause()
public void setKeepAlive(boolean keepAlive) { try { socket.setKeepAlive(keepAlive); } catch (SocketException e) { throw new ChannelException(e); } }
@Override public void operationComplete(ChannelFuture future) { if (!future.isSuccess()) { channel.close(); channelResourceContainer.returnResource(); if (!retVal.isDone()) { retVal.setException( new ChannelException( StringUtils.format("[%s] Failed to write request to channel", requestDesc), future.getCause() ) ); } } } }
public void setSoLinger(int soLinger) { try { if (soLinger < 0) { socket.setSoLinger(false, 0); } else { socket.setSoLinger(true, soLinger); } } catch (SocketException e) { throw new ChannelException(e); } }
public void setSendBufferSize(int sendBufferSize) { try { socket.setSendBufferSize(sendBufferSize); } catch (SocketException e) { throw new ChannelException(e); } }
public void setReceiveBufferSize(int receiveBufferSize) { try { socket.setReceiveBufferSize(receiveBufferSize); } catch (SocketException e) { throw new ChannelException(e); } }
OioDatagramChannel( ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink) { super(null, factory, pipeline, sink); try { socket = new MulticastSocket(null); } catch (IOException e) { throw new ChannelException("Failed to open a datagram socket.", e); } try { socket.setSoTimeout(10); socket.setBroadcast(false); } catch (SocketException e) { throw new ChannelException( "Failed to configure the datagram socket timeout.", e); } config = new DefaultDatagramChannelConfig(socket); fireChannelOpen(this); }
public void setReuseAddress(boolean reuseAddress) { try { socket.setReuseAddress(reuseAddress); } catch (SocketException e) { throw new ChannelException(e); } }
@Override protected void unbindRequested(ChannelPipeline pipeline, ChannelStateEvent evt) throws Exception { final BBoshServerChannel bboshUnbindChannel = (BBoshServerChannel) evt.getChannel(); final ChannelFuture bboshUnbindFuture = evt.getFuture(); ChannelAddress bboshLocalAddress = bboshUnbindChannel.getLocalAddress(); URI bboshLocation = bboshLocalAddress.getLocation(); if (!bboshBindings.remove(bboshLocation, bboshUnbindChannel)) { bboshUnbindFuture.setFailure(new ChannelException("Channel not bound")); return; } Channel transport = bboshUnbindChannel.getTransport(); ChannelFuture unbindFuture = transport.unbind(); if (unbindFuture.isDone()) { handleBBoshTransportUnbindComplete(bboshUnbindChannel, bboshUnbindFuture, unbindFuture); } else { unbindFuture.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture unbindFuture) throws Exception { handleBBoshTransportUnbindComplete(bboshUnbindChannel, bboshUnbindFuture, unbindFuture); } }); } }
public int getReceiveBufferSize() { try { return socket.getReceiveBufferSize(); } catch (SocketException e) { throw new ChannelException(e); } }
public int getSendBufferSize() { try { return socket.getSendBufferSize(); } catch (SocketException e) { throw new ChannelException(e); } }
public void setReuseAddress(boolean reuseAddress) { try { socket.setReuseAddress(reuseAddress); } catch (SocketException e) { throw new ChannelException(e); } }
tlsUnbindFuture.setFailure(new ChannelException("Channel not bound")); return; if (unbindFuture.isDone()) { handleTlsTransportUnbindComplete(tlsUnbindChannel, tlsUnbindFuture, unbindFuture); unbindFuture.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture unbindFuture) throws Exception { fireChannelUnbound(tlsUnbindChannel); tlsUnbindFuture.setSuccess();
public void setTimeToLive(int ttl) { if (socket instanceof MulticastSocket) { try { ((MulticastSocket) socket).setTimeToLive(ttl); } catch (IOException e) { throw new ChannelException(e); } } else { throw new UnsupportedOperationException(); } }
public void setTrafficClass(int trafficClass) { try { socket.setTrafficClass(trafficClass); } catch (SocketException e) { throw new ChannelException(e); } } }
public boolean isTcpNoDelay() { try { return socket.getTcpNoDelay(); } catch (SocketException e) { throw new ChannelException(e); } }