Example usage for org.apache.thrift.transport TTransportException TTransportException

List of usage examples for org.apache.thrift.transport TTransportException TTransportException

Introduction

In this page you can find the example usage for org.apache.thrift.transport TTransportException TTransportException.

Prototype

public TTransportException(int type, String message, Throwable cause) 

Source Link

Usage

From source file:com.facebook.nifty.client.TNiftyClientChannelTransport.java

License:Apache License

@Override
public void flush() throws TTransportException {
    try {/*from www .j av  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.facebook.presto.hive.metastore.thrift.Transport.java

License:Apache License

private static TTransportException rewriteException(TTransportException e, String host) {
    return new TTransportException(e.getType(), String.format("%s: %s", host, e.getMessage()), e.getCause());
}

From source file:com.facebook.tools.example.ThriftService.java

License:Apache License

private T openService(HostAndPort host, ThriftClient<T> client, Transport transport)
        throws TTransportException {
    try {/*  w  w  w .  ja  va2 s.  c o  m*/
        NiftyClientConnector<? extends NiftyClientChannel> connector;

        if (Transport.FRAMED.equals(transport)) {
            connector = new FramedClientConnector(host);
        } else if (Transport.BUFFERED.equals(transport)) {
            connector = new UnframedClientConnector(host);
        } else {
            throw new ErrorMessage("Unexpected thrift transport type: %s", transport);
        }

        return client.open(connector).get();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();

        throw new TTransportException(TIMED_OUT, "Interrupted opening connection to " + host, e);
    } catch (ExecutionException e) {
        Throwable cause = e.getCause();

        Throwables.propagateIfInstanceOf(cause, TTransportException.class);

        throw new TTransportException(UNKNOWN, "Exception opening connection to " + host, cause);
    }
}

From source file:com.netflix.metacat.connector.hive.client.thrift.HiveMetastoreClientFactory.java

License:Apache License

private static TTransportException rewriteException(final TTransportException e, final String host) {
    return new TTransportException(e.getType(), String.format("%s: %s", host, e.getMessage()), e.getCause());
}

From source file:com.palantir.atlasdb.keyvalue.cassandra.CassandraClientPool.java

License:Open Source License

@SuppressWarnings("unchecked")
private <K extends Exception> void handleException(int numTries, InetSocketAddress host, Exception e) throws K {
    if (isRetriableException(e)) {
        if (numTries >= MAX_TRIES) {
            if (e instanceof TTransportException && e.getCause() != null
                    && (e.getCause().getClass() == SocketException.class)) {
                String msg = "Error writing to Cassandra socket. Likely cause: Exceeded maximum thrift frame size; unlikely cause: network issues.";
                log.error("Tried to connect to cassandra " + numTries + " times. " + msg, e);
                e = new TTransportException(((TTransportException) e).getType(), msg, e);
            } else {
                log.error("Tried to connect to cassandra " + numTries + " times.", e);
            }/*w  ww . j a  v a  2 s  .c o m*/
            throw (K) e;
        } else {
            log.warn("Error occurred talking to cassandra. Attempt {} of {}.", numTries, MAX_TRIES, e);
            if (isConnectionException(e)) {
                addToBlacklist(host);
            }
        }
    } else {
        throw (K) e;
    }
}

From source file:com.palantir.atlasdb.keyvalue.cassandra.RetriableManyHostPoolingContainer.java

License:Open Source License

@SuppressWarnings("unchecked")
private <K extends Exception> void handleException(int numTries, Exception e) throws K {
    if (e instanceof ClientCreationFailedException || e instanceof TTransportException
            || e instanceof TimedOutException || e instanceof SocketTimeoutException
            || e instanceof UnavailableException || e instanceof InsufficientConsistencyException) {
        if (numTries >= maxTries) {
            if (e instanceof TTransportException && e.getCause() != null
                    && (e.getCause().getClass() == SocketException.class)) {
                String msg = "Error writing to Cassandra socket. Likely cause: Exceeded maximum thrift frame size; unlikely cause: network issues.";
                log.error("Tried to connect to cassandra " + numTries + " times. " + msg, e);
                e = new TTransportException(((TTransportException) e).getType(), msg, e);
            } else {
                log.error("Tried to connect to cassandra " + numTries + " times.", e);
            }/*from   ww w. j  a v a 2  s. co  m*/
            throw (K) e;
        } else {
            log.warn("Error occurred talking to cassandra. Attempt {} of {}.", numTries, maxTries, e);
            if (e instanceof SocketTimeoutException || e instanceof UnavailableException) {
                // Connection is no good? This may be due to a long GC, we should back off sending them requests.
                // Binary exponential backoff; should in total take ~10s on average w/maxTries=10
                try {
                    Thread.sleep(new Random().nextInt((1 << numTries) - 1) * 20);
                } catch (InterruptedException e1) {
                    Thread.currentThread().interrupt();
                }
            }
        }
    } else {
        throw (K) e;
    }
}

