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


Java TTransport.close方法代碼示例

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


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

示例1: startClient

import org.apache.thrift.transport.TTransport; //導入方法依賴的package包/類
public static void startClient(String ip ,int port ,int timeout) throws Exception
{
	TTransport transport = new TSocket(ip,port,timeout);
	TProtocol protocol = new TBinaryProtocol(transport);
	leafrpc.Client client = new leafrpc.Client(protocol);
	transport.open();

	int i = 0;
	while(i < 2000000)
	{
		 client.getID("");
		 ++i;
	}

	transport.close();
}
 
開發者ID:weizhenyi,項目名稱:leaf-snowflake,代碼行數:17,代碼來源:rpcClient.java

示例2: startClient2

import org.apache.thrift.transport.TTransport; //導入方法依賴的package包/類
public static void startClient2(String ip ,int port ,int timeout) throws Exception
{
	TTransport transport = new TFramedTransport(new TSocket(ip,port,timeout));
	TProtocol protocol = new TBinaryProtocol(transport);
	leafrpc.Client client = new leafrpc.Client(protocol);
	transport.open();

	for(int i = 0; i< 1000000; i++)
	{
		client.getID("");
		if (i % 100000 == 0)
		{
			System.out.println(Thread.currentThread().getName() + " " + client.getID(""));
		}
		//ai.incrementAndGet();
	}
	transport.close();
}
 
開發者ID:weizhenyi,項目名稱:leaf-snowflake,代碼行數:19,代碼來源:rpcClient.java

示例3: deflateNonNull

import org.apache.thrift.transport.TTransport; //導入方法依賴的package包/類
/**
 * Encodes a thrift object into a DEFLATE-compressed binary array.
 *
 * @param tBase Object to encode.
 * @return Deflated, encoded object.
 * @throws CodingException If the object could not be encoded.
 */
