org.apache.thrift.transport.TTransportException Java Examples
The following examples show how to use
org.apache.thrift.transport.TTransportException.
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: CoronaTaskTracker.java From RDFS with Apache License 2.0 | 7 votes |
private synchronized void initializeClusterManagerClient() throws IOException { // Connect to cluster manager thrift service String target = CoronaConf.getClusterManagerAddress(fConf); LOG.info("Connecting to Cluster Manager at " + target); InetSocketAddress address = NetUtils.createSocketAddr(target); transport = new TFramedTransport( new TSocket(address.getHostName(), address.getPort())); TProtocol protocol = new TBinaryProtocol(transport); client = new ClusterManagerService.Client(protocol); try { transport.open(); } catch (TTransportException e) { throw new IOException(e); } }
Example #2
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 #3
Source File: HiveClient.java From garmadon with Apache License 2.0 | 6 votes |
protected void execute(String query) throws SQLException { LOGGER.debug("Execute hql: {}", query); int maxAttempts = 5; for (int retry = 1; retry <= maxAttempts; ++retry) { try { stmt.execute(query); } catch (SQLException sqlException) { if (ExceptionUtils.indexOfThrowable(sqlException, TTransportException.class) != -1) { String exMsg = String.format("Retry connecting to hive (%d/%d)", retry, maxAttempts); if (retry <= maxAttempts) { LOGGER.warn(exMsg, sqlException); try { Thread.sleep(1000 * retry); connect(); } catch (Exception ignored) { } } else { LOGGER.error(exMsg, sqlException); throw sqlException; } } else { throw sqlException; } } } }
Example #4
Source File: CarreraConsumerExample.java From DDMQ with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws TTransportException, InterruptedException { Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { LogManager.shutdown(); //shutdown log4j2. } })); LOGGER.info("start simpleExample..."); simpleExample(60 * 1000); LOGGER.info("start exampleWithExtraThreadsForSomeTopic..."); exampleWithExtraThreadsForSomeTopic(60 * 1000); exampleConsumeStatsFetch(); }
Example #5
Source File: MetaStoreProxyServer.java From waggle-dance with Apache License 2.0 | 6 votes |
private TServerSocket createServerSocket(boolean useSSL, int port) throws IOException, TTransportException { TServerSocket serverSocket = null; // enable SSL support for HMS List<String> sslVersionBlacklist = new ArrayList<>(Arrays.asList(hiveConf.getVar(ConfVars.HIVE_SSL_PROTOCOL_BLACKLIST).split(","))); if (!useSSL) { serverSocket = HiveAuthUtils.getServerSocket(null, port); } else { String keyStorePath = hiveConf.getVar(ConfVars.HIVE_METASTORE_SSL_KEYSTORE_PATH).trim(); if (keyStorePath.isEmpty()) { throw new IllegalArgumentException( ConfVars.HIVE_METASTORE_SSL_KEYSTORE_PASSWORD.varname + " Not configured for SSL connection"); } String keyStorePassword = ShimLoader .getHadoopShims() .getPassword(hiveConf, HiveConf.ConfVars.HIVE_METASTORE_SSL_KEYSTORE_PASSWORD.varname); serverSocket = HiveAuthUtils.getServerSSLSocket(null, port, keyStorePath, keyStorePassword, sslVersionBlacklist); } return serverSocket; }
Example #6
Source File: ThriftConnection.java From hbase with Apache License 2.0 | 6 votes |
@Override public Pair<THBaseService.Client, TTransport> getClient() throws IOException { Preconditions.checkArgument(connection.getHost().startsWith("http"), "http client host must start with http or https"); String url = connection.getHost() + ":" + connection.getPort(); try { THttpClient httpClient = new THttpClient(url, connection.getHttpClient()); for (Map.Entry<String, String> header : customHeader.entrySet()) { httpClient.setCustomHeader(header.getKey(), header.getValue()); } httpClient.open(); TProtocol prot = new TBinaryProtocol(httpClient); THBaseService.Client client = new THBaseService.Client(prot); return new Pair<>(client, httpClient); } catch (TTransportException e) { throw new IOException(e); } }
Example #7
Source File: TLoadBalancerClient.java From spring-thrift-starter with MIT License | 6 votes |
public void flush() throws TTransportException { byte[] data = this.requestBuffer_.toByteArray(); this.requestBuffer_.reset(); int retryCount = 0; while (true) { try { retryCount++; doFlush(data); return; } catch (IOException ioe) { if (retryCount >= maxRetries_) { throw new TTransportException(ioe); } } catch (Exception e) { if (retryCount >= maxRetries_) { throw e; } } } }
Example #8
Source File: LegacyApacheThriftTesterUtil.java From drift with Apache License 2.0 | 6 votes |
private static TSocket createClientSocket(boolean secure, HostAndPort address) throws TTransportException { if (!secure) { return new TSocket(address.getHost(), address.getPort()); } try { SSLContext serverSslContext = ClientTestUtils.getClientSslContext(); SSLSocket clientSocket = (SSLSocket) serverSslContext.getSocketFactory().createSocket(address.getHost(), address.getPort()); // clientSocket.setSoTimeout(timeout); return new TSocket(clientSocket); } catch (Exception e) { throw new TTransportException("Error initializing secure socket", e); } }
Example #9
Source File: AbstractThriftServerImpl.java From ikasoa with MIT License | 6 votes |
/** * 启动Thrift服务 * * @exception IkasoaException * 异常 */ public void start() throws IkasoaException { if (ObjectUtil.isNull(server)) { log.debug("Server configuration : {}", configuration); // 不允许使用1024以内的端口. if (!ServerUtil.isSocketPort(serverPort)) throw new IkasoaException(String.format( "Server initialize failed ! Port range must is 1025 ~ 65535 . Your port is : %d .", serverPort)); try { initServer(getTransport()); } catch (TTransportException e) { throw new IkasoaException("Server initialize failed !", e); } } // 如果服务没有启动,则自动启动服务. if (ObjectUtil.isNotNull(server)) { if (server.isServing()) { log.info("Server already run ."); return; } server.serve(); log.info("Startup server ... (name : {} , port : {})", getServerName(), getServerPort()); } else log.warn("Startup server failed !"); }
Example #10
Source File: TFramedTransport.java From warp10-platform with Apache License 2.0 | 6 votes |
private void readFrame() throws TTransportException { transport_.readAll(i32buf, 0, 4); int size = decodeFrameSize(i32buf); if (size < 0) { throw new TTransportException("Read a negative frame size (" + size + ")!"); } if (size > maxLength_) { throw new TTransportException("Frame size (" + size + ") larger than max length (" + maxLength_ + ")!"); } byte[] buff = new byte[size]; transport_.readAll(buff, 0, size); readBuffer_.reset(buff); }
Example #11
Source File: ThriftServer.java From plow with Apache License 2.0 | 6 votes |
@PostConstruct public void start() { logger.info("Starting thift server " + name + " on port " + port); try { transport = new TNonblockingServerSocket(port); server = new TThreadedSelectorServer( new TThreadedSelectorServer.Args(transport) .processor(processor) .workerThreads(threads) .selectorThreads((threads / 16) + 1) .protocolFactory(protocolFactory) .transportFactory(new TFramedTransport.Factory())); thread.start(); } catch (TTransportException e) { throw new RuntimeException("Unable to start thrift server " + e, e); } }
Example #12
Source File: BookKeeperFactory.java From rubix with Apache License 2.0 | 6 votes |
public RetryingPooledBookkeeperClient createBookKeeperClient(String host, Configuration conf) throws TTransportException { if (!initFlag.get()) { synchronized (initFlag) { if (!initFlag.get()) { pool = createSocketObjectPool(conf, host, CacheConfig.getBookKeeperServerPort(conf)); initFlag.set(true); } } } if (bookKeeper != null) { return new LocalBookKeeperClient(bookKeeper); } else { Poolable<TTransport> obj; obj = pool.borrowObject(host, conf); RetryingPooledBookkeeperClient retryingBookkeeperClient = new RetryingPooledBookkeeperClient(obj, host, conf); return retryingBookkeeperClient; } }
Example #13
Source File: Transport.java From presto with Apache License 2.0 | 6 votes |
public static TTransport create( HostAndPort address, Optional<SSLContext> sslContext, Optional<HostAndPort> socksProxy, int timeoutMillis, HiveMetastoreAuthentication authentication, Optional<String> delegationToken) throws TTransportException { requireNonNull(address, "address is null"); try { TTransport rawTransport = createRaw(address, sslContext, socksProxy, timeoutMillis); TTransport authenticatedTransport = authentication.authenticate(rawTransport, address.getHost(), delegationToken); if (!authenticatedTransport.isOpen()) { authenticatedTransport.open(); } return new TTransportWrapper(authenticatedTransport, address); } catch (TTransportException e) { throw rewriteException(e, address); } }
Example #14
Source File: FileTrans.java From ThriftBook with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws IOException, TTransportException, ClassNotFoundException { Trade trade = new Trade(); trade.symbol = "F"; trade.price = 13.10; trade.size = 2500; TSimpleFileTransport trans_out = new TSimpleFileTransport("data",false,true); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(trade); trans_out.write(baos.toByteArray()); trans_out.close(); TSimpleFileTransport trans_in = new TSimpleFileTransport("data",true,false); byte[] buf = new byte[128]; int iBytesRead = trans_in.read(buf, 0, buf.length); ByteArrayInputStream bais = new ByteArrayInputStream(buf); ObjectInputStream ois = new ObjectInputStream(bais); trade = (Trade) ois.readObject(); System.out.println("Trade(" + iBytesRead + "): " + trade.symbol + " " + trade.size + " @ " + trade.price); }
Example #15
Source File: CustomServerSocket.java From suro with Apache License 2.0 | 6 votes |
public CustomServerSocket(ServerConfig config) throws TTransportException { this.config = config; InetSocketAddress bindAddr = new InetSocketAddress(config.getPort()); try { serverSocketChannel = ServerSocketChannel.open(); serverSocketChannel.configureBlocking(false); // Make server socket serverSocket_ = serverSocketChannel.socket(); // Prevent 2MSL delay problem on server restarts serverSocket_.setReuseAddress(true); // Bind to listening port serverSocket_.bind(new InetSocketAddress(config.getPort())); } catch (IOException ioe) { serverSocket_ = null; throw new TTransportException("Could not create ServerSocket on address " + bindAddr.toString() + "."); } }
Example #16
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 #17
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 #18
Source File: AbstractThriftServerImpl.java From ikasoa with MIT License | 5 votes |
/** * 获取一个服务传输类型 * <p> * 如果使用非Socket传输类型,需要重写此方法. * * @return TServerTransport 服务传输类型 */ @Override public TServerTransport getTransport() throws TTransportException { if (ObjectUtil.isNull(serverSocket)) { TSSLTransportParameters params = getServerConfiguration().getSslTransportParameters(); serverSocket = ObjectUtil.isNull(params) ? new TServerSocket(getServerPort()) : TSSLTransportFactory.getServerSocket(getServerPort(), 0, null, params); } return serverSocket; }
Example #19
Source File: AbstractCassandraOutputAdapter.java From OpenRate with Apache License 2.0 | 5 votes |
/** * Tries to connect to Cassandra. * * @throws OpenRate.exception.ProcessingException */ public void openCassandraConnection() throws ProcessingException { tr = new TFramedTransport(new TSocket(cassandraIPAddr, 9160)); TProtocol proto = new TBinaryProtocol(tr); client = new Cassandra.Client(proto); try { tr.open(); } catch (TTransportException ex) { message = "Transport exception opening Cassandra transport"; throw new ProcessingException(message, ex, getSymbolicName()); } }
Example #20
Source File: ConnectionPool.java From suro with Apache License 2.0 | 5 votes |
public void disconnect() { try { transport.flush(); } catch (TTransportException e) { logger.error("Exception on disconnect: " + e.getMessage(), e); } finally { transport.close(); } }
Example #21
Source File: HiveMetastoreClientFactory.java From metacat with Apache License 2.0 | 5 votes |
@Override public void write(final byte[] bytes, final int off, final int len) throws TTransportException { try { transport.write(bytes, off, len); } catch (TTransportException e) { throw rewriteException(e, host); } }
Example #22
Source File: ReturnResultsReducer.java From jstorm with Apache License 2.0 | 5 votes |
@Override public void complete(ReturnResultsState state, TridentCollector collector) { // only one of the multireducers will receive the tuples if (state.returnInfo != null) { String result = JSONValue.toJSONString(state.results); Map retMap = (Map) JSONValue.parse(state.returnInfo); final String host = (String) retMap.get("host"); final int port = Utils.getInt(retMap.get("port")); String id = (String) retMap.get("id"); DistributedRPCInvocations.Iface client; if (local) { client = (DistributedRPCInvocations.Iface) ServiceRegistry.getService(host); } else { List server = new ArrayList() { { add(host); add(port); } }; if (!_clients.containsKey(server)) { try { _clients.put(server, new DRPCInvocationsClient(conf, host, port)); } catch (TTransportException ex) { throw new RuntimeException(ex); } } client = _clients.get(server); } try { client.result(id, result); } catch (AuthorizationException aze) { collector.reportError(aze); } catch (TException e) { collector.reportError(e); } } }
Example #23
Source File: ThriftServer.java From ThriftBook with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws TTransportException, IOException { TradeHistory.Processor proc = new TradeHistory.Processor(new TradeHistoryHandler()); TServerSocket trans_svr = new TServerSocket(9090); TThreadPoolServer server = new TThreadPoolServer(new TThreadPoolServer.Args(trans_svr).processor(proc)); System.out.println("[Server] listening of port 9090"); server.serve(); }
Example #24
Source File: HiveTables.java From iceberg with Apache License 2.0 | 5 votes |
private ThriftHiveMetastore.Client getClient() { final URI metastoreUri = URI.create(MetastoreConf.getAsString(conf, THRIFT_URIS)); final int socketTimeOut = (int) MetastoreConf.getTimeVar(conf, CLIENT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS); TTransport transport = new TSocket(metastoreUri.getHost(), metastoreUri.getPort(), socketTimeOut); try { transport.open(); } catch (TTransportException e) { throw new RuntimeException("failed to open socket for " + metastoreUri + " with timeoutMillis " + socketTimeOut); } return new ThriftHiveMetastore.Client(new TBinaryProtocol(transport)); }
Example #25
Source File: TTextProtocol.java From armeria with Apache License 2.0 | 5 votes |
/** * Helper shared by write{List/Set}End. */ private void writeSequenceEnd() throws TException { try { getCurrentWriter().writeEndArray(); } catch (IOException ex) { throw new TTransportException(ex); } popContext(); }
Example #26
Source File: OkhttpTransport.java From Firefly with Apache License 2.0 | 5 votes |
@Override public int read(byte[] buf, int off, int len) throws TTransportException { int bytesRemaining = getBytesRemainingInBuffer(); int amtToRead = (len > bytesRemaining ? bytesRemaining : len); if (amtToRead > 0) { System.arraycopy(readBuffer, readBufferPosition, buf, off, amtToRead); consumeBuffer(amtToRead); } return amtToRead; }
Example #27
Source File: MetacatHiveClient.java From metacat with Apache License 2.0 | 5 votes |
/** * Create a metastore client instance. * * @return hivemetastore client */ private HiveMetastoreClient createMetastoreClient() { try { return hiveMetastoreClientFactory.create(host, port); } catch (TTransportException e) { throw new RuntimeException("Failed connecting to Hive metastore: " + host + ":" + port, e); } }
Example #28
Source File: HelloServer.java From ThriftBook with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws TTransportException { TServerSocket trans_svr = new TServerSocket(9090); TProcessor proc = new helloSvc.Processor<>(new MessageHandler()); TServer server = new TSimpleServer( new TSimpleServer.Args(trans_svr) .processor(proc) ); System.out.println("[Server] waiting for connections"); server.serve(); }
Example #29
Source File: ByteArrayOutputStreamTransportTest.java From pinpoint with Apache License 2.0 | 5 votes |
@Test public void flush() throws TTransportException { transport.write(buf, 0, buf.length); assertEquals(buf.length, out.size()); transport.flush(); assertEquals(0, out.size()); }
Example #30
Source File: DigestSaslTransportPlugin.java From jstorm with Apache License 2.0 | 5 votes |
@Override public TTransport connect(TTransport transport, String serverHost, String asUser) throws TTransportException, IOException { ClientCallbackHandler client_callback_handler = new ClientCallbackHandler(login_conf); TSaslClientTransport wrapper_transport = new TSaslClientTransport(DIGEST, null, AuthUtils.SERVICE, serverHost, null, client_callback_handler, transport); wrapper_transport.open(); LOG.debug("SASL DIGEST-MD5 client transport has been established"); return wrapper_transport; }