當前位置: 首頁>>代碼示例>>Java>>正文


Java TTransportException類代碼示例

本文整理匯總了Java中org.apache.thrift.transport.TTransportException的典型用法代碼示例。如果您正苦於以下問題:Java TTransportException類的具體用法?Java TTransportException怎麽用?Java TTransportException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TTransportException類屬於org.apache.thrift.transport包,在下文中一共展示了TTransportException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createServerTransport

import org.apache.thrift.transport.TTransportException; //導入依賴的package包/類
private static TServerSocket createServerTransport(boolean secure)
        throws TTransportException
{
    if (!secure) {
        return new TServerSocket(0);
    }

    try {
        SSLContext serverSslContext = ClientTestUtils.getServerSslContext();
        SSLServerSocket serverSocket = (SSLServerSocket) serverSslContext.getServerSocketFactory().createServerSocket(0);
        return new TServerSocket(serverSocket);
    }
    catch (Exception e) {
        throw new TTransportException("Error initializing secure socket", e);
    }
}
 
開發者ID:airlift,項目名稱:drift,代碼行數:17,代碼來源:TestClientsWithApacheServer.java

示例2: createClientSocket

import org.apache.thrift.transport.TTransportException; //導入依賴的package包/類
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);
    }
}
 
開發者ID:airlift,項目名稱:drift,代碼行數:18,代碼來源:LegacyApacheThriftTesterUtil.java

示例3: start