From source file:com.palantir.atlasdb.keyvalue.cassandra.RetriablePoolingContainer.java

License:Open Source License

@SuppressWarnings("unchecked")
private <K extends Exception> void handleException(int numTries, Exception e) throws K {
    if (e instanceof ClientCreationFailedException || e instanceof TTransportException
            || e instanceof TimedOutException || e instanceof SocketTimeoutException
            || e instanceof UnavailableException || e instanceof InsufficientConsistencyException) {
        if (numTries >= MAX_TRIES) {
            if (e instanceof TTransportException && e.getCause() != null
                    && (e.getCause().getClass() == SocketException.class)) {
                String msg = "Error writing to Cassandra socket. Likely cause: Exceeded maximum thrift frame size; unlikely cause: network issues.";
                log.error("Tried to connect to cassandra " + numTries + " times. " + msg, e);
                e = new TTransportException(((TTransportException) e).getType(), msg, e);
            } else {
                log.error("Tried to connect to cassandra " + numTries + " times.", e);
            }// w  ww.  j  a  v  a 2 s.  c  om
            throw (K) e;
        } else {
            log.warn("Transport failure to cassandra. We will retry.", e);
            if (e instanceof SocketTimeoutException || e instanceof UnavailableException) {
                // Connection is no good? This may be due to a long GC, we should back off sending them requests.
                // Binary exponential backoff; should in total take ~10s on average w/MAX_TRIES=10
                try {
                    Thread.sleep(new Random().nextInt((1 << numTries) - 1) * 20);
                } catch (InterruptedException e1) {
                    Thread.currentThread().interrupt();
                }
            }
        }
    } else {
        throw (K) e;
    }
}

From source file:com.uber.jaeger.reporters.protocols.ThriftUdpTransport.java

License:Open Source License

@Override
public void flush() throws TTransportException {
    if (this.writeBuffer != null) {
        byte[] bytes = new byte[MAX_PACKET_SIZE];
        int len = this.writeBuffer.position();
        this.writeBuffer.flip();
        this.writeBuffer.get(bytes, 0, len);
        try {//from  w ww . java 2  s.  c om
            this.socket.send(new DatagramPacket(bytes, len));
        } catch (IOException e) {
            throw new TTransportException(TTransportException.UNKNOWN, "Cannot flush closed transport", e);
        } finally {
            this.writeBuffer = null;
        }
    }
}

From source file:io.mandrel.transport.thrift.nifty.NiftyClient.java

License:Apache License

public <T extends NiftyClientChannel> TNiftyClientChannelTransport connectSync(
        Class<? extends TServiceClient> clientClass, NiftyClientConnector<T> clientChannelConnector,
        @Nullable Duration connectTimeout, @Nullable Duration receiveTimeout, @Nullable Duration readTimeout,
        @Nullable Duration sendTimeout, int maxFrameSize, @Nullable HostAndPort socksProxyAddress)
        throws TTransportException, InterruptedException {
    try {/*from  www  . ja v a 2s .  c  o m*/
        T channel = connectAsync(clientChannelConnector, connectTimeout, receiveTimeout, readTimeout,
                sendTimeout, maxFrameSize, socksProxyAddress).get();
        return new TNiftyClientChannelTransport(clientClass, channel);
    } catch (ExecutionException e) {
        Throwables.propagateIfInstanceOf(e, TTransportException.class);
        throw new TTransportException(TTransportException.UNKNOWN, "Failed to establish client connection", e);
    }
}

From source file:io.prestosql.plugin.hive.metastore.thrift.Transport.java

License:Apache License

private static TTransportException rewriteException(TTransportException e, HostAndPort address) {
    return new TTransportException(e.getType(), String.format("%s: %s", address, e.getMessage()), e);
}