Java 类org.apache.thrift.protocol.TMultiplexedProtocol 实例源码

项目:athena    文件:Bmv2ControllerImpl.java   
@Override
public Pair<TTransport, Bmv2DeviceThriftClient> load(DeviceId deviceId)
        throws TTransportException {
    log.debug("Instantiating new client... > deviceId={}", deviceId);
    // Make the expensive call
    Bmv2Device device = Bmv2Device.of(deviceId);
    TTransport transport = new TSocket(device.thriftServerHost(), device.thriftServerPort());
    TProtocol protocol = new TBinaryProtocol(transport);
    // Our BMv2 device implements multiple Thrift services, create a client for each one on the same transport.
    Standard.Client standardClient = new Standard.Client(
            new TMultiplexedProtocol(protocol, "standard"));
    SimpleSwitch.Client simpleSwitch = new SimpleSwitch.Client(
            new TMultiplexedProtocol(protocol, "simple_switch"));
    // Wrap clients so to automatically have synchronization and resiliency to connectivity errors
    Standard.Iface safeStandardClient = SafeThriftClient.wrap(standardClient,
                                                              Standard.Iface.class,
                                                              options);
    SimpleSwitch.Iface safeSimpleSwitchClient = SafeThriftClient.wrap(simpleSwitch,
                                                                      SimpleSwitch.Iface.class,
                                                                      options);
    Bmv2DeviceThriftClient client = new Bmv2DeviceThriftClient(deviceId,
                                                               transport,
                                                               safeStandardClient,
                                                               safeSimpleSwitchClient);
    return Pair.of(transport, client);
}
项目:albedo-thrift    文件:ThriftClientPoolFactory.java   
@Override
    public TServiceClient makeObject() throws Exception {
        TSocket tsocket = new TSocket(server.getHost(), server.getPort());
        tsocket.open();
//        TTransport transport = new TFramedTransport(tsocket);
        TJSONProtocol protocol = new TJSONProtocol(tsocket);
        TMultiplexedProtocol uProtocol=new TMultiplexedProtocol(protocol, proccessName);
        TServiceClient client = this.clientFactory.getClient(uProtocol);
        if (callback != null) {
            try {
                callback.make(client);
            } catch (Exception e) {
                logger.warn("makeObject:{}", e);
            }
        }
        return client;
    }
项目:trpc    文件:AsyncTrpcClient.java   
@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;
        }
    });
}
项目:nebo    文件:NeboTestCase.java   
@Test
public void thriftTest() throws TException {
    TSocket transport = new TSocket("127.0.0.1", 8080);
    transport.open();
    TProtocol protocol = new TBinaryProtocol(transport);
    TMultiplexedProtocol mp1 = new TMultiplexedProtocol(protocol,"helloWorld");
    HelloWorld.Client client = new HelloWorld.Client(mp1);
    User user = new User();
    user.setName("{\"proid\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}");
    user.setId(234242453);
    user.setIsman(true);
    Result result = client.createNewBaseResInfo(user);
    Assert.notNull(result);
    System.out.println(result.getMsg());
    System.out.println("end>>>>>>>>>>>>>>>>");

}
项目:ThriftBook    文件:MultiServiceClient.java   
public static void main(String[] args) throws TException {
    TTransport trans = new TFramedTransport(new TSocket("localhost", 9090));
    TProtocol proto = new TJSONProtocol(trans);

    TMultiplexedProtocol proto_msg = new TMultiplexedProtocol(proto, "Message");
    Message.Client client_msg = new Message.Client(proto_msg);
    TMultiplexedProtocol proto_time = new TMultiplexedProtocol(proto, "ServerTime");
    ServerTime.Client client_time = new ServerTime.Client(proto_time);

    trans.open();
    String line;
    do {
        System.out.println("Message from server: " + client_msg.motd());
        System.out.println("Time at server: " + client_time.time_at_server((short)-1));
        System.out.println("Enter to continue, 'q' to quit: ");
        line = System.console().readLine();
    } while (0 != line.compareToIgnoreCase("q"));   
}
项目:kaa    文件:ThriftClient.java   
/**
 * The Constructor.
 *
 * @param endpointHost     the endpoint host
 * @param endpointPort     the endpoint port
 * @param kaaThriftService the kaa thrift service
 * @param clazz            the clazz
 * @throws NoSuchMethodException     the no such method exception
 * @throws SecurityException         the security exception
 * @throws InstantiationException    the instantiation exception
 * @throws IllegalAccessException    the illegal access exception
 * @throws IllegalArgumentException  the illegal argument exception
 * @throws InvocationTargetException the invocation target exception
 */