import org.apache.thrift.transport.TTransportException; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@Override
public void start() {
  try {
    InetSocketAddress bindAddr = new InetSocketAddress(host, port);
    serverTransport = new TServerSocket(bindAddr);
    ThriftFlumeEventServer.Processor processor =
        new ThriftFlumeEventServer.Processor(new ThriftFlumeEventServerImpl());
    server = new TThreadPoolServer(
        new TThreadPoolServer.Args(serverTransport).processor(processor));
  } catch (TTransportException e) {
    throw new FlumeException("Failed starting source", e);
  }
  ThriftHandler thriftHandler = new ThriftHandler(server);
  thriftHandlerThread = new Thread(thriftHandler);
  thriftHandlerThread.start();
  super.start();
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:19,代碼來源:ThriftLegacySource.java

示例4: startServer

import org.apache.thrift.transport.TTransportException; //導入依賴的package包/類
@BeforeClass
public static void startServer() throws InterruptedException, TTransportException, ConfigurationException, IOException, URISyntaxException  {
    if (! started) {
        EmbeddedCassandraServerHelper.startEmbeddedCassandra(CASSANDRA_UNIT_RANDOM_PORT_YAML, CASSANDRA_TIMEOUT);
        Cluster cluster = new Cluster.Builder().addContactPoints("127.0.0.1").withPort(getNativeTransportPort()).build();
        Session session = cluster.connect();
        String createQuery = "CREATE KEYSPACE " + CASSANDRA_UNIT_KEYSPACE + " WITH replication={'class' : 'SimpleStrategy', 'replication_factor':1}";
        session.execute(createQuery);
        String useKeyspaceQuery = "USE " + CASSANDRA_UNIT_KEYSPACE;
        session.execute(useKeyspaceQuery);
        CQLDataLoader dataLoader = new CQLDataLoader(session);
        applyScripts(dataLoader, "config/cql/changelog/", "*.cql");
        started = true;
    }
}
 
開發者ID:xm-online,項目名稱:xm-ms-timeline,代碼行數:16,代碼來源:AbstractCassandraTest.java

示例5: load

import org.apache.thrift.transport.TTransportException; //導入依賴的package包/類
@Override
public Pair<TTransport, Bmv2DeviceThriftClient> load(DeviceId deviceId)
        throws TTransportException {
    log.debug("Instantiating new client... > deviceId={}", deviceId);
    // Make the expensive call
    Bmv2Device device = Bmv2Device.of(deviceId);
    TTransport transport = new TSocket(device.thriftServerHost(), device.thriftServerPort());
    TProtocol protocol = new TBinaryProtocol(transport);
    // Our BMv2 device implements multiple Thrift services, create a client for each one on the same transport.
    Standard.Client standardClient = new Standard.Client(
            new TMultiplexedProtocol(protocol, "standard"));
    SimpleSwitch.Client simpleSwitch = new SimpleSwitch.Client(
            new TMultiplexedProtocol(protocol, "simple_switch"));
    // Wrap clients so to automatically have synchronization and resiliency to connectivity errors
    Standard.Iface safeStandardClient = SafeThriftClient.wrap(standardClient,
                                                              Standard.Iface.class,
                                                              options);
    SimpleSwitch.Iface safeSimpleSwitchClient = SafeThriftClient.wrap(simpleSwitch,
                                                                      SimpleSwitch.Iface.class,
                                                                      options);
    Bmv2DeviceThriftClient client = new Bmv2DeviceThriftClient(deviceId,
                                                               transport,
                                                               safeStandardClient,
                                                               safeSimpleSwitchClient);
    return Pair.of(transport, client);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:27,代碼來源:Bmv2ControllerImpl.java

示例6: invoke

import org.apache.thrift.transport.TTransportException; //導入依賴的package包/類
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

    // Thrift transport layer is not thread-safe (it's a wrapper on a socket), hence we need locking.
    synchronized (transport) {

        LOG.debug("Invoking method... > fromThread={}, method={}, args={}",
                  Thread.currentThread().getId(), method.getName(), args);

        try {

            return method.invoke(baseClient, args);
        } catch (InvocationTargetException e) {
            if (e.getTargetException() instanceof TTransportException) {
                TTransportException cause = (TTransportException) e.getTargetException();

                if (RESTARTABLE_CAUSES.contains(cause.getType())) {
                    // Try to reconnect. If fail, a TTransportException will be thrown.
                    reconnectOrThrowException();
                    try {
                        // If here, transport has been successfully open, hence new exceptions will be thrown.
                        return method.invoke(baseClient, args);
                    } catch (InvocationTargetException e1) {
                        LOG.debug("Exception: {}", e1.getTargetException());
                        throw e1.getTargetException();
                    }
                }
            }
            // Target exception is neither a TTransportException nor a restartable cause.
            LOG.debug("Exception: {}", e.getTargetException());
            throw e.getTargetException();
        }
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:35,代碼來源:SafeThriftClient.java

示例7: flush

import org.apache.thrift.transport.TTransportException; //導入依賴的package包/類
@Override
public void flush() throws TTransportException {
    synchronized (sendLock) {
        byte[] bytes = new byte[MAX_BUFFER_SIZE];
        int length = writeBuffer.position();

        writeBuffer.flip();
        writeBuffer.get(bytes, 0, length);

        try {
            socket.send(new DatagramPacket(bytes, length));
        } catch (IOException e) {
            throw new TTransportException(e);
        } finally {
            writeBuffer.clear();
        }
    }
}
 
開發者ID:uber-java,項目名稱:tally,代碼行數:19,代碼來源:TUdpClient.java

示例8: write

import org.apache.thrift.transport.TTransportException; //導入依賴的package包/類
@Override
public void write(byte[] bytes, int offset, int length) throws TTransportException {
    if (!isOpen()) {
        throw new TTransportException(TTransportException.NOT_OPEN);
    }

    synchronized (sendLock) {
        if (writeBuffer.position() + length > MAX_BUFFER_SIZE) {
            throw new TTransportException(
                String.format("Message size too large: %d is greater than available size %d",
                    length,
                    MAX_BUFFER_SIZE - writeBuffer.position()
                )
            );
        }

        writeBuffer.put(bytes, offset, length);
    }
}
 
開發者ID:uber-java,項目名稱:tally,代碼行數:20,代碼來源:TUdpTransport.java

示例9: emitMetricBatch

import org.apache.thrift.transport.TTransportException; //導入依賴的package包/類
public void emitMetricBatch(MetricBatch batch) throws TTransportException {
    lock.writeLock().lock();

    batches.add(batch);

    if (countBatches) {
        phaser.arrive();
    }

    for (Metric metric : batch.getMetrics()) {
        metrics.add(metric);

        if (!countBatches) {
            phaser.arrive();
        }
    }

    lock.writeLock().unlock();

    throw new TTransportException(TTransportException.END_OF_FILE, "complete");
}
 
開發者ID:uber-java,項目名稱:tally,代碼行數:22,代碼來源:MockM3Service.java

示例10: createServerSocket

import org.apache.thrift.transport.TTransportException; //導入依賴的package包/類
private TServerSocket createServerSocket(boolean useSSL, int port) throws IOException, TTransportException {
  TServerSocket serverSocket = null;
  // enable SSL support for HMS
  List<String> sslVersionBlacklist = new ArrayList<>();
  for (String sslVersion : hiveConf.getVar(ConfVars.HIVE_SSL_PROTOCOL_BLACKLIST).split(",")) {
    sslVersionBlacklist.add(sslVersion);
  }
  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;
}
 
開發者ID:HotelsDotCom,項目名稱:waggle-dance,代碼行數:22,代碼來源:MetaStoreProxyServer.java

示例11: ServerThread

import org.apache.thrift.transport.TTransportException; //導入依賴的package包/類
ServerThread() throws TTransportException {
   TMultiplexedProcessor processor = new TMultiplexedProcessor();
   for (String beanName : serviceMap.keySet()) {
      IThriftServerService serverService = (IThriftServerService) serviceMap.getService(beanName);
      String processorName = serverService.getName();
      TProcessor tProcessor = serverService.getProcessor(serverService);
      processor.registerProcessor(processorName, tProcessor);
      logger.info("Register a processorName {} processorImpl {}", processorName, tProcessor);
   }

   logger.info("init default TServerTransport in addr {} port {}", applicationProperties.getAddr(), applicationProperties.getPort());
   TServerTransport tServerTransport = new TServerSocket(new InetSocketAddress(applicationProperties.getAddr(),
           applicationProperties.getPort()));
   TThreadPoolServer.Args args = new TThreadPoolServer.Args(tServerTransport);
   args.processor(processor);
   args.protocolFactory(tProtocolFactory);
   server = new TThreadPoolServer(args);
}
 
開發者ID:somewhereMrli,項目名稱:albedo-thrift,代碼行數:19,代碼來源:ThriftServer.java

示例12: TsfileConnection

import org.apache.thrift.transport.TTransportException; //導入依賴的package包/類
public TsfileConnection(String url, Properties info) throws SQLException, TTransportException {
if (url == null) {
    throw new TsfileURLException("Input url cannot be null");
}
params = Utils.parseURL(url, info);

supportedProtocols.add(TSProtocolVersion.TSFILE_SERVICE_PROTOCOL_V1);

openTransport();
client = new TSIService.Client(new TBinaryProtocol(transport));
// open client session
openSession();
// Wrap the client with a thread-safe proxy to serialize the RPC calls
client = newSynchronizedClient(client);
autoCommit = false;
   }
 
開發者ID:thulab,項目名稱:iotdb-jdbc,代碼行數:17,代碼來源:TsfileConnection.java

示例13: getTThreadPoolServer

import org.apache.thrift.transport.TTransportException; //導入依賴的package包/類
private static TServer getTThreadPoolServer(TProtocolFactory protocolFactory,
                                            TProcessor processor,
                                            TTransportFactory transportFactory,
                                            int workerThreads,
                                            InetSocketAddress inetSocketAddress,
                                            int backlog,
                                            int clientTimeout)
    throws TTransportException {
  TServerTransport serverTransport = new TServerSocket(
                                         new TServerSocket.ServerSocketTransportArgs().
                                             bindAddr(inetSocketAddress).backlog(backlog).
                                             clientTimeout(clientTimeout));
  log.info("starting HBase ThreadPool Thrift server on " + inetSocketAddress.toString());
  TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);
  serverArgs.processor(processor);
  serverArgs.transportFactory(transportFactory);
  serverArgs.protocolFactory(protocolFactory);
  if (workerThreads > 0) {
    serverArgs.maxWorkerThreads(workerThreads);
  }
  return new TThreadPoolServer(serverArgs);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:23,代碼來源:ThriftServer.java

示例14: ensureMockCassandraRunningAndEstablished

import org.apache.thrift.transport.TTransportException; //導入依賴的package包/類
/**
 * Ensures that the Mock Cassandra instance is up and running. Will reinit
 * the database every time it is called.
 *
 * @param cassandraKeyspace Cassandra keyspace to setup.
 * @return A cluster object.
 * @throws ConfigurationException
 * @throws IOException
 * @throws InterruptedException
 * @throws TTransportException
 */
public static Cluster ensureMockCassandraRunningAndEstablished(String cassandraKeyspace) throws ConfigurationException, IOException, InterruptedException, TTransportException
{
    Cluster cluster;
    long timeout = 60000;
    EmbeddedCassandraServerHelper.startEmbeddedCassandra(timeout);
    cluster = Cluster.builder().addContactPoints("127.0.0.1").withPort(9142).build();
    //Thread.sleep(20000);//time to let cassandra startup
    final Metadata metadata = cluster.getMetadata();

    Session session = cluster.connect();
    Utils.initDatabase(DB_CQL, session);
    session = cluster.connect(cassandraKeyspace);

    logger.info("Connected to cluster: " + metadata.getClusterName() + '\n');
    return cluster;
}
 
開發者ID:PearsonEducation,項目名稱:Docussandra,代碼行數:28,代碼來源:Fixtures.java

示例15: resolveHost

import org.apache.thrift.transport.TTransportException; //導入依賴的package包/類
public InetAddress resolveHost() throws TTransportException {
  // TODO: SW: JDK's InetAddress has an inbuilt cache but it is no good
  // and does not honour DNS TTL etc. Custom DNSCacheService should be
  // added for better behaviour.

  // InetAddress addr = DNSCacheService.getInstance().lookupCache(hostName);
  try {
    return InetAddress.getByName(this.hostName);
  } catch (UnknownHostException uhe) {
    // use ipAddress if available
    if (this.ipAddress != null) {
      try {
        return InetAddress.getByName(this.ipAddress);
      } catch (UnknownHostException e) {
        throw new TTransportException(e);
      }
    }
    else {
      throw new TTransportException(uhe);
    }
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:23,代碼來源:HostAddress.java


注:本文中的org.apache.thrift.transport.TTransportException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。