本文整理匯總了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();
}
示例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();
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
示例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();
}
}
}
示例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());
}
}
示例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;
}
示例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();
}
示例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();
}
}
示例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();
}
}
}
示例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);
}
}
示例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);
}
}
示例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;
}