本文整理汇总了Java中org.apache.thrift.transport.TNonblockingTransport.close方法的典型用法代码示例。如果您正苦于以下问题:Java TNonblockingTransport.close方法的具体用法?Java TNonblockingTransport.close怎么用?Java TNonblockingTransport.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.thrift.transport.TNonblockingTransport
的用法示例。
在下文中一共展示了TNonblockingTransport.close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleAccept
import org.apache.thrift.transport.TNonblockingTransport; //导入方法依赖的package包/类
/**
* Accept a new connection.
*/
private void handleAccept() {
final TNonblockingTransport client = doAccept();
if (client != null) {
// Pass this connection to a selector thread
final SelectorThread targetThread = threadChooser.nextThread();
if (args.acceptPolicy == Args.AcceptPolicy.FAST_ACCEPT || invoker == null) {
doAddAccept(targetThread, client);
} else {
// FAIR_ACCEPT
try {
invoker.submit(new Runnable() {
public void run() {
doAddAccept(targetThread, client);
}
});
} catch (RejectedExecutionException rx) {
LOGGER.warn("ExecutorService rejected accept registration!", rx);
// close immediately
client.close();
}
}
}
}
示例2: registerAccepted
import org.apache.thrift.transport.TNonblockingTransport; //导入方法依赖的package包/类
private void registerAccepted(TNonblockingTransport accepted) {
SelectionKey clientKey = null;
try {
clientKey = accepted.registerSelector(selector, SelectionKey.OP_READ);
FrameBuffer frameBuffer = createFrameBuffer(accepted, clientKey, SelectorThread.this);
clientKey.attach(frameBuffer);
} catch (IOException e) {
LOGGER.warn("Failed to register accepted connection to selector!", e);
if (clientKey != null) {
cleanupSelectionKey(clientKey);
}
accepted.close();
}
}
示例3: registerAccepted
import org.apache.thrift.transport.TNonblockingTransport; //导入方法依赖的package包/类
private void registerAccepted(TNonblockingTransport accepted) {
SelectionKey clientKey = null;
try {
clientKey = accepted.registerSelector(selector, SelectionKey.OP_READ);
FrameBuffer frameBuffer = new FrameBuffer(accepted, clientKey, SelectorThread.this);
clientKey.attach(frameBuffer);
} catch (IOException e) {
LOGGER.warn("Failed to register accepted connection to selector!", e);
if (clientKey != null) {
cleanupSelectionKey(clientKey);
}
accepted.close();
}
}
示例4: test_AsyncClient
import org.apache.thrift.transport.TNonblockingTransport; //导入方法依赖的package包/类
@Test
public void test_AsyncClient() throws Throwable {
Random rnd = new Random(System.nanoTime());
TProtocolFactory[] protfacs = new TProtocolFactory[] { new TCompactProtocol.Factory(),
new TBinaryProtocol.Factory(), new TJSONProtocol.Factory(),
new TSimpleJSONProtocol.Factory(TCalculator.Iface.class, false) };
TProtocolFactory protocolFactory = protfacs[rnd.nextInt(protfacs.length)];
System.out.println("protocolFactory: " + protocolFactory);
TAsyncClientManager clientManager = new TAsyncClientManager();
TNonblockingTransport transport = new TNonblockingSocket(HOST, PORT);
TCalculator.AsyncClient client = new TCalculator.AsyncClient(protocolFactory, clientManager, transport);
final int num1 = rnd.nextInt(Integer.MAX_VALUE / 2 - 1);
final int num2 = rnd.nextInt(Integer.MAX_VALUE / 2 - 1);
final CountDownLatch latch = new CountDownLatch(1);
final Throwable[] exceptions = new Throwable[1];
AsyncMethodCallback<TCalculator.AsyncClient.add_call> resultHandler = new AsyncMethodCallback<TCalculator.AsyncClient.add_call>() {
@Override
public void onComplete(TCalculator.AsyncClient.add_call response) {
System.out.println("onComplete!");
try {
int result = response.getResult();
Assert.assertEquals(num1 + num2, result);
} catch (Throwable e) {
exceptions[0] = e;
} finally {
latch.countDown();
}
}
@Override
public void onError(Exception exception) {
System.err.println("onError!");
exception.printStackTrace();
latch.countDown();
}
};
client.add(num1, num2, resultHandler);
latch.await();
transport.close();
if (exceptions[0] != null) {
throw exceptions[0];
}
}
示例5: doAddAccept
import org.apache.thrift.transport.TNonblockingTransport; //导入方法依赖的package包/类
private void doAddAccept(SelectorThread thread, TNonblockingTransport client) {
if (!thread.addAcceptedConnection(client)) {
client.close();
}
}