Search in sources :

Example 26 with TTransportException

use of org.apache.thrift.transport.TTransportException in project eiger by wlloyd.

the class TCustomServerSocket method acceptImpl.

@Override
protected TCustomSocket acceptImpl() throws TTransportException {
    if (serverSocket_ == null)
        throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket.");
    TCustomSocket tsocket = null;
    Socket socket = null;
    try {
        socket = serverSocket_.accept();
        tsocket = new TCustomSocket(socket);
        tsocket.setTimeout(0);
    } catch (IOException iox) {
        throw new TTransportException(iox);
    }
    try {
        socket.setKeepAlive(this.keepAlive);
    } catch (SocketException se) {
        logger.warn("Failed to set keep-alive on Thrift socket.", se);
    }
    if (this.sendBufferSize != null) {
        try {
            socket.setSendBufferSize(this.sendBufferSize.intValue());
        } catch (SocketException se) {
            logger.warn("Failed to set send buffer size on Thrift socket.", se);
        }
    }
    if (this.recvBufferSize != null) {
        try {
            socket.setReceiveBufferSize(this.recvBufferSize.intValue());
        } catch (SocketException se) {
            logger.warn("Failed to set receive buffer size on Thrift socket.", se);
        }
    }
    return tsocket;
}
Also used : SocketException(java.net.SocketException) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException) ServerSocket(java.net.ServerSocket) TServerSocket(org.apache.thrift.transport.TServerSocket) Socket(java.net.Socket) TSocket(org.apache.thrift.transport.TSocket)

Example 27 with TTransportException

use of org.apache.thrift.transport.TTransportException in project simba-os by cegeka.

the class SimbaGateway method createAuthenticationService.

/**
	 * @return always creates a new client
	 * @throws SimbaUnavailableException
	 */
AuthenticationFilterService.Client createAuthenticationService() throws SimbaUnavailableException {
    try {
        tHttpClient = getTHttpClient();
        authenticationFilterService = simbaServiceFactory.createJSONAuthenticationFilterService(tHttpClient);
    } catch (TTransportException | RuntimeException e) {
        if (tHttpClient != null) {
            tHttpClient.close();
        }
        logger.error("Simba is down?", e);
        throw new SimbaUnavailableException(e);
    }
    return authenticationFilterService;
}
Also used : TTransportException(org.apache.thrift.transport.TTransportException) SimbaUnavailableException(org.simbasecurity.dwclient.exception.SimbaUnavailableException)

Example 28 with TTransportException

use of org.apache.thrift.transport.TTransportException in project simba-os by cegeka.

the class SimbaGatewayTest method isSimbaAlive_WhenTHttpFlushThrewSocketException_ReturnFalse.

@Test
public void isSimbaAlive_WhenTHttpFlushThrewSocketException_ReturnFalse() throws Exception {
    when(simbaServiceFactoryMock.createTHttpClient(SIMBA_WEB_URL + "/" + SIMBA_AUTHENTICATION_SERVICE)).thenThrow(new TTransportException(new SocketException()));
    assertThat(simbaGateway.isSimbaAlive()).isFalse();
}
Also used : SocketException(java.net.SocketException) TTransportException(org.apache.thrift.transport.TTransportException) Test(org.junit.Test)

Example 29 with TTransportException

use of org.apache.thrift.transport.TTransportException in project simba-os by cegeka.

the class SimbaGatewayTest method isSimbaAlive_WhenTHttpCouldFlushWithoutSocketException_ReturnTrue.

@Test
public void isSimbaAlive_WhenTHttpCouldFlushWithoutSocketException_ReturnTrue() throws Exception {
    when(simbaServiceFactoryMock.createTHttpClient(SIMBA_WEB_URL + "/" + SIMBA_AUTHENTICATION_SERVICE)).thenThrow(new TTransportException("HTTP Response code: 404"));
    assertThat(simbaGateway.isSimbaAlive()).isTrue();
}
Also used : TTransportException(org.apache.thrift.transport.TTransportException) Test(org.junit.Test)

Example 30 with TTransportException

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

the class TBoundedThreadPoolServer method serve.

public void serve() {
    try {
        serverTransport_.listen();
    } catch (TTransportException ttx) {
        LOG.error("Error occurred during listening.", ttx);
        return;
    }
    Runtime.getRuntime().addShutdownHook(new Thread(getClass().getSimpleName() + "-shutdown-hook") {

        @Override
        public void run() {
            TBoundedThreadPoolServer.this.stop();
        }
    });
    stopped = false;
    while (!stopped && !Thread.interrupted()) {
        TTransport client = null;
        try {
            client = serverTransport_.accept();
        } catch (TTransportException ttx) {
            if (!stopped) {
                LOG.warn("Transport error when accepting message", ttx);
                continue;
            } else {
                // The server has been stopped
                break;
            }
        }
        ClientConnnection command = new ClientConnnection(client);
        try {
            executorService.execute(command);
        } catch (RejectedExecutionException rex) {
            if (client.getClass() == TSocket.class) {
                // We expect the client to be TSocket.
                LOG.warn(QUEUE_FULL_MSG + " from " + ((TSocket) client).getSocket().getRemoteSocketAddress());
            } else {
                LOG.warn(QUEUE_FULL_MSG, rex);
            }
            client.close();
        }
    }
    shutdownServer();
}
Also used : TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) TSocket(org.apache.thrift.transport.TSocket)

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