@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(); }
@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); }
@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; }