Search in sources :

Example 21 with TTransportException

use of org.apache.thrift.transport.TTransportException in project commons by twitter.

the class ThriftTest method testRetriesRecover.

@Test
public void testRetriesRecover() throws Exception {
    // 1st call
    expect(expectServiceCall(true).calculateMass("jake")).andThrow(new TTransportException());
    requestTracker.requestResult((InetSocketAddress) anyObject(), eq(RequestTracker.RequestResult.FAILED), anyLong());
    // 1st retry recovers
    expect(expectServiceCall(false).calculateMass("jake")).andReturn(42);
    requestTracker.requestResult((InetSocketAddress) anyObject(), eq(RequestTracker.RequestResult.SUCCESS), anyLong());
    Thrift<TestService> thrift = createThrift(expectUnusedExecutorService());
    control.replay();
    TestService testService = thrift.builder().blocking().withRetries(1).create();
    assertEquals(42, testService.calculateMass("jake"));
    assertRequestsTotal(thrift, 1);
    assertErrorsTotal(thrift, 0);
    assertReconnectsTotal(thrift, 0);
    assertTimeoutsTotal(thrift, 0);
    control.verify();
}
Also used : TTransportException(org.apache.thrift.transport.TTransportException) Test(org.junit.Test)

Example 22 with TTransportException

use of org.apache.thrift.transport.TTransportException in project commons by twitter.

the class TTextProtocol method writeSequenceBegin.

/**
   * Helper shared by write{List/Set}Begin
   */
private void writeSequenceBegin(int size) throws TException {
    getCurrentContext().write();
    if (getCurrentContext().isMapKey()) {
        throw new TException(SEQUENCE_AS_KEY_ILLEGAL);
    }
    pushContext(new SequenceContext(null));
    try {
        getCurrentWriter().beginArray();
    } catch (IOException ex) {
        throw new TTransportException(ex);
    }
}
Also used : TException(org.apache.thrift.TException) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException)

Example 23 with TTransportException

use of org.apache.thrift.transport.TTransportException in project metacat by Netflix.

the class HiveMetastoreClientFactory method createRawTransport.

protected TTransport createRawTransport(final String host, final int port) throws TTransportException {
    if (socksProxy == null) {
        final TTransport transport = new TSocket(host, port, timeoutMillis);
        try {
            transport.open();
            return transport;
        } catch (Throwable t) {
            transport.close();
            throw t;
        }
    }
    final Socket socks = createSocksSocket(socksProxy);
    try {
        try {
            socks.connect(InetSocketAddress.createUnresolved(host, port), timeoutMillis);
            socks.setSoTimeout(timeoutMillis);
            return new TSocket(socks);
        } catch (Throwable t) {
            closeQuietly(socks);
            throw t;
        }
    } catch (IOException e) {
        throw new TTransportException(e);
    }
}
Also used : TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) IOException(java.io.IOException) Socket(java.net.Socket) TSocket(org.apache.thrift.transport.TSocket) TSocket(org.apache.thrift.transport.TSocket)

Example 24 with TTransportException

use of org.apache.thrift.transport.TTransportException in project alluxio by Alluxio.

the class ThriftClientPool method createNewResource.

/**
   * Creates a thrift client instance.
   *
   * @return the thrift client created
   * @throws IOException if it fails to create a thrift client
   */
@Override
protected T createNewResource() throws IOException {
    TTransport transport = mTransportProvider.getClientTransport(mParentSubject, mAddress);
    TProtocol binaryProtocol = new TBinaryProtocol(transport);
    T client = createThriftClient(new TMultiplexedProtocol(binaryProtocol, mServiceName));
    TException exception;
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(BASE_SLEEP_MS, MAX_SLEEP_MS, RPC_MAX_NUM_RETRY);
    do {
        LOG.info("Alluxio client (version {}) is trying to connect with {} {} @ {}", RuntimeConstants.VERSION, mServiceName, mAddress);
        try {
            if (!transport.isOpen()) {
                transport.open();
            }
            if (transport.isOpen()) {
                checkVersion(client);
            }
            LOG.info("Client registered with {} @ {}", mServiceName, mAddress);
            return client;
        } catch (TTransportException e) {
            if (e.getCause() instanceof java.net.SocketTimeoutException) {
                // Do not retry if socket timeout.
                String message = "Thrift transport open times out. Please check whether the " + "authentication types match between client and server. Note that NOSASL client " + "is not able to connect to servers with SIMPLE security mode.";
                throw new IOException(message, e);
            }
            LOG.warn("Failed to connect ({}) to {} @ {}: {}", retryPolicy.getRetryCount(), mServiceName, mAddress, e.getMessage());
            exception = e;
        }
    } while (retryPolicy.attemptRetry());
    LOG.error("Failed after " + retryPolicy.getRetryCount() + " retries.");
    Preconditions.checkNotNull(exception);
    throw new IOException(exception);
}
Also used : TException(org.apache.thrift.TException) ExponentialBackoffRetry(alluxio.retry.ExponentialBackoffRetry) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException) TMultiplexedProtocol(org.apache.thrift.protocol.TMultiplexedProtocol) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TTransport(org.apache.thrift.transport.TTransport) RetryPolicy(alluxio.retry.RetryPolicy)

Example 25 with TTransportException

use of org.apache.thrift.transport.TTransportException in project voldemort by voldemort.

the class ThriftSerializer method toObject.

public T toObject(byte[] bytes) {
    MemoryBuffer buffer = new MemoryBuffer();
    try {
        buffer.write(bytes);
    } catch (TTransportException e) {
        throw new SerializationException(e);
    }
    TProtocol protocol = createThriftProtocol(buffer);
    T msg = null;
    try {
        msg = messageClass.newInstance();
        msg.read(protocol);
    } catch (InstantiationException e) {
        throw new SerializationException(e);
    } catch (IllegalAccessException e) {
        throw new SerializationException(e);
    } catch (TException e) {
        throw new SerializationException(e);
    }
    return msg;
}
Also used : TException(org.apache.thrift.TException) SerializationException(voldemort.serialization.SerializationException) TProtocol(org.apache.thrift.protocol.TProtocol) TTransportException(org.apache.thrift.transport.TTransportException)

Aggregations

TTransportException (org.apache.thrift.transport.TTransportException)67 IOException (java.io.IOException)23 TException (org.apache.thrift.TException)22 TTransport (org.apache.thrift.transport.TTransport)18 TSocket (org.apache.thrift.transport.TSocket)14 Test (org.junit.Test)13 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)8 TProtocol (org.apache.thrift.protocol.TProtocol)8 TFramedTransport (org.apache.thrift.transport.TFramedTransport)7 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 List (java.util.List)4 Map (java.util.Map)4 KeyAlreadyExistsException (backtype.storm.generated.KeyAlreadyExistsException)3 KeyNotFoundException (backtype.storm.generated.KeyNotFoundException)3 NimbusInfo (backtype.storm.nimbus.NimbusInfo)3 NimbusClient (backtype.storm.utils.NimbusClient)3 SocketException (java.net.SocketException)3 PrivilegedActionException (java.security.PrivilegedActionException)3 LoginException (javax.security.auth.login.LoginException)3