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


Java TMultiplexedProtocol类代码示例

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


TMultiplexedProtocol类属于org.apache.thrift.protocol包,在下文中一共展示了TMultiplexedProtocol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: load

import org.apache.thrift.protocol.TMultiplexedProtocol; //导入依赖的package包/类
@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);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:27,代码来源:Bmv2ControllerImpl.java

示例2: makeObject

import org.apache.thrift.protocol.TMultiplexedProtocol; //导入依赖的package包/类
@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;
    }
 
开发者ID:somewhereMrli,项目名称:albedo-thrift,代码行数:18,代码来源:ThriftClientPoolFactory.java

示例3: getClient

import org.apache.thrift.protocol.TMultiplexedProtocol; //导入依赖的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: thriftTest

import org.apache.thrift.protocol.TMultiplexedProtocol; //导入依赖的package包/类
@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\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}");
    user.setId(234242453);
    user.setIsman(true);
    Result result = client.createNewBaseResInfo(user);
    Assert.notNull(result);
    System.out.println(result.getMsg());
    System.out.println("end>>>>>>>>>>>>>>>>");

}
 
开发者ID:paullyphang,项目名称:nebo,代码行数:18,代码来源:NeboTestCase.java

示例5: main

import org.apache.thrift.protocol.TMultiplexedProtocol; //导入依赖的package包/类
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"));   
}
 
开发者ID:RandyAbernethy,项目名称:ThriftBook,代码行数:19,代码来源:MultiServiceClient.java

示例6: ThriftClient

import org.apache.thrift.protocol.TMultiplexedProtocol; //导入依赖的package包/类
/**
 * 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.");
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:32,代码来源:ThriftClient.java

示例7: newClient

import org.apache.thrift.protocol.TMultiplexedProtocol; //导入依赖的package包/类
private Client newClient() throws TException{
	transport = new TSocket("localhost", PORT);
	transport.open();
	TMultiplexedProtocol protocol = new TMultiplexedProtocol(
			new TBinaryProtocol(transport), "Algorithm");
	return new Client(protocol);
}
 
开发者ID:kaichao,项目名称:algorithm.annotation,代码行数:8,代码来源:AlgorithmClient.java

示例8: getClient

import org.apache.thrift.protocol.TMultiplexedProtocol; //导入依赖的package包/类
@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;
        }
    });
}
 
开发者ID:sofn,项目名称:trpc,代码行数:14,代码来源:BlockTrpcClient.java

示例9: getProtocol

import org.apache.thrift.protocol.TMultiplexedProtocol; //导入依赖的package包/类
@Override
public TProtocol getProtocol(TTransport transport, String serviceName) {
	if (serviceName != null)
		return new TMultiplexedProtocol(getProtocol(transport), serviceName);
	else
		return getProtocol(transport);
}
 
开发者ID:venwyhk,项目名称:ikasoa,代码行数:8,代码来源:AbstractThriftClientImpl.java

示例10: main

import org.apache.thrift.protocol.TMultiplexedProtocol; //导入依赖的package包/类
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);
}
 
开发者ID:bigdullrock,项目名称:nifty-spring-boot-starter,代码行数:11,代码来源:SampleClient.java

示例11: setUp

import org.apache.thrift.protocol.TMultiplexedProtocol; //导入依赖的package包/类
@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);
}
 
开发者ID:bigdullrock,项目名称:nifty-spring-boot-starter,代码行数:9,代码来源:GreeterServiceTest.java

示例12: userProfileClient

import org.apache.thrift.protocol.TMultiplexedProtocol; //导入依赖的package包/类
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");
    }
}
 
开发者ID:SciGaP,项目名称:allocateme,代码行数:13,代码来源:UserProfileClientFactory.java

示例13: createConnection

import org.apache.thrift.protocol.TMultiplexedProtocol; //导入依赖的package包/类
/**
 * 创建原始连接的方法
 * 
 * @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);
	}
}
 
开发者ID:wmz7year,项目名称:Thrift-Connection-Pool,代码行数:35,代码来源:MulitServiceThriftConnecion.java

示例14: main

import org.apache.thrift.protocol.TMultiplexedProtocol; //导入依赖的package包/类
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());
    }
 
开发者ID:twellhausen,项目名称:spring-thrift-integration,代码行数:14,代码来源:Client.java

示例15: start

import org.apache.thrift.protocol.TMultiplexedProtocol; //导入依赖的package包/类
/**
 * 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());
  }
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:36,代码来源:NeighborConnection.java


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