public ThriftClient(String endpointHost, int endpointPort, KaaThriftService kaaThriftService,
                    Class<T> clazz)
    throws NoSuchMethodException,
    InstantiationException,
    IllegalAccessException,
    InvocationTargetException {
  this.classT = clazz;
  this.endpointHost = endpointHost;
  this.endpointPort = endpointPort;
  constructorT = classT.getConstructor(TProtocol.class, TProtocol.class);
  transport = new TSocket(endpointHost, endpointPort);
  LOG.debug("ThriftClient sokcet to " + endpointHost + ":" + endpointPort + " created.");
  TProtocol protocol = new TBinaryProtocol(transport);
  TMultiplexedProtocol mp = new TMultiplexedProtocol(protocol, kaaThriftService.getServiceName());
  client = constructorT.newInstance(mp, mp);
  LOG.debug("ThriftClient new Client to " + endpointHost + ":" + endpointPort + " created.");
}
项目:algorithm.annotation    文件:AlgorithmClient.java   
private Client newClient() throws TException{
    transport = new TSocket("localhost", PORT);
    transport.open();
    TMultiplexedProtocol protocol = new TMultiplexedProtocol(
            new TBinaryProtocol(transport), "Algorithm");
    return new Client(protocol);
}
项目:trpc    文件:BlockTrpcClient.java   
@Override
@SuppressWarnings("unchecked")
public <C extends TServiceClient> C getClient(final Class<C> clazz) {
    return (C) super.clients.computeIfAbsent(ClassNameUtils.getOuterClassName(clazz), className -> {
        TMultiplexedProtocol tmp = new TMultiplexedProtocol(this.protocol, className);
        try {
            return clazz.getConstructor(TProtocol.class).newInstance(tmp);
        } catch (Exception e) {
            log.error("never execute");
            return null;
        }
    });
}
项目:ikasoa    文件:AbstractThriftClientImpl.java   
@Override
public TProtocol getProtocol(TTransport transport, String serviceName) {
    if (serviceName != null)
        return new TMultiplexedProtocol(getProtocol(transport), serviceName);
    else
        return getProtocol(transport);
}
项目:nifty-spring-boot-starter    文件:SampleClient.java   
public static void main(final String[] args) throws Exception {
  TSocket transport = new TSocket("localhost", 8000);
  transport.open();
  TBinaryProtocol protocol = new TBinaryProtocol(transport);
  TMultiplexedProtocol mp = new TMultiplexedProtocol(protocol, "greeterService");
  Greeter.Client client = new Greeter.Client(mp);
  HelloRequest req = new HelloRequest("world");
  HelloReply rep = client.sayHello(req);
  System.out.println("Message: " + rep.message);
}
项目:nifty-spring-boot-starter    文件:GreeterServiceTest.java   
@Before
public void setUp() throws Exception {
  TSocket transport = new TSocket("localhost", port);
  transport.open();
  TMultiplexedProtocol mp =
      new TMultiplexedProtocol(new TBinaryProtocol(transport), "Greeter");
  client = new Greeter.Client(mp);
}
项目:allocateme    文件:UserProfileClientFactory.java   
public static UserProfileService.Client userProfileClient(String serverHost, int serverPort) throws Exception{
    try {
        TTransport transport = new TSocket(serverHost, serverPort);
        transport.open();
        TProtocol protocol = new TBinaryProtocol(transport);
        TMultiplexedProtocol multiplexedProtocol = new TMultiplexedProtocol(protocol, "UserProfileService");
        return new UserProfileService.Client(multiplexedProtocol);
    } catch (TTransportException e) {
        e.printStackTrace();
        throw new Exception("Could not connect to user profile server");
    }
}
项目:Thrift-Connection-Pool    文件:MulitServiceThriftConnecion.java   
/**
 * 创建原始连接的方法
 * 
 * @throws ThriftConnectionPoolException
 *             创建连接出现问题时抛出该异常
 */