public static byte[] deflateNonNull(TBase<?, ?> tBase) throws CodingException {
  requireNonNull(tBase);

  // NOTE: Buffering is needed here for performance.
  // There are actually 2 buffers in play here - the BufferedOutputStream prevents thrift from
  // causing a call to deflate() on every encoded primitive. The DeflaterOutputStream buffer
  // allows the underlying Deflater to operate on a larger chunk at a time without stopping to
  // copy the intermediate compressed output to outBytes.
  // See http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4986239
  ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
  TTransport transport = new TIOStreamTransport(
      new BufferedOutputStream(
          new DeflaterOutputStream(outBytes, new Deflater(DEFLATE_LEVEL), DEFLATER_BUFFER_SIZE),
          DEFLATER_BUFFER_SIZE));
  try {
    TProtocol protocol = PROTOCOL_FACTORY.getProtocol(transport);
    tBase.write(protocol);
    transport.close(); // calls finish() on the underlying stream, completing the compression
    return outBytes.toByteArray();
  } catch (TException e) {
    throw new CodingException("Failed to serialize: " + tBase, e);
  } finally {
    transport.close();
  }
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:33,代碼來源:ThriftBinaryCodec.java

示例4: inflateNonNull

import org.apache.thrift.transport.TTransport; //導入方法依賴的package包/類
/**
 * Decodes a thrift object from a DEFLATE-compressed byte array into a target type.
 *
 * @param clazz Class to instantiate and deserialize to.
 * @param buffer Compressed buffer to decode.
 * @return A populated message.
 * @throws CodingException If the message could not be decoded.
 */
public static <T extends TBase<T, ?>> T inflateNonNull(Class<T> clazz, byte[] buffer)
    throws CodingException {

  requireNonNull(clazz);
  requireNonNull(buffer);

  T tBase = newInstance(clazz);
  TTransport transport = new TIOStreamTransport(
        new InflaterInputStream(new ByteArrayInputStream(buffer)));
  try {
    TProtocol protocol = PROTOCOL_FACTORY.getProtocol(transport);
    tBase.read(protocol);
    return tBase;
  } catch (TException e) {
    throw new CodingException("Failed to deserialize: " + e, e);
  } finally {
    transport.close();
  }
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:28,代碼來源:ThriftBinaryCodec.java

示例5: connectToCMD

import org.apache.thrift.transport.TTransport; //導入方法依賴的package包/類
private static void connectToCMD() {
    QueryInput query_input = new QueryInput();
    query_input.type = "ensemble";
    query_input.data = new ArrayList<String>();
    query_input.data.add("localhost");
    query_input.tags = new ArrayList<String>();
    query_input.tags.add("9090");
    QuerySpec spec = new QuerySpec();
    spec.content = new ArrayList<QueryInput>();
    spec.content.add(query_input);
    // Initialize thrift objects.
    TTransport transport = new TSocket("localhost", 8080);
    TProtocol protocol = new TBinaryProtocol(new TFramedTransport(transport));
    LucidaService.Client client = new LucidaService.Client(protocol);
    try {
        transport.open();
        System.out.println("Connecting to CMD at port " + 8080);
        // Register itself to CMD.
        client.create("", spec);
        transport.close();
        System.out.println("Successfully connected to CMD");
    } catch (TException x) {
        x.printStackTrace();
    }
}
 
開發者ID:k0105,項目名稱:ensemble,代碼行數:26,代碼來源:ThriftServer.java

示例6: dropOldKeyspace

import org.apache.thrift.transport.TTransport; //導入方法依賴的package包/類
private void dropOldKeyspace() throws InvalidRequestException, SchemaDisagreementException, TException {
  TTransport tr = new TFramedTransport(new TSocket("localhost", 9160));
  TProtocol proto = new TBinaryProtocol(tr);
  Cassandra.Client client = new Cassandra.Client(proto);
  tr.open();

  client.system_drop_keyspace(JANUSGRAPH);
  LOGGER.info("DROPPED keyspace janusgraph");
  tr.close();
}
 
開發者ID:marcelocf,項目名稱:janusgraph_tutorial,代碼行數:11,代碼來源:Schema.java

示例7: onRemoval

import org.apache.thrift.transport.TTransport; //導入方法依賴的package包/類
@Override
public void onRemoval(RemovalNotification<DeviceId, Pair<TTransport, Bmv2DeviceThriftClient>> notification) {
    // close the transport connection
    Bmv2DeviceThriftClient client = notification.getValue().getRight();
    TTransport transport = notification.getValue().getLeft();
    // Locking here is ugly, but needed (see SafeThriftClient).
    synchronized (transport) {
        if (transport.isOpen()) {
            transport.close();
        }
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:13,代碼來源:Bmv2ControllerImpl.java

示例8: destroyObject

import org.apache.thrift.transport.TTransport; //導入方法依賴的package包/類
@Override
public void destroyObject(ThriftServer thriftServer, PooledObject<TTransport> pooledObject) throws Exception {
	TTransport transport = pooledObject.getObject();
	if (transport != null) {
		transport.close();
		logger.trace("Close thrift connection: {}:{}", thriftServer.getHost(), thriftServer.getPort());
	}
}
 
開發者ID:cyfonly,項目名稱:ThriftJ,代碼行數:9,代碼來源:ThriftConnectionFactory.java

示例9: getTimestamp

import org.apache.thrift.transport.TTransport; //導入方法依賴的package包/類
public static long getTimestamp(String ip, int port ,int timeout) throws Exception
{
	TTransport transport = new TSocket(ip,port,timeout);
	TProtocol protocol = new TBinaryProtocol(transport);
	leafrpc.Client client = new leafrpc.Client(protocol);
	transport.open();
	long timestamp = client.gettimestamp(Utils.currentTimeMs());
	transport.close();
	return timestamp;
}
 
開發者ID:weizhenyi,項目名稱:leaf-snowflake,代碼行數:11,代碼來源:rpcClient.java

示例10: destroyObject

import org.apache.thrift.transport.TTransport; //導入方法依賴的package包/類
@Override
public void destroyObject(TServiceClient client) throws Exception {
    if (callback != null) {
        try {
            callback.destroy(client);
        } catch (Exception e) {
            logger.warn("destroyObject:{}", e);
        }
    }
    logger.info("destroyObject:{}", client);
    TTransport pin = client.getInputProtocol().getTransport();
    pin.close();
    TTransport pout = client.getOutputProtocol().getTransport();
    pout.close();
}
 
開發者ID:somewhereMrli,項目名稱:albedo-thrift,代碼行數:16,代碼來源:ThriftClientPoolFactory.java

示例11: run

import org.apache.thrift.transport.TTransport; //導入方法依賴的package包/類
/**
 * Loops on processing a client forever
 */
public void run() {
  TProcessor processor = null;
  TTransport inputTransport = null;
  TTransport outputTransport = null;
  TProtocol inputProtocol = null;
  TProtocol outputProtocol = null;
  try {
    processor = processorFactory_.getProcessor(client);
    inputTransport = inputTransportFactory_.getTransport(client);
    outputTransport = outputTransportFactory_.getTransport(client);
    inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
    outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
    // we check stopped_ first to make sure we're not supposed to be shutting
    // down. this is necessary for graceful shutdown.
    while (!stopped && processor.process(inputProtocol, outputProtocol)) {}
  } catch (TTransportException ttx) {
    // Assume the client died and continue silently
  } catch (TException tx) {
    LOG.error("Thrift error occurred during processing of message.", tx);
  } catch (Exception x) {
    LOG.error("Error occurred during processing of message.", x);
  }

  if (inputTransport != null) {
    inputTransport.close();
  }

  if (outputTransport != null) {
    outputTransport.close();
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:35,代碼來源:TBoundedThreadPoolServer.java

示例12: close

import org.apache.thrift.transport.TTransport; //導入方法依賴的package包/類
private void close( TProtocol protocol ) {
    if ( protocol != null ) {
        TTransport transport = protocol.getTransport();
        if ( transport != null && transport.isOpen() ) {
            transport.close();
        }
    }
}
 
開發者ID:dneves,項目名稱:thrift-ui-fx,代碼行數:9,代碼來源:MethodRequestController.java

示例13: destroyObject

import org.apache.thrift.transport.TTransport; //導入方法依賴的package包/類
@Override
public void destroyObject(ThriftServerInfo info, PooledObject<TTransport> p)
        throws Exception {
    TTransport transport = p.getObject();
    if (transport != null && transport.isOpen()) {
        transport.close();
        logger.trace("close thrift connection:{}", info);
    }
}
 
開發者ID:ngayngo9x,項目名稱:q-thrift,代碼行數:10,代碼來源:DefaultThriftConnectionPoolImpl.java

示例14: get

import org.apache.thrift.transport.TTransport; //導入方法依賴的package包/類
@Override
public String get(String arg) throws STException {
	TTransport transport = oprot_.getTransport();
	try {
		if (!transport.isOpen())
			transport.open();
		LOG.debug("Transport is open .");
		sendGet(arg);
		return recvGet();
	} catch (TException e) {
		transport.close();
		LOG.debug("Transport is close .");
		throw new STException("Execute failed !", e);
	}
}
 
開發者ID:venwyhk,項目名稱:ikasoa,代碼行數:16,代碼來源:ServiceClientImpl.java

示例15: destroy

import org.apache.thrift.transport.TTransport; //導入方法依賴的package包/類
public void destroy() throws NaviSystemException {
    TTransport transport = client.getInputProtocol().getTransport();
    if (transport != null && transport.isOpen()) {
        transport.close();
        log.info("scribe client is closed successfully!");
    }
    client = null;
}
 
開發者ID:sunguangran,項目名稱:navi,代碼行數:9,代碼來源:NaviScribeDriver.java


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