List of usage examples for org.apache.thrift.transport TTransportFactory getTransport
public TTransport getTransport(TTransport trans)
From source file:com.facebook.nifty.duplex.TDuplexTransportFactory.java
License:Apache License
public static TDuplexTransportFactory fromSingleTransportFactory(final TTransportFactory transportFactory) { return new TDuplexTransportFactory() { @Override/* w w w .ja v a2 s. co m*/ public TTransportPair getTransportPair(TTransportPair transportPair) { return TTransportPair.fromSeparateTransports( transportFactory.getTransport(transportPair.getInputTransport()), transportFactory.getTransport(transportPair.getOutputTransport())); } }; }
From source file:com.facebook.nifty.duplex.TDuplexTransportFactory.java
License:Apache License
public static TDuplexTransportFactory fromSeparateTransportFactories( final TTransportFactory inputTransportFactory, final TTransportFactory outputTransportFactory) { return new TDuplexTransportFactory() { @Override//from w w w .ja v a 2s. c o m public TTransportPair getTransportPair(TTransportPair transportPair) { return TTransportPair.fromSeparateTransports( inputTransportFactory.getTransport(transportPair.getInputTransport()), outputTransportFactory.getTransport(transportPair.getOutputTransport())); } }; }
From source file:ezbake.thrift.ThriftUtils.java
License:Apache License
protected static TTransport getTransport(Properties configuration, HostAndPort hostAndPort, String securityId, TTransportFactory transportFactory) throws TTransportException { TTransport transport;//from w w w . jav a 2 s . c o m ThriftConfigurationHelper thriftConfiguration = new ThriftConfigurationHelper(configuration); logger.debug("getTransport for hostAndPort {}", hostAndPort); if (thriftConfiguration.getServerMode() == ThriftConfigurationHelper.ThriftServerMode.HsHa) { logger.debug("opening framed transport to {}", hostAndPort); transport = new TFramedTransport(new TSocket(hostAndPort.getHostText(), hostAndPort.getPort())); } else { if (thriftConfiguration.useSSL()) { logger.debug("opening SSL connection to {}", hostAndPort); transport = ThriftUtils.getSslClientSocket(hostAndPort.getHostText(), hostAndPort.getPort(), configuration); transport = new EzSecureClientTransport(transport, configuration, securityId); } else { logger.debug("opening connection in the clear (without SSL) to {}", hostAndPort); transport = new TSocket(hostAndPort.getHostText(), hostAndPort.getPort()); } } // Wrap the transport using the transportFactory (if provided) if (transportFactory != null) { transport = transportFactory.getTransport(transport); } return transport; }
From source file:io.airlift.drift.integration.LegacyApacheThriftTesterUtil.java
License:Apache License
private static int logThrift(HostAndPort address, List<LogEntry> messages, List<MethodInvocationFilter> filters, Transport transportType, Protocol protocolType, boolean secure) { if (!filters.isEmpty()) { return 0; }//from w w w . j a v a 2s. c om TTransportFactory transportFactory; switch (transportType) { case UNFRAMED: transportFactory = new TTransportFactory(); break; case FRAMED: transportFactory = new TFramedTransport.Factory(); break; case HEADER: return 0; default: throw new IllegalArgumentException("Unsupported transport " + transportType); } try (TSocket socket = createClientSocket(secure, address)) { if (!socket.isOpen()) { socket.open(); } TTransport transport = transportFactory.getTransport(socket); TProtocol protocol; switch (protocolType) { case BINARY: protocol = new TBinaryProtocol(transport); break; case COMPACT: protocol = new TCompactProtocol(transport); break; case FB_COMPACT: return 0; default: throw new IllegalArgumentException("Unsupported protocol " + protocolType); } assertEquals(new scribe.Client(protocol).Log(messages), ResultCode.OK); } catch (TException e) { throw new RuntimeException(e); } return 1; }
From source file:io.airlift.drift.transport.netty.client.TestDriftNettyMethodInvoker.java
License:Apache License
private static int logThrift(HostAndPort address, List<LogEntry> messages, TTransportFactory framingFactory, TProtocolFactory protocolFactory) { try {//from ww w . j av a2 s. c om TSocket socket = new TSocket(address.getHost(), address.getPort()); socket.open(); try { TProtocol tp = protocolFactory.getProtocol(framingFactory.getTransport(socket)); Client client = new Client(tp); assertEquals(client.Log(messages), ResultCode.OK); try { client.Log(ImmutableList.of(new LogEntry("exception", "test"))); fail("Expected exception"); } catch (org.apache.thrift.TApplicationException e) { assertEquals(e.getType(), org.apache.thrift.TApplicationException.UNSUPPORTED_CLIENT_TYPE); } } finally { socket.close(); } } catch (TException e) { throw new RuntimeException(e); } return 1; }
From source file:io.airlift.drift.transport.netty.server.TestDriftNettyServerTransport.java
License:Apache License
private static int testOutOfOrder(HostAndPort address, List<LogEntry> messages, TTransportFactory framingFactory, TProtocolFactory protocolFactory, BlockingQueue<SettableFuture<Object>> results) { try {// w w w . ja va 2 s . c o m TSocket socket = new TSocket(address.getHost(), address.getPort()); socket.open(); try { TProtocol protocol = protocolFactory.getProtocol(framingFactory.getTransport(socket)); // send first request, but do not finish the result sendLogRequest(11, messages, protocol); SettableFuture<Object> firstResult = results.take(); assertFalse(firstResult.isDone()); // send second request, but do not finish the result sendLogRequest(22, messages, protocol); SettableFuture<Object> secondResult = results.take(); assertFalse(secondResult.isDone()); // finish the second invocation, first invocation will not be completed secondResult.set(DriftResultCode.OK); assertEquals(readLogResponse(22, protocol), ResultCode.OK); assertFalse(firstResult.isDone()); // complete first invocation firstResult.set(DriftResultCode.OK); assertEquals(readLogResponse(11, protocol), ResultCode.OK); } finally { socket.close(); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } catch (TException e) { throw new RuntimeException(e); } return 2; }
From source file:io.airlift.drift.transport.netty.server.TestDriftNettyServerTransport.java
License:Apache License
private static int testOutOfOrderNotSupported(HostAndPort address, List<LogEntry> messages, TTransportFactory framingFactory, TProtocolFactory protocolFactory, BlockingQueue<SettableFuture<Object>> results) { try {/*from w w w .j a va 2 s . co m*/ TSocket socket = new TSocket(address.getHost(), address.getPort()); socket.open(); try { TProtocol protocol = protocolFactory.getProtocol(framingFactory.getTransport(socket)); // send first request, but do not finish the result sendLogRequest(11, messages, protocol); SettableFuture<Object> firstResult = results.take(); assertFalse(firstResult.isDone()); // send second request, which will be blocked in the server because this client does not support out of order responses // the only way to test this is with a sleep because the request is blocked inside of the server IO stack sendLogRequest(22, messages, protocol); assertNull(results.poll(1, SECONDS), "Second request future"); assertFalse(firstResult.isDone()); // finish the first invocation, second invocation will not be completed firstResult.set(DriftResultCode.OK); assertEquals(readLogResponse(11, protocol), ResultCode.OK); SettableFuture<Object> secondResult = results.take(); assertFalse(secondResult.isDone()); // complete second invocation secondResult.set(DriftResultCode.OK); assertEquals(readLogResponse(22, protocol), ResultCode.OK); } finally { socket.close(); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } catch (TException e) { throw new RuntimeException(e); } return 2; }