@SuppressWarnings("unchecked")
private void createConnection() throws ThriftConnectionPoolException {
    try {
        transport = new TSocket(host, port, connectionTimeOut);
        transport.open();
        TProtocol protocol = createTProtocol(transport);

        Iterator<Entry<String, Class<? extends TServiceClient>>> iterator = thriftClientClasses.entrySet()
                .iterator();
        while (iterator.hasNext()) {
            Entry<String, Class<? extends TServiceClient>> entry = iterator.next();
            String serviceName = entry.getKey();
            Class<? extends TServiceClient> clientClass = entry.getValue();
            TMultiplexedProtocol multiProtocol = new TMultiplexedProtocol(protocol, serviceName);
            // 反射实例化客户端对象
            Constructor<? extends TServiceClient> clientConstructor = clientClass.getConstructor(TProtocol.class);
            T client = (T) clientConstructor.newInstance(multiProtocol);
            clients.put(serviceName, client);
            if (logger.isDebugEnabled()) {
                logger.debug("创建新连接成功:" + host + " 端口:" + port);
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
        throw new ThriftConnectionPoolException("无法连接服务器:" + host + " 端口:" + port, e);
    }
}
项目:spring-thrift-integration    文件:Client.java   
public static void main(String[] args) throws Exception {

        THttpClient transport = new THttpClient("http://localhost:8080/api");
        transport.open();
        TProtocol protocol = new TBinaryProtocol(transport);
        PingPongService.Client client = new PingPongService.Client(new TMultiplexedProtocol(protocol, "PingPongService"));

        Ping ping = new Ping();
        ping.setMessage("Hello");
        Pong pong = client.knock(ping);

        LoggerFactory.getLogger(Client.class).info("Got answer: "+pong.getAnswer());
    }
项目:kaa    文件:NeighborConnection.java   
/**
 * Start neighbor connection if it not started yet.
 */
public synchronized void start() {
  if (!started) {
    executor = Executors.newFixedThreadPool(maxNumberConnection);
    messageQueue = new LinkedBlockingQueue<>(messageQueueLength);
    workers = new LinkedList<>();
    clientFactory = ThriftFactory.create(OperationsThriftService.Iface.class);
    InetSocketAddress address = new InetSocketAddress(
        connectionInfo.getThriftHost().toString(), connectionInfo.getThriftPort()
    );
    Set<InetSocketAddress> backends = new HashSet<>();
    backends.add(address);
    thrift = clientFactory.withMaxConnectionsPerEndpoint(maxNumberConnection)
        .withSocketTimeout(Amount.of(socketTimeout, Time.SECONDS))
        .withClientFactory(new Function<TTransport, OperationsThriftService.Iface>() {
              @Override
              public Iface apply(TTransport transport) {
                TProtocol protocol = new TBinaryProtocol(transport);
                TMultiplexedProtocol mprotocol = new TMultiplexedProtocol(
                    protocol, KaaThriftService.OPERATIONS_SERVICE.getServiceName()
                );
                return new OperationsThriftService.Client(mprotocol);
              }
            }).build(backends);
    for (int i = 0; i < maxNumberConnection; i++) {
      EventWorker worker = new EventWorker(template);
      workers.add(executor.submit(worker));
    }
    started = true;
  } else {
    LOG.debug("Neighbor Connection {} is already started", getId());
  }
}
项目:kaa    文件:CliSessionState.java   
/**
 * Connect to Thrift Server.
 *
 * @throws TException the t exception
 */
public void connect() throws TException {
  transport = new TSocket(host, port);
  TProtocol protocol = new TBinaryProtocol(transport);
  TMultiplexedProtocol mp = new TMultiplexedProtocol(protocol,
          KaaThriftService.KAA_NODE_SERVICE.getServiceName());
  client = new CliClient(mp);
  transport.open();
  remoteServerName = client.serverName();
  remoteMode = true;
}
项目:spring-thrift-service-manager    文件:ServiceThreadPoolWrapper.java   
public TProtocol getClientProtocol(String serviceInterfaceClassName, String host, Integer port) throws TTransportException {
    TSocket localhostSocket = new TSocket(host, port);
    localhostSocket.open();
    TProtocol protocol = new TBinaryProtocol(new TFramedTransport(localhostSocket));

    return new TMultiplexedProtocol(protocol, serviceInterfaceClassName);
}
项目:spring-thrift-service-manager    文件:SecuredThreadPoolWrapper.java   
@Override
public TProtocol getClientProtocol(String serviceInterfaceClassName, String host, Integer port) throws TTransportException {
    if(truststoreFile == null || truststorePass == null){
        throw new IllegalStateException("truststore not defined. Initialize the Factory properly");
    }

    TSSLTransportFactory.TSSLTransportParameters paramsClient = new TSSLTransportFactory.TSSLTransportParameters();
    paramsClient.setTrustStore(truststoreFile, truststorePass);
    TTransport transport = TSSLTransportFactory.getClientSocket(host, port, 1000, paramsClient);
    TProtocol protocol = new TBinaryProtocol(transport);

    return new TMultiplexedProtocol(protocol, serviceInterfaceClassName);
}
项目:airavata    文件:ProfileServiceClientFactory.java   
public static UserProfileService.Client createUserProfileServiceClient(String serverHost, int serverPort)  throws UserProfileServiceException {
    try {
        TTransport transport = new TSocket(serverHost, serverPort);
        transport.open();
        TProtocol protocol = new TBinaryProtocol(transport);
        TMultiplexedProtocol multiplexedProtocol = new TMultiplexedProtocol(protocol, profile_user_cpiConstants.USER_PROFILE_CPI_NAME);
        return new UserProfileService.Client(multiplexedProtocol);
    } catch (TTransportException e) {
        throw new UserProfileServiceException(e.getMessage());
    }
}
项目:airavata    文件:ProfileServiceClientFactory.java   
public static TenantProfileService.Client createTenantProfileServiceClient(String serverHost, int serverPort) throws TenantProfileServiceException {
    try {
        TTransport transport = new TSocket(serverHost, serverPort);
        transport.open();
        TProtocol protocol = new TBinaryProtocol(transport);
        TMultiplexedProtocol multiplexedProtocol = new TMultiplexedProtocol(protocol, profile_tenant_cpiConstants.TENANT_PROFILE_CPI_NAME);
        return new TenantProfileService.Client(multiplexedProtocol);
    } catch (TTransportException e) {
        throw new TenantProfileServiceException(e.getMessage());
    }
}
项目:airavata    文件:ProfileServiceClientFactory.java   
public static IamAdminServices.Client createIamAdminServiceClient(String serverHost, int serverPort) throws IamAdminServicesException {
    try {
        TTransport transport = new TSocket(serverHost, serverPort);
        transport.open();
        TProtocol protocol = new TBinaryProtocol(transport);
        TMultiplexedProtocol multiplexedProtocol = new TMultiplexedProtocol(protocol, iam_admin_services_cpiConstants.IAM_ADMIN_SERVICES_CPI_NAME);
        return new IamAdminServices.Client(multiplexedProtocol);
    } catch (TTransportException e) {
        throw new IamAdminServicesException(e.getMessage());
    }
}
项目:ikasoa    文件:AsyncMultiplexedProtocolFactory.java   
@Override
public TProtocol getProtocol(TTransport trans) {
    return StringUtil.isNotEmpty(serviceName) ? new TMultiplexedProtocol(super.getProtocol(trans), serviceName)
            : super.getProtocol(trans);
}
项目:diqube    文件:JsonRequest.java   
@PostConstruct
public void initialize() {
  commandClusterInteraction = new AbstractCommandClusterInteraction(config, ticket) {
    @Override
    protected void registerQueryThriftResultCallback(Pair<String, Short> node, UUID queryUuid, Iface resultHandler) {
      queryResultRegistry.registerThriftResultCallback(session, requestId, node, queryUuid, resultHandler);

      cleanupActions.add(() -> queryResultRegistry.unregisterQuery(requestId, queryUuid));
    }

    @Override
    protected Pair<UUID, Pair<String, Short>> findQueryUuidAndServerAddr() {
      UUID queryUuid = queryResultRegistry.getQueryUuid(session, requestId);
      Pair<String, Short> node = queryResultRegistry.getDiqubeServerAddr(queryUuid);

      if (queryUuid == null || node == null)
        return null;
      return new Pair<>(queryUuid, node);
    }

    @Override
    protected <T extends TServiceClient> T openConnection(Class<? extends T> thriftClientClass, String serviceName,
        Pair<String, Short> node) {
      TTransport transport = new TFramedTransport(new TSocket(node.getLeft(), node.getRight()));
      TProtocol protocol = new TMultiplexedProtocol(new TCompactProtocol(transport), serviceName);

      T res;
      try {
        res = thriftClientClass.getConstructor(TProtocol.class).newInstance(protocol);
      } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
          | NoSuchMethodException | SecurityException e) {
        throw new RuntimeException("Could not instantiate thrift client", e);
      }

      try {
        transport.open();
      } catch (TTransportException e) {
        return null;
      }

      cleanupActions.add(() -> transport.close());

      return res;
    }
  };
}
项目:NettyThrift    文件:JavaClient.java   
public static void main(String[] args) {

        try {

            TSocket transport = new TSocket("localhost", 9090);
            transport.open();

            TBinaryProtocol protocol = new TBinaryProtocol(transport);

            TMultiplexedProtocol mp = new TMultiplexedProtocol(protocol, "Calculator");
            Calculator.Client client = new Calculator.Client(mp);

            TMultiplexedProtocol mp2 = new TMultiplexedProtocol(protocol, "Scribe");
            scribe.Client client2 = new scribe.Client(mp2);

            testCalculator(client);

            testScribe(client2);

            transport.close();
        } catch (TException x) {
            x.printStackTrace();
        }
    }
项目:thrift-client-pool-java    文件:ThriftMultiplexedBinaryProtocolFactory.java   
@Override
public TProtocol makeProtocol(TTransport transport) {
    return new TMultiplexedProtocol(new TBinaryProtocol(new TFramedTransport(transport)), serviceName);
}
项目:incubator-sentry    文件:SentryGenericServiceClientDefaultImpl.java   
public SentryGenericServiceClientDefaultImpl(Configuration conf) throws IOException {
  // copy the configuration because we may make modifications to it.
  this.conf = new Configuration(conf);
  Preconditions.checkNotNull(this.conf, "Configuration object cannot be null");
  this.serverAddress = NetUtils.createSocketAddr(Preconditions.checkNotNull(
                         conf.get(ClientConfig.SERVER_RPC_ADDRESS), "Config key "
                         + ClientConfig.SERVER_RPC_ADDRESS + " is required"), conf.getInt(
                         ClientConfig.SERVER_RPC_PORT, ClientConfig.SERVER_RPC_PORT_DEFAULT));
  this.connectionTimeout = conf.getInt(ClientConfig.SERVER_RPC_CONN_TIMEOUT,
                                       ClientConfig.SERVER_RPC_CONN_TIMEOUT_DEFAULT);
  kerberos = ServerConfig.SECURITY_MODE_KERBEROS.equalsIgnoreCase(
      conf.get(ServerConfig.SECURITY_MODE, ServerConfig.SECURITY_MODE_KERBEROS).trim());
  transport = new TSocket(serverAddress.getHostName(),
      serverAddress.getPort(), connectionTimeout);
  if (kerberos) {
    String serverPrincipal = Preconditions.checkNotNull(conf.get(ServerConfig.PRINCIPAL), ServerConfig.PRINCIPAL + " is required");
    // since the client uses hadoop-auth, we need to set kerberos in
    // hadoop-auth if we plan to use kerberos
    conf.set(HADOOP_SECURITY_AUTHENTICATION, ServerConfig.SECURITY_MODE_KERBEROS);

    // Resolve server host in the same way as we are doing on server side
    serverPrincipal = SecurityUtil.getServerPrincipal(serverPrincipal, serverAddress.getAddress());
    LOGGER.debug("Using server kerberos principal: " + serverPrincipal);

    serverPrincipalParts = SaslRpcServer.splitKerberosName(serverPrincipal);
    Preconditions.checkArgument(serverPrincipalParts.length == 3,
         "Kerberos principal should have 3 parts: " + serverPrincipal);
    boolean wrapUgi = "true".equalsIgnoreCase(conf
        .get(ServerConfig.SECURITY_USE_UGI_TRANSPORT, "true"));
    transport = new UgiSaslClientTransport(AuthMethod.KERBEROS.getMechanismName(),
        null, serverPrincipalParts[0], serverPrincipalParts[1],
        ClientConfig.SASL_PROPERTIES, null, transport, wrapUgi, conf);
  } else {
    serverPrincipalParts = null;
  }
  try {
    transport.open();
  } catch (TTransportException e) {
    throw new IOException("Transport exception while opening transport: " + e.getMessage(), e);
  }
  LOGGER.debug("Successfully opened transport: " + transport + " to " + serverAddress);
  long maxMessageSize = conf.getLong(ServiceConstants.ClientConfig.SENTRY_POLICY_CLIENT_THRIFT_MAX_MESSAGE_SIZE,
      ServiceConstants.ClientConfig.SENTRY_POLICY_CLIENT_THRIFT_MAX_MESSAGE_SIZE_DEFAULT);
  TMultiplexedProtocol protocol = new TMultiplexedProtocol(
      new TBinaryProtocol(transport, maxMessageSize, maxMessageSize, true, true),
      SentryGenericPolicyProcessor.SENTRY_GENERIC_SERVICE_NAME);
  client = new SentryGenericPolicyService.Client(protocol);
  LOGGER.debug("Successfully created client");
}
项目:incubator-sentry    文件:SentryPolicyServiceClientDefaultImpl.java   
public SentryPolicyServiceClientDefaultImpl(Configuration conf) throws IOException {
  this.conf = conf;
  Preconditions.checkNotNull(this.conf, "Configuration object cannot be null");
  this.serverAddress = NetUtils.createSocketAddr(Preconditions.checkNotNull(
                         conf.get(ClientConfig.SERVER_RPC_ADDRESS), "Config key "
                         + ClientConfig.SERVER_RPC_ADDRESS + " is required"), conf.getInt(
                         ClientConfig.SERVER_RPC_PORT, ClientConfig.SERVER_RPC_PORT_DEFAULT));
  this.connectionTimeout = conf.getInt(ClientConfig.SERVER_RPC_CONN_TIMEOUT,
                                       ClientConfig.SERVER_RPC_CONN_TIMEOUT_DEFAULT);
  kerberos = ServerConfig.SECURITY_MODE_KERBEROS.equalsIgnoreCase(
      conf.get(ServerConfig.SECURITY_MODE, ServerConfig.SECURITY_MODE_KERBEROS).trim());
  transport = new TSocket(serverAddress.getHostName(),
      serverAddress.getPort(), connectionTimeout);
  if (kerberos) {
    String serverPrincipal = Preconditions.checkNotNull(conf.get(ServerConfig.PRINCIPAL), ServerConfig.PRINCIPAL + " is required");

    // Resolve server host in the same way as we are doing on server side
    serverPrincipal = SecurityUtil.getServerPrincipal(serverPrincipal, serverAddress.getAddress());
    LOGGER.debug("Using server kerberos principal: " + serverPrincipal);

    serverPrincipalParts = SaslRpcServer.splitKerberosName(serverPrincipal);
    Preconditions.checkArgument(serverPrincipalParts.length == 3,
         "Kerberos principal should have 3 parts: " + serverPrincipal);
    boolean wrapUgi = "true".equalsIgnoreCase(conf
        .get(ServerConfig.SECURITY_USE_UGI_TRANSPORT, "true"));
    transport = new UgiSaslClientTransport(AuthMethod.KERBEROS.getMechanismName(),
        null, serverPrincipalParts[0], serverPrincipalParts[1],
        ClientConfig.SASL_PROPERTIES, null, transport, wrapUgi);
  } else {
    serverPrincipalParts = null;
  }
  try {
    transport.open();
  } catch (TTransportException e) {
    throw new IOException("Transport exception while opening transport: " + e.getMessage(), e);
  }
  LOGGER.debug("Successfully opened transport: " + transport + " to " + serverAddress);
  long maxMessageSize = conf.getLong(ServiceConstants.ClientConfig.SENTRY_POLICY_CLIENT_THRIFT_MAX_MESSAGE_SIZE,
      ServiceConstants.ClientConfig.SENTRY_POLICY_CLIENT_THRIFT_MAX_MESSAGE_SIZE_DEFAULT);
  TMultiplexedProtocol protocol = new TMultiplexedProtocol(
      new TBinaryProtocol(transport, maxMessageSize, maxMessageSize, true, true),
      SentryPolicyStoreProcessor.SENTRY_POLICY_SERVICE_NAME);
  client = new SentryPolicyService.Client(protocol);
  LOGGER.debug("Successfully created client");
}
项目:thrift-pool-client    文件:ThriftClientImpl.java   
/**
 * {@inheritDoc}
 *
 * <p>
 * mpiface.
 * </p>
 */
@Override
public <X extends TServiceClient> X mpiface(Class<X> ifaceClass, String serviceName,
    Function<TTransport, TProtocol> protocolProvider, int hash) {
    return iface(ifaceClass,
        protocolProvider.andThen((p) -> new TMultiplexedProtocol(p, serviceName)), hash);
}