当前位置: 首页>>代码示例>>Java>>正文


Java TNonblockingTransport类代码示例

本文整理汇总了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;
}
 
开发者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


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