List of usage examples for org.apache.thrift.transport TTransportException UNKNOWN
int UNKNOWN
To view the source code for org.apache.thrift.transport TTransportException UNKNOWN.
Click Source Link
From source file:com.facebook.hive.metastore.client.TestRetryingHiveMetastore.java
License:Apache License
@Test public void testNonExistent() throws Exception { final int port = NetUtils.findUnusedPort(); final HiveMetastoreClientConfig metastoreConfig = new HiveMetastoreClientConfig().setPort(port) .setMaxRetries(5).setRetrySleep(new Duration(1, TimeUnit.SECONDS)) .setRetryTimeout(new Duration(30, TimeUnit.SECONDS)); try (final ThriftClientManager clientManager = new ThriftClientManager()) { final ThriftClientConfig clientConfig = new ThriftClientConfig(); final HiveMetastoreFactory factory = new SimpleHiveMetastoreFactory(clientManager, clientConfig, metastoreConfig);//from w ww . ja va 2s. c o m try (final HiveMetastore metastore = factory.getDefaultClient()) { assertFalse(metastore.isConnected()); metastore.getTable("hello", "world"); fail(); } catch (TTransportException te) { assertEquals(TTransportException.UNKNOWN, te.getType()); } } }
From source file:com.facebook.nifty.client.TNiftyClientChannelTransport.java
License:Apache License
@Override public void flush() throws TTransportException { try {/*ww w . j a v a 2 s . c o m*/ boolean sendOneWay = inOneWayRequest(); ResponseListener listener = new ResponseListener(); channel.sendAsynchronousRequest(requestBufferTransport.getOutputBuffer().copy(), sendOneWay, listener); queuedResponses.add(listener); requestBufferTransport.resetOutputBuffer(); } catch (TException e) { Throwables.propagateIfInstanceOf(e, TTransportException.class); throw new TTransportException(TTransportException.UNKNOWN, "Failed to use reflection on Client class to determine whether method is oneway", e); } }
From source file:com.flaptor.indextank.storage.RecordIterator.java
License:Apache License
@Override protected LogRecord computeNext() { if (end >= 0 && transport.getBytesRead() >= end) { if (transport != null) { totalRead = transport.getBytesRead(); transport.close();//w w w . ja v a2 s. c o m } return endOfData(); } LogRecord record = new LogRecord(); try { ((TBinaryProtocol) protocol).setReadLength(10000000); record.read(protocol); if (transport != null) { safelyRead = transport.getBytesRead(); } } catch (TTransportException e) { switch (e.getType()) { case TTransportException.END_OF_FILE: if (transport != null) { totalRead = transport.getBytesRead(); transport.close(); } return endOfData(); case TTransportException.UNKNOWN: if (e.getMessage().startsWith("Cannot read. Remote side has closed")) { if (transport != null) { totalRead = transport.getBytesRead(); transport.close(); } return endOfData(); } default: transport.close(); throw new RuntimeException("Failed while iterating: " + description, e); } } catch (TException e) { transport.close(); throw new RuntimeException("Failed while iterating: " + description, e); } return record; }
From source file:com.linecorp.armeria.server.thrift.THttp2Client.java
License:Apache License
THttp2Client(String uriStr) throws TTransportException { uri = URI.create(uriStr);/*from ww w.jav a 2s.c om*/ int port; switch (uri.getScheme()) { case "http": port = uri.getPort(); if (port < 0) { port = 80; } sslCtx = null; break; case "https": port = uri.getPort(); if (port < 0) { port = 443; } try { sslCtx = SslContextBuilder.forClient() .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE) .trustManager(InsecureTrustManagerFactory.INSTANCE) .applicationProtocolConfig(new ApplicationProtocolConfig(Protocol.ALPN, // NO_ADVERTISE is currently the only mode supported by both OpenSsl and // JDK providers. SelectorFailureBehavior.NO_ADVERTISE, // ACCEPT is currently the only mode supported by both OpenSsl and // JDK providers. SelectedListenerFailureBehavior.ACCEPT, ApplicationProtocolNames.HTTP_2)) .build(); } catch (SSLException e) { throw new TTransportException(TTransportException.UNKNOWN, e); } break; default: throw new IllegalArgumentException("unknown scheme: " + uri.getScheme()); } String host = uri.getHost(); if (host == null) { throw new IllegalArgumentException("host not specified: " + uriStr); } String path = uri.getPath(); if (path == null) { throw new IllegalArgumentException("path not specified: " + uriStr); } this.host = host; this.port = port; this.path = path; }
From source file:com.linecorp.armeria.server.thrift.THttp2Client.java
License:Apache License
@Override public void flush() throws TTransportException { THttp2ClientInitializer initHandler = new THttp2ClientInitializer(); Bootstrap b = new Bootstrap(); b.group(group);//from ww w . j a v a 2 s . c o m b.channel(NioSocketChannel.class); b.handler(initHandler); Channel ch = null; try { ch = b.connect(host, port).syncUninterruptibly().channel(); THttp2ClientHandler handler = initHandler.clientHandler; // Wait until HTTP/2 upgrade is finished. assertTrue(handler.settingsPromise.await(5, TimeUnit.SECONDS)); handler.settingsPromise.get(); // Send a Thrift request. FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, path, Unpooled.wrappedBuffer(out.getArray(), 0, out.length())); request.headers().add(HttpHeaderNames.HOST, host); request.headers().set(ExtensionHeaderNames.SCHEME.text(), uri.getScheme()); ch.writeAndFlush(request).sync(); // Wait until the Thrift response is received. assertTrue(handler.responsePromise.await(5, TimeUnit.SECONDS)); ByteBuf response = handler.responsePromise.get(); // Pass the received Thrift response to the Thrift client. final byte[] array = new byte[response.readableBytes()]; response.readBytes(array); in = new TMemoryInputTransport(array); response.release(); } catch (Exception e) { throw new TTransportException(TTransportException.UNKNOWN, e); } finally { if (ch != null) { ch.close(); } } }
From source file:com.pinterest.quasar.thrift.TFiberServerSocket.java
License:Apache License
/** * Binds the server socket to the requested port. This must be called before the server socket * can be used to accept incoming requests. * * The server socket enables SO_REUSEADDR to make it faster to restart a server on the same port. * * @throws TTransportException if the bind operation fails. *///from ww w. j av a2s .co m @Override @Suspendable public void listen() throws TTransportException { try { serverSocketChannel = FiberServerSocketChannel.open() .setOption(StandardSocketOptions.SO_REUSEADDR, true).bind(addr); } catch (SuspendExecution se) { throw new AssertionError(se); } catch (IOException ioex) { throw new TTransportException(TTransportException.UNKNOWN, ioex); } }
From source file:com.pinterest.quasar.thrift.TFiberServerSocket.java
License:Apache License
@Override @Suspendable//from w w w .j av a2 s . c om protected TTransport acceptImpl() throws TTransportException { try { FiberSocketChannel socketChannel = serverSocketChannel.accept(); return new TFiberSocket(socketChannel, -1, TimeUnit.SECONDS); } catch (SuspendExecution ex) { throw new AssertionError("Instrumentation should have removed this code"); } catch (IOException ioex) { throw new TTransportException(TTransportException.UNKNOWN, ioex); } }
From source file:com.pinterest.quasar.thrift.TFiberSocket.java
License:Apache License
/** * Reads up to limit bytes from the underlying socket into the bytes buffer starting at offset. * * @param bytes must be at least offset + bytes in size. * @param offset the offset at which to start writing into bytes. * @param limit the maximum number of bytes to read into bytes. * @return the number of bytes actually read from the underlying socket. * @throws TTransportException if an error occurred while reading. */// w w w .java 2 s .c o m @Override @Suspendable public int read(byte[] bytes, int offset, int limit) throws TTransportException { ByteBuffer buf = ByteBuffer.wrap(bytes, offset, limit); int bytesRead; try { bytesRead = socketChannel.read(buf, timeout, timeoutUnit); if (bytesRead < 0) { throw new TTransportException(TTransportException.END_OF_FILE); } return bytesRead; } catch (IOException ioex) { throw new TTransportException(TTransportException.UNKNOWN, ioex); } catch (SuspendExecution ex) { throw new TTransportException(TTransportException.UNKNOWN, ex); } }
From source file:com.pinterest.quasar.thrift.TFiberSocket.java
License:Apache License
@Override @Suspendable//from w ww. j av a2 s. c om public void flush() throws TTransportException { if (curWriteBuffer < 2) { throw new RuntimeException("Attempted to flush with less than two buffers, make sure you " + "are using TFastFramedTransport or TFramedTransport"); } curWriteBuffer = 0; try { while (writeBuffers[1].hasRemaining()) { long bytesWritten = socketChannel.write(writeBuffers); if (bytesWritten < 0) { throw new TTransportException(TTransportException.END_OF_FILE); } } } catch (IOException ioex) { throw new TTransportException(TTransportException.UNKNOWN, ioex); } }
From source file:com.si.jupiter.smart.client.channel.AbstractClientChannel.java
License:Apache License
@Override public void sendAsynchronousRequest(final ByteBuf message, final boolean oneway, final Listener listener) throws TException { final int sequenceId = extractSequenceId(message); // Ensure channel listeners are always called on the channel's I/O thread executeInIoThread(new Runnable() { @Override/*from w w w . ja v a 2 s .co m*/ public void run() { try { final Request request = makeRequest(sequenceId, listener); if (!nettyChannel.isActive()) { fireChannelErrorCallback(listener, new TTransportException(TTransportException.NOT_OPEN, "Channel closed")); return; } if (hasError()) { fireChannelErrorCallback(listener, new TTransportException(TTransportException.UNKNOWN, "Channel is in a bad state due to failing a previous request")); return; } ChannelFuture sendFuture = writeRequest(message); //queueSendTimeout(request); sendFuture.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { messageSent(future, request, oneway); } }); } catch (Throwable t) { // onError calls all registered listeners in the requestMap, but this request // may not be registered yet. So we try to remove it (to make sure we don't call // the callback twice) and then manually make the callback for this request // listener. requestMap.remove(sequenceId); fireChannelErrorCallback(listener, t); onError(t); } } }); }