• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TNonblockingTransport类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.thrift.transport.TNonblockingTransport的典型用法代码示例。如果您正苦于以下问题:Java TNonblockingTransport类的具体用法?Java TNonblockingTransport怎么用?Java TNonblockingTransport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TNonblockingTransport类属于org.apache.thrift.transport包,在下文中一共展示了TNonblockingTransport类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
 
开发者ID:funtl,项目名称:framework,代码行数:17,代码来源:ThriftUtil.java


示例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;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:20,代码来源:Bmv2ControlPlaneThriftServer.java


示例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;
        }
    });
}
 
开发者ID:sofn,项目名称:trpc,代码行数:20,代码来源:AsyncTrpcClient.java


示例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();
      }
    }
  }
}
 
开发者ID:apache,项目名称:incubator-tephra,代码行数:28,代码来源:TThreadedSelectorServerWithFix.java


示例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;
}
 
开发者ID:apache,项目名称:incubator-tephra,代码行数:24,代码来源:TThreadedSelectorServerWithFix.java


示例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;
}
 
开发者ID:superhj1987,项目名称:spring-remoting-thrift,代码行数:17,代码来源:ThriftUtil.java


示例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;
  }
}
 
开发者ID:adityayadav76,项目名称:internet_of_things_simulator,代码行数:22,代码来源:AbstractNonblockingServer.java


示例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();
  }
}
 
开发者ID:adityayadav76,项目名称:internet_of_things_simulator,代码行数:17,代码来源:TThreadedSelectorServer.java


示例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);
    }
}
 
开发者ID:54chen,项目名称:disruptor_thrift_server,代码行数:20,代码来源:TDisruptorServer.java


示例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);
	}
}
 
开发者ID:venwyhk,项目名称:ikasoa,代码行数:16,代码来源:GeneralFactory.java


示例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;
}
 
开发者ID:epfl-labos,项目名称:eagle,代码行数:10,代码来源:ThriftClientPool.java


示例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);
}
 
开发者ID:apache,项目名称:incubator-tephra,代码行数:8,代码来源:TThreadedSelectorServerWithFix.java


示例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;
  }
}
 
开发者ID:apache,项目名称:incubator-tephra,代码行数:10,代码来源:TThreadedSelectorServerWithFix.java


示例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);
  }
}
 
开发者ID:apache,项目名称:incubator-tephra,代码行数:11,代码来源:TThreadedSelectorServerWithFix.java


示例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();
  }
}
 
开发者ID:apache,项目名称:incubator-tephra,代码行数:16,代码来源:TThreadedSelectorServerWithFix.java


示例16: 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 {
    acceptedQueue.put(accepted);
  } catch (InterruptedException e) {
    LOGGER.warn("Interrupted while adding accepted connection!", e);
    return false;
  }
  selector.wakeup();
  return true;
}
 
开发者ID:adityayadav76,项目名称:internet_of_things_simulator,代码行数:19,代码来源:TThreadedSelectorServer.java


示例17: createFrameBuffer

import org.apache.thrift.transport.TNonblockingTransport; //导入依赖的package包/类
protected FrameBuffer createFrameBuffer(final TNonblockingTransport trans,
    final SelectionKey selectionKey,
    final AbstractSelectThread selectThread) {
    return processorFactory_.isAsyncProcessor() ?
              new AsyncFrameBuffer(trans, selectionKey, selectThread) :
              new FrameBuffer(trans, selectionKey, selectThread);
}
 
开发者ID:adityayadav76,项目名称:internet_of_things_simulator,代码行数:8,代码来源:TThreadedSelectorServer.java


示例18: TAsyncMethodCall

import org.apache.thrift.transport.TNonblockingTransport; //导入依赖的package包/类
protected TAsyncMethodCall(TAsyncClient client, TProtocolFactory protocolFactory, TNonblockingTransport transport, AsyncMethodCallback<T> callback, boolean isOneway) {
  this.transport = transport;
  this.callback = callback;
  this.protocolFactory = protocolFactory;
  this.client = client;
  this.isOneway = isOneway;
  this.sequenceId = TAsyncMethodCall.sequenceIdCounter.getAndIncrement();
  this.timeout = client.getTimeout();
}
 
开发者ID:adityayadav76,项目名称:internet_of_things_simulator,代码行数:10,代码来源:TAsyncMethodCall.java


示例19: Message

import org.apache.thrift.transport.TNonblockingTransport; //导入依赖的package包/类
public Message(TNonblockingTransport trans, SelectionKey key, ThriftFactories factories, boolean heapBasedAllocation)
{
    frameSizeBuffer = Buffer.allocate(4, heapBasedAllocation);
    transport = trans;
    selectionKey = key;
    thriftFactories = factories;
    useHeapBasedAllocation = heapBasedAllocation;
}
 
开发者ID:54chen,项目名称:disruptor_thrift_server,代码行数:9,代码来源:Message.java


示例20: selectorIterationComplete

import org.apache.thrift.transport.TNonblockingTransport; //导入依赖的package包/类
@Override
protected void selectorIterationComplete() throws IOException
{
    TNonblockingTransport newClient;

    while ((newClient = newConnections.poll()) != null)
    {
        SelectionKey clientKey = newClient.registerSelector(selector, SelectionKey.OP_READ);
        clientKey.attach(new Message(newClient, clientKey, thriftFactories, useHeapBasedAllocation));
    }
}
 
开发者ID:54chen,项目名称:disruptor_thrift_server,代码行数:12,代码来源:TDisruptorServer.java



注:本文中的org.apache.thrift.transport.TNonblockingTransport类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ValidationParameter类代码示例发布时间:2022-05-21
下一篇:
Java CacheWriter类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap