コード例 #1
0
    @Override
    public T makeObject() throws Exception {
      String thriftClassName = StringUtils.split(serviceNode.getServiceFace(), '$')[0];
      Class<T> clientClazz = (Class<T>) ClassHelper.forName(thriftClassName + "$Client");
      TTransport transport = thriftClient.connectSync(serviceNode.getSocketAddress());

      TMultiplexedProtocol protocol =
          new TMultiplexedProtocol(factory.getProtocol(transport), header);
      Constructor<T> cons = clientClazz.getConstructor(TProtocol.class);
      T client = cons.newInstance(protocol);
      transports.put(client, transport);
      LOG.debug(
          "ServiceNode: {}, finish makeObject client : {}, transport : {}",
          serviceNode.getZnodeName(),
          client,
          transport);
      return client;
    }
コード例 #2
0
 public ThriftClientFactory(ServiceNode serviceNode, TProtocolFactory factory) {
   this.serviceNode = serviceNode;
   this.factory = factory;
   this.header =
       new TMessageHeader()
           .add(THeaderName.USER, ZookeeperConfig.getAclUserString())
           .add(THeaderName.SERVICE, serviceNode.getName())
           .encode();
 }
コード例 #3
0
 @Override
 public boolean validateObject(final T client) {
   TTransport transport = transports.get(client);
   LOG.debug(
       "ServiceNode: {}, trying to validateObject client : {}, transport : {}",
       serviceNode.getZnodeName(),
       client,
       transport);
   return transport != null && transport.isOpen();
 }
コード例 #4
0
 @Override
 public void destroyObject(final T client) throws Exception {
   TTransport transport = transports.get(client);
   if (transport != null && transport.isOpen()) {
     LOG.debug(
         "Closing transport. client : {}, transport : {}, serviceNode :{}",
         client,
         transport,
         serviceNode.getZnodeName());
     transport.close();
   }
   transports.remove(client);
 }
コード例 #5
0
 public ThriftClientPool(final HedwigPoolConfig config, final ServiceNode serviceNode) {
   super(config, new ThriftClientFactory<T>(serviceNode));
   connections = new AtomicInteger(Math.max(0, serviceNode.getConnections()));
   weight = new AtomicInteger(Math.max(1, serviceNode.getWeight()));
 }