本文整理汇总了Java中org.apache.thrift.transport.TNonblockingTransport类的典型用法代码示例。如果您正苦于以下问题:Java TNonblockingTransport类的具体用法?Java TNonblockingTransport怎么用?Java TNonblockingTransport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TNonblockingTransport类属于org.apache.thrift.transport包,在下文中一共展示了TNonblockingTransport类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClientConstructor
import org.apache.thrift.transport.TNonblockingTransport; //导入依赖的package包/类
public static Constructor<?> getClientConstructor(Class<?> svcInterface) {
String client = svcInterface.getName().indexOf("Async") > 0 ? ASYNC_CLIENT_NAME : CLIENT_NAME;
Class<?>[] args = svcInterface.getName().indexOf("Async") > 0 ? new Class[]{TProtocolFactory.class, TAsyncClientManager.class, TNonblockingTransport.class} : new Class[]{TProtocol.class};
Class<?> clientClass = getThriftServiceInnerClassOrNull(svcInterface.getEnclosingClass(), client, false);
if (clientClass == null) {
throw new ThriftRuntimeException("the client class is null");
}
Constructor<?> constructor = ClassUtils.getConstructorIfAvailable(clientClass, args);
if (constructor == null) {
throw new ThriftRuntimeException("the clientClass constructor is null");
}
return constructor;
}
示例2: createFrameBuffer
import org.apache.thrift.transport.TNonblockingTransport; //导入依赖的package包/类
@Override
protected FrameBuffer createFrameBuffer(TNonblockingTransport trans, SelectionKey selectionKey,
AbstractSelectThread selectThread) {
TrackingFrameBuffer frameBuffer = new TrackingFrameBuffer(trans, selectionKey, selectThread);
if (trans instanceof TNonblockingSocket) {
try {
SocketChannel socketChannel = ((TNonblockingSocket) trans).getSocketChannel();
InetAddress addr = ((InetSocketAddress) socketChannel.getRemoteAddress()).getAddress();
clientAddresses.put(frameBuffer.getInputFramedTransport(), addr);
} catch (IOException e) {
log.warn("Exception while tracking client address", e);
clientAddresses.remove(frameBuffer.getInputFramedTransport());
}
} else {
log.warn("Unknown TNonblockingTransport instance: {}", trans.getClass().getName());
clientAddresses.remove(frameBuffer.getInputFramedTransport());
}
return frameBuffer;
}
示例3: getClient
import org.apache.thrift.transport.TNonblockingTransport; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <X extends TAsyncClient> X getClient(final Class<X> clazz) {
return (X) super.clients.computeIfAbsent(ClassNameUtils.getOuterClassName(clazz), (className) -> {
TProtocolFactory protocolFactory = (TProtocolFactory) tTransport -> {
TProtocol protocol = new TBinaryProtocol(tTransport);
return new TMultiplexedProtocol(protocol, className);
};
try {
return clazz.getConstructor(TProtocolFactory.class, TAsyncClientManager.class, TNonblockingTransport.class)
.newInstance(protocolFactory, this.clientManager, this.transport);
} catch (Throwable e) {
if (e instanceof UnresolvedAddressException) {
this.isOpen = false;
}
return null;
}
});
}
示例4: 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();
}
}
}
}
示例5: addAcceptedConnection
import org.apache.thrift.transport.TNonblockingTransport; //导入依赖的package包/类
/**
* Hands off an accepted connection to be handled by this thread. This
* method will block if the queue for new connections is at capacity.
*
* @param accepted
* The connection that has been accepted.
* @return true if the connection has been successfully added.
*/
public boolean addAcceptedConnection(TNonblockingTransport accepted) {
try {
while (!acceptedQueue.offer(accepted, 200, TimeUnit.MILLISECONDS)) {
// If server is stopped, then return false.
if (stopped_) {
return false;
}
}
} catch (InterruptedException e) {
LOGGER.warn("Interrupted while adding accepted connection!", e);
return false;
}
selector.wakeup();
return true;
}
示例6: getClientConstructor
import org.apache.thrift.transport.TNonblockingTransport; //导入依赖的package包/类
public static Constructor<?> getClientConstructor(Class<?> svcInterface) {
String client = svcInterface.getName().indexOf("Async") > 0 ? ASYNC_CLIENT_NAME : CLIENT_NAME;
Class<?>[] args = svcInterface.getName().indexOf("Async") > 0 ? new Class[]{TProtocolFactory.class, TAsyncClientManager.class, TNonblockingTransport.class} : new Class[]{TProtocol.class};
Class<?> clientClass = getThriftServiceInnerClassOrNull(svcInterface.getEnclosingClass(), client, false);
if (clientClass == null) {
throw new ThriftRuntimeException("the client class is null");
}
Constructor<?> constructor = ClassUtils.getConstructorIfAvailable(clientClass, args);
if (constructor == null) {
throw new ThriftRuntimeException("the clientClass constructor is null");
}
return constructor;
}
示例7: FrameBuffer
import org.apache.thrift.transport.TNonblockingTransport; //导入依赖的package包/类
public FrameBuffer(final TNonblockingTransport trans,
final SelectionKey selectionKey,
final AbstractSelectThread selectThread) {
trans_ = trans;
selectionKey_ = selectionKey;
selectThread_ = selectThread;
buffer_ = ByteBuffer.allocate(4);
frameTrans_ = new TMemoryInputTransport();
response_ = new TByteArrayOutputStream();
inTrans_ = inputTransportFactory_.getTransport(frameTrans_);
outTrans_ = outputTransportFactory_.getTransport(new TIOStreamTransport(response_));
inProt_ = inputProtocolFactory_.getProtocol(inTrans_);
outProt_ = outputProtocolFactory_.getProtocol(outTrans_);
if (eventHandler_ != null) {
context_ = eventHandler_.createContext(inProt_, outProt_);
} else {
context_ = null;
}
}
示例8: 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();
}
}
示例9: processKey
import org.apache.thrift.transport.TNonblockingTransport; //导入依赖的package包/类
@Override
protected void processKey(SelectionKey key) throws IOException
{
if (!key.isAcceptable())
return;
try
{
// accept the connection
SelectorThread selector = selectorLoadBalancer.nextSelector();
selector.subscribe((TNonblockingTransport) serverTransport.accept());
selector.wakeupSelector();
}
catch (TTransportException tte)
{
// accept() shouldn't be NULL if fine because are are raising for a socket
logger.debug("Non-fatal exception trying to accept!", tte);
}
}
示例10: getAsyncService
import org.apache.thrift.transport.TNonblockingTransport; //导入依赖的package包/类
/**
* 获取客户端AsyncService对象
*/
@Override
public AsyncService getAsyncService(TNonblockingTransport transport, String serviceName) throws STException {
if (transport == null)
throw new STException("'transport' is null !");
try {
return StringUtil.isEmpty(serviceName)
? new AsyncServiceClientImpl((TProtocolFactory) new TCompactProtocol.Factory(), transport)
: new AsyncServiceClientImpl(new AsyncMultiplexedProtocolFactory(serviceName), transport);
} catch (IOException e) {
throw new STException(e);
}
}
示例11: makeObject
import org.apache.thrift.transport.TNonblockingTransport; //导入依赖的package包/类
@Override
public T makeObject(InetSocketAddress socket) throws Exception {
TNonblockingTransport nbTr = new TNonblockingSocket(
socket.getAddress().getHostAddress(), socket.getPort());
TProtocolFactory factory = new TBinaryProtocol.Factory();
T client = maker.create(nbTr, clientManager, factory);
transports.put(client, nbTr);
return client;
}
示例12: createDefaultAcceptQueue
import org.apache.thrift.transport.TNonblockingTransport; //导入依赖的package包/类
private static BlockingQueue<TNonblockingTransport> createDefaultAcceptQueue(int queueSize) {
if (queueSize == 0) {
// Unbounded queue
return new LinkedBlockingQueue<TNonblockingTransport>();
}
return new ArrayBlockingQueue<TNonblockingTransport>(queueSize);
}
示例13: doAccept
import org.apache.thrift.transport.TNonblockingTransport; //导入依赖的package包/类
private TNonblockingTransport doAccept() {
try {
return (TNonblockingTransport) serverTransport.accept();
} catch (TTransportException tte) {
// something went wrong accepting.
LOGGER.warn("Exception trying to accept!", tte);
return null;
}
}
示例14: processAcceptedConnections
import org.apache.thrift.transport.TNonblockingTransport; //导入依赖的package包/类
private void processAcceptedConnections() {
// Register accepted connections
while (!stopped_) {
TNonblockingTransport accepted = acceptedQueue.poll();
if (accepted == null) {
break;
}
registerAccepted(accepted);
}
}
示例15: 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();
}
}