@Override protected SnappyTSocket acceptImpl() throws TTransportException { try { SocketChannel srvChannel = this.serverSockChannel.accept(); return new SnappyTSocket(srvChannel, this.useSSL, this.clientBlocking, this.socketParams); } catch (IOException ioe) { throw new TTransportException(ioe); } }
/** * Creates a new socket that will connect to the given server on given port. * * @param srvAddress Resolved remote server address * @param port Remote port * @param timeout Any explicit socket timeout or zero if using defaults * from <code>params</code> * @param params Socket parameters like buffer sizes, keep-alive settings */ public SnappyTSocket(InetAddress srvAddress, int port, String clientId, boolean useSSL, boolean blocking, boolean framedWrites, int timeout, SocketParameters params) throws TTransportException { try { this.socketChannel = initSocket(blocking); this.socketAddress = new InetSocketAddress(srvAddress, port); this.framedWrites = framedWrites; setProperties(socketChannel.socket(), timeout, params); this.dataChannel = openChannel(clientId, useSSL, params); this.socketToSameHost = ClientSharedUtils.isSocketToSameHost(dataChannel); } catch (IOException ioe) { close(); throw new TTransportException(TTransportException.NOT_OPEN, "Failed to create or configure socket.", ioe); } }
@Override public void open() throws TTransportException { if (!isOpen()) { throw new TTransportException(TTransportException.NOT_OPEN, "Expected the socket to be already connected."); } }
this.socketAddress = new InetSocketAddress(getSocket().getInetAddress(), getSocket().getPort()); try { srvChannel.configureBlocking(blocking); setProperties(srvChannel.socket(), params.getReadTimeout(), params); this.dataChannel = initChannel(srvChannel.getRemoteAddress().toString(), null, useSSL, params, false); this.inputStream = UnsafeHolder.newChannelBufferFramedInputStream( this.socketToSameHost = ClientSharedUtils.isSocketToSameHost(dataChannel); } catch (IOException ioe) { close(); throw new TTransportException(TTransportException.NOT_OPEN, "Failed to create or configure socket for client.", ioe);
if (isOpen()) { throw new TTransportException(TTransportException.ALREADY_OPEN, "Socket already connected."); clientId = getSocket().getLocalSocketAddress().toString(); ByteChannel channel = initChannel(clientId, null, useSSL, params, true);
try { if (remainingFrameSize == 0) { remainingFrameSize = client.getInputStream() .readFrame(); } else { remainingFrameSize = client.getInputStream() .readFrameFragment(remainingFrameSize); if (client.isOpen()) { LOGGER.trace("Got an IOException while reading frame", ioe); .getInputStream().getParkedThread(); if (parkedThread != null) { LockSupport.unpark(parkedThread); } else if ((readyOps & SelectionKey.OP_WRITE) != 0) { if (!data.idle) { parkedThread = data.clientSocket.getOutputStream() .getParkedThread(); if (parkedThread != null) { if (!data.idle) { final Thread parkedThread = data.clientSocket .getOutputStream().getParkedThread(); if (parkedThread != null) { LockSupport.unpark(parkedThread);
final InputStreamChannel input = data.clientSocket.getInputStream(); data.idle = true; if (!data.clientSocket.isOpen()) { cleanupConnection(data);
protected void close() { this.clientSocket.close(); } }
/** * {@inheritDoc} */ @Override public void setSoTimeout(int timeout) throws SocketException { getSocket().setSoTimeout(timeout); this.timeout = timeout; }
@Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { try { // register the client socket channel in selector beyond this final ClientProcessData data = ((ThreadWorker)r).data; data.clientSocket.getSocketChannel().configureBlocking(false); registerClientDataInNextSelector(data); } catch (IOException ioe) { if (!stopped) { LOGGER.warn("Transport error occurred during " + "acceptance of connection.", ioe); } } } };
/** * {@inheritDoc} */ @Override public int getSoTimeout() throws SocketException { return getSocket().getSoTimeout(); }
transport = new SnappyTSSLSocket(controlAddr, this.socketParams); } else { transport = new SnappyTSocket(controlAddr, null, false, true, ThriftUtils.isThriftSelectorServer(), this.socketParams);
hostAddr.getPort(), readTimeout, socketParams); } else { transport = new SnappyTSocket( hostAddr.resolveHost(), hostAddr.getPort(), connArgs.clientID, false, true, ThriftUtils.isThriftSelectorServer(),