本文整理汇总了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);
}
示例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;
}
示例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;
}
});
}
示例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\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}");
user.setId(234242453);
user.setIsman(true);
Result result = client.createNewBaseResInfo(user);
Assert.notNull(result);
System.out.println(result.getMsg());
System.out.println("end>>>>>>>>>>>>>>>>");
}
示例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"));
}
示例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.");
}
示例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);
}
示例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;
}
});
}
示例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);
}
示例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);
}
示例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);
}
示例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");
}
}
示例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);
}
}
示例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());
}
示例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());
}
}