Java Code Examples for org.apache.thrift.transport.TTransportException#NOT_OPEN
The following examples show how to use
org.apache.thrift.transport.TTransportException#NOT_OPEN .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TCustomSocket.java From stratio-cassandra with Apache License 2.0 | 6 votes |
/** * Constructor that takes an already created socket. * * @param socket Already created socket object * @throws TTransportException if there is an error setting up the streams */ public TCustomSocket(Socket socket) throws TTransportException { this.socket = socket; try { socket.setSoLinger(false, 0); socket.setTcpNoDelay(true); } catch (SocketException sx) { LOGGER.warn("Could not configure socket.", sx); } if (isOpen()) { try { inputStream_ = new BufferedInputStream(socket.getInputStream(), 1024); outputStream_ = new BufferedOutputStream(socket.getOutputStream(), 1024); } catch (IOException iox) { close(); throw new TTransportException(TTransportException.NOT_OPEN, iox); } } }
Example 2
Source File: GfxdTSocket.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Constructor that takes an already created socket. * * @param socket * Already created socket object * @param params * Socket parameters including buffer sizes and keep-alive settings * @param props * the system properties instance to use and initialize global socket * options like keepalive and buffer sizes that are not set in params * * @throws TTransportException * if there is an error setting up the streams */ public GfxdTSocket(SocketChannel socketChannel, boolean blocking, int timeout, SocketParameters params, SystemProperties props) throws TTransportException { this.socketChannel = socketChannel; if (!socketChannel.isConnected()) throw new TTransportException(TTransportException.NOT_OPEN, "Socket must already be connected"); try { socketChannel.configureBlocking(blocking); setProperties(socketChannel.socket(), timeout, params, props); this.inputStream = UnsafeHolder.newChannelBufferFramedInputStream( socketChannel, this.inputBufferSize); this.outputStream = UnsafeHolder.newChannelBufferOutputStream( socketChannel, this.outputBufferSize); this.framedWrites = false; } catch (IOException ioe) { close(); throw new TTransportException(TTransportException.NOT_OPEN, ioe); } }
Example 3
Source File: GfxdTSSLSocket.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Sets the socket properties like timeout, keepalive, buffer sizes. * * @param timeout * Milliseconds timeout * @param params * Socket parameters including buffer sizes and keep-alive settings * @param props * the system properties instance to use and initialize global socket * options like keepalive and buffer sizes that are not set in params */ protected void setProperties(Socket socket, int timeout, SocketParameters params, SystemProperties props) throws TTransportException { this.inputBufferSize = params.getInputBufferSize(props .getSocketInputBufferSize()); this.outputBufferSize = params.getOutputBufferSize(props .getSocketOutputBufferSize()); try { socket.setSoLinger(false, 0); socket.setTcpNoDelay(true); this.timeout = GfxdTSocket.setTimeout(socket, timeout, params, props); } catch (SocketException se) { LOGGER.warn("Could not set socket timeout.", se); throw new TTransportException(TTransportException.NOT_OPEN, "Could not set socket timeout.", se); } }
Example 4
Source File: GfxdTSSLSocket.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Constructor that takes an already created socket. * * @param socket * Already created socket object * * @throws TTransportException * if there is an error setting up the streams */ public GfxdTSSLSocket(Socket socket, int timeout, SocketParameters params, SystemProperties props) throws TTransportException { super(socket); if (isOpen()) { try { setProperties(socket, timeout, params, props); this.inputStream_ = new BufferedInputStream(socket.getInputStream(), this.inputBufferSize); this.outputStream_ = new BufferedOutputStream(socket.getOutputStream(), this.outputBufferSize); } catch (IOException ioe) { close(); throw new TTransportException(TTransportException.NOT_OPEN, ioe); } } }
Example 5
Source File: GfxdTSocket.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Sets the socket properties like timeout, keepalive, buffer sizes. * * @param timeout * Milliseconds timeout * @param params * Socket parameters including buffer sizes and keep-alive settings * @param props * the system properties instance to use and initialize global socket * options like keepalive and buffer sizes that are not set in params */ protected void setProperties(Socket socket, int timeout, SocketParameters params, SystemProperties props) throws TTransportException { this.inputBufferSize = params.getInputBufferSize(props .getSocketInputBufferSize()); this.outputBufferSize = params.getOutputBufferSize(props .getSocketOutputBufferSize()); try { socket.setSoLinger(false, 0); socket.setTcpNoDelay(true); this.timeout = setTimeout(socket, timeout, params, props); } catch (SocketException se) { LOGGER.warn("Could not set socket timeout.", se); throw new TTransportException(TTransportException.NOT_OPEN, "Could not set socket timeout.", se); } }
Example 6
Source File: GfxdTServerSocket.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Creates a port listening server socket */ public GfxdTServerSocket(InetSocketAddress bindAddress, boolean blocking, boolean clientBlocking, SocketParameters params) throws TTransportException { this.clientBlocking = clientBlocking; this.socketParams = params; try { // Make server socket this.serverSockChannel = ServerSocketChannel.open(); this.serverSockChannel.configureBlocking(blocking); ServerSocket socket = this.serverSockChannel.socket(); // Prevent 2MSL delay problem on server restarts socket.setReuseAddress(true); // Bind to listening port socket.bind(bindAddress); } catch (IOException ioe) { throw new TTransportException(TTransportException.NOT_OPEN, "Could not bind to host:port " + bindAddress.toString(), ioe); } }
Example 7
Source File: GfxdTSSLServerSocketFactory.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
private static GfxdTSSLServerSocket createServer( SSLServerSocketFactory factory, InetSocketAddress bindAddress, SocketParameters params) throws TTransportException { try { SSLServerSocket serverSocket = (SSLServerSocket)factory .createServerSocket(bindAddress.getPort(), 100, bindAddress.getAddress()); if (params != null) { if (params.getSSLEnabledProtocols() != null) { serverSocket.setEnabledProtocols(params.getSSLEnabledProtocols()); } if (params.getSSLCipherSuites() != null) { serverSocket.setEnabledCipherSuites(params.getSSLCipherSuites()); } serverSocket.setNeedClientAuth(params.getSSLClientAuth()); } return new GfxdTSSLServerSocket(serverSocket, bindAddress, params); } catch (Exception e) { throw new TTransportException(TTransportException.NOT_OPEN, "Could not bind to host:port " + bindAddress.toString(), e); } }
Example 8
Source File: GfxdTSSLServerSocket.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Creates a server socket from underlying socket object */ public GfxdTSSLServerSocket(ServerSocket serverSocket, InetSocketAddress bindAddress, SocketParameters params) throws TTransportException { this.socketParams = params; try { this.serverSocket = serverSocket; // Prevent 2MSL delay problem on server restarts serverSocket.setReuseAddress(true); // Bind to listening port if (!serverSocket.isBound()) { // backlog hardcoded to 100 as in TSSLTransportFactory serverSocket.bind(bindAddress, 100); } } catch (IOException ioe) { throw new TTransportException(TTransportException.NOT_OPEN, "Could not bind to host:port " + bindAddress.toString(), ioe); } }
Example 9
Source File: GfxdTSSLSocketFactory.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
private static SSLSocket createClient(SSLSocketFactory factory, InetAddress hostAddress, int port, int timeout, final SocketParameters params) throws TTransportException { try { SSLSocket socket = (SSLSocket)factory.createSocket(hostAddress, port); socket.setSoTimeout(timeout); if (params != null) { if (params.getSSLEnabledProtocols() != null) { socket.setEnabledProtocols(params.getSSLEnabledProtocols()); } if (params.getSSLCipherSuites() != null) { socket.setEnabledCipherSuites(params.getSSLCipherSuites()); } } return socket; } catch (IOException ioe) { throw new TTransportException(TTransportException.NOT_OPEN, ioe); } catch (Exception e) { throw new TTransportException(TTransportException.NOT_OPEN, "Could not connect to " + hostAddress + " on port " + port, e); } }
Example 10
Source File: GfxdTSSLServerSocketFactory.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
private static GfxdTSSLServerSocket createServer( SSLServerSocketFactory factory, InetSocketAddress bindAddress, SocketParameters params) throws TTransportException { try { SSLServerSocket serverSocket = (SSLServerSocket)factory .createServerSocket(bindAddress.getPort(), 100, bindAddress.getAddress()); if (params != null) { if (params.getSSLEnabledProtocols() != null) { serverSocket.setEnabledProtocols(params.getSSLEnabledProtocols()); } if (params.getSSLCipherSuites() != null) { serverSocket.setEnabledCipherSuites(params.getSSLCipherSuites()); } serverSocket.setNeedClientAuth(params.getSSLClientAuth()); } return new GfxdTSSLServerSocket(serverSocket, bindAddress, params); } catch (Exception e) { throw new TTransportException(TTransportException.NOT_OPEN, "Could not bind to host:port " + bindAddress.toString(), e); } }
Example 11
Source File: GfxdTSocket.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Sets the socket properties like timeout, keepalive, buffer sizes. * * @param timeout * Milliseconds timeout * @param params * Socket parameters including buffer sizes and keep-alive settings * @param props * the system properties instance to use and initialize global socket * options like keepalive and buffer sizes that are not set in params */ protected void setProperties(Socket socket, int timeout, SocketParameters params, SystemProperties props) throws TTransportException { this.inputBufferSize = params.getInputBufferSize(props .getSocketInputBufferSize()); this.outputBufferSize = params.getOutputBufferSize(props .getSocketOutputBufferSize()); try { socket.setSoLinger(false, 0); socket.setTcpNoDelay(true); this.timeout = setTimeout(socket, timeout, params, props); } catch (SocketException se) { LOGGER.warn("Could not set socket timeout.", se); throw new TTransportException(TTransportException.NOT_OPEN, "Could not set socket timeout.", se); } }
Example 12
Source File: GfxdTSocket.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public final int read(byte[] buf, int off, int len) throws TTransportException { int bytesRead; try { bytesRead = this.inputStream.read(buf, off, len); } catch (ClosedChannelException cce) { throw new TTransportException(TTransportException.NOT_OPEN, "Cannot read from closed channel."); } catch (IOException ioe) { throw new TTransportException(TTransportException.UNKNOWN, ioe); } if (bytesRead >= 0) { return bytesRead; } else { throw new TTransportException(TTransportException.END_OF_FILE, "Channel closed."); } }
Example 13
Source File: TCustomSocket.java From stratio-cassandra with Apache License 2.0 | 6 votes |
/** * Connects the socket, creating a new socket object if necessary. */ public void open() throws TTransportException { if (isOpen()) { throw new TTransportException(TTransportException.ALREADY_OPEN, "Socket already connected."); } if (host.length() == 0) { throw new TTransportException(TTransportException.NOT_OPEN, "Cannot open null host."); } if (port <= 0) { throw new TTransportException(TTransportException.NOT_OPEN, "Cannot open without port."); } if (socket == null) { initSocket(); } try { socket.connect(new InetSocketAddress(host, port), timeout); inputStream_ = new BufferedInputStream(socket.getInputStream(), 1024); outputStream_ = new BufferedOutputStream(socket.getOutputStream(), 1024); } catch (IOException iox) { close(); throw new TTransportException(TTransportException.NOT_OPEN, iox); } }
Example 14
Source File: GfxdTSSLSocket.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Constructor that takes an already created socket. * * @param socket * Already created socket object * * @throws TTransportException * if there is an error setting up the streams */ public GfxdTSSLSocket(Socket socket, int timeout, SocketParameters params, SystemProperties props) throws TTransportException { super(socket); if (isOpen()) { try { setProperties(socket, timeout, params, props); this.inputStream_ = new BufferedInputStream(socket.getInputStream(), this.inputBufferSize); this.outputStream_ = new BufferedOutputStream(socket.getOutputStream(), this.outputBufferSize); } catch (IOException ioe) { close(); throw new TTransportException(TTransportException.NOT_OPEN, ioe); } } }
Example 15
Source File: GfxdTSocket.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public final void write(byte[] buf, int off, int len) throws TTransportException { try { this.outputStream.write(buf, off, len); } catch (ClosedChannelException cce) { throw new TTransportException(TTransportException.NOT_OPEN, "Cannot write to closed channel."); } catch (IOException ioe) { throw new TTransportException(TTransportException.UNKNOWN, ioe); } }
Example 16
Source File: ByteArrayOutputStreamTransport.java From pinpoint with Apache License 2.0 | 5 votes |
@Override public void write(byte[] buf, int off, int len) throws TTransportException { if (out == null) { throw new TTransportException(TTransportException.NOT_OPEN, "cannot write to null outputStream"); } out.write(buf, off, len); }
Example 17
Source File: GfxdTSocket.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Connects the socket, creating a new socket object if necessary. */ @Override public void open() throws TTransportException { if (isOpen()) { throw new TTransportException(TTransportException.ALREADY_OPEN, "Socket already connected."); } if (this.socketAddress == null) { throw new TTransportException(TTransportException.NOT_OPEN, "Cannot open null host."); } if (this.socketAddress.getPort() <= 0) { throw new TTransportException(TTransportException.NOT_OPEN, "Cannot open without port."); } final Socket socket = getSocket(); try { socket.connect(this.socketAddress, this.timeout); this.inputStream = UnsafeHolder.newChannelBufferFramedInputStream( this.socketChannel, this.inputBufferSize); this.outputStream = this.framedWrites ? UnsafeHolder.newChannelBufferFramedOutputStream(this.socketChannel, this.outputBufferSize) : UnsafeHolder.newChannelBufferOutputStream(this.socketChannel, this.outputBufferSize); } catch (IOException ioe) { close(); throw new TTransportException(TTransportException.NOT_OPEN, ioe); } }
Example 18
Source File: GfxdTSSLSocket.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Connects the socket, creating a new socket object if necessary. */ @Override public void open() throws TTransportException { if (isOpen()) { throw new TTransportException(TTransportException.ALREADY_OPEN, "Socket already connected."); } if (this.hostAddress == null) { throw new TTransportException(TTransportException.NOT_OPEN, "Cannot open null host."); } if (this.port <= 0) { throw new TTransportException(TTransportException.NOT_OPEN, "Cannot open without port."); } final Socket socket = getSocket(); try { socket.connect(new InetSocketAddress(this.hostAddress, this.port), this.timeout); this.inputStream_ = new BufferedInputStream(socket.getInputStream(), this.inputBufferSize); this.outputStream_ = new BufferedOutputStream(socket.getOutputStream(), this.outputBufferSize); } catch (IOException ioe) { close(); throw new TTransportException(TTransportException.NOT_OPEN, ioe); } }
Example 19
Source File: GfxdTSSLSocket.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Connects the socket, creating a new socket object if necessary. */ @Override public void open() throws TTransportException { if (isOpen()) { throw new TTransportException(TTransportException.ALREADY_OPEN, "Socket already connected."); } if (this.hostAddress == null) { throw new TTransportException(TTransportException.NOT_OPEN, "Cannot open null host."); } if (this.port <= 0) { throw new TTransportException(TTransportException.NOT_OPEN, "Cannot open without port."); } final Socket socket = getSocket(); try { socket.connect(new InetSocketAddress(this.hostAddress, this.port), this.timeout); this.inputStream_ = new BufferedInputStream(socket.getInputStream(), this.inputBufferSize); this.outputStream_ = new BufferedOutputStream(socket.getOutputStream(), this.outputBufferSize); } catch (IOException ioe) { close(); throw new TTransportException(TTransportException.NOT_OPEN, ioe); } }
Example 20
Source File: TLoadBalancerClient.java From spring-thrift-starter with MIT License | 4 votes |
private void doFlush(byte[] data) throws TTransportException, IOException { ServiceInstance serviceInstance = this.loadBalancerClient.choose(serviceName); if (serviceInstance == null) { throw new TTransportException(TTransportException.NOT_OPEN, "No service instances available"); } HttpURLConnection iox = (HttpURLConnection) new URL( serviceInstance.getUri().toString() + path ).openConnection(); if (this.connectTimeout_ > 0) { iox.setConnectTimeout(this.connectTimeout_); } if (this.readTimeout_ > 0) { iox.setReadTimeout(this.readTimeout_); } iox.setRequestMethod("POST"); iox.setRequestProperty("Content-Type", "application/x-thrift"); iox.setRequestProperty("Accept", "application/x-thrift"); iox.setRequestProperty("User-Agent", "Java/THttpClient"); if (this.customHeaders_ != null) { Iterator responseCode = this.customHeaders_.entrySet().iterator(); while (responseCode.hasNext()) { Map.Entry header = (Map.Entry) responseCode.next(); iox.setRequestProperty((String) header.getKey(), (String) header.getValue()); } } iox.setDoOutput(true); iox.connect(); iox.getOutputStream().write(data); int responseCode1 = iox.getResponseCode(); if (responseCode1 != 200) { throw new TTransportException("HTTP Response code: " + responseCode1); } else { this.inputStream_ = iox.getInputStream(); } }