本文整理汇总了Java中org.apache.thrift.protocol.TProtocol类的典型用法代码示例。如果您正苦于以下问题:Java TProtocol类的具体用法?Java TProtocol怎么用?Java TProtocol使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TProtocol类属于org.apache.thrift.protocol包,在下文中一共展示了TProtocol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkAndCreateAdminUser
import org.apache.thrift.protocol.TProtocol; //导入依赖的package包/类
private void checkAndCreateAdminUser() throws TException {
THttpClient thriftClient = new THttpClient(thriftServerUrl + "/users/thrift");
TProtocol protocol = new TCompactProtocol(thriftClient);
UserService.Iface userClient = new UserService.Client(protocol);
User admin = new User("admin", "[email protected]", "SW360 Administration");
admin.setFullname("John Doe");
admin.setGivenname("John");
admin.setLastname("Doe");
admin.setUserGroup(UserGroup.ADMIN);
try {
userClient.getByEmail("[email protected]");
System.out.println("sw360 admin user already exists");
} catch (Exception e) {
System.out.println("creating admin user => " + userClient.addUser(admin));
}
}
示例2: getClientConstructor
import org.apache.thrift.protocol.TProtocol; //导入依赖的package包/类
public static Constructor<?> getClientConstructor(Class<?> svcInterface) {
String client = svcInterface.getName().indexOf("Async") > 0 ? ASYNC_CLIENT_NAME : CLIENT_NAME;
Class<?>[] args = svcInterface.getName().indexOf("Async") > 0 ? new Class[]{TProtocolFactory.class, TAsyncClientManager.class, TNonblockingTransport.class} : new Class[]{TProtocol.class};
Class<?> clientClass = getThriftServiceInnerClassOrNull(svcInterface.getEnclosingClass(), client, false);
if (clientClass == null) {
throw new ThriftRuntimeException("the client class is null");
}
Constructor<?> constructor = ClassUtils.getConstructorIfAvailable(clientClass, args);
if (constructor == null) {
throw new ThriftRuntimeException("the clientClass constructor is null");
}
return constructor;
}
示例3: process
import org.apache.thrift.protocol.TProtocol; //导入依赖的package包/类
@Override
public boolean process(TProtocol in, TProtocol out) throws TException {
TMessage msg = in.readMessageBegin();
Controller<?, ?> fn = (Controller<?, ?>) this.beanFactory
.getBean(msg.name);
if (fn == null) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("Invalid request: failed to find interface="
+ msg.name + ", from: " + getInetAddress(in));
}
TProtocolUtil.skip(in, TType.STRUCT);
in.readMessageEnd();
TApplicationException x = new TApplicationException(
TApplicationException.UNKNOWN_METHOD,
"Invalid method name: '" + msg.name + "'");
out.writeMessageBegin(new TMessage(msg.name,
TMessageType.EXCEPTION, msg.seqid));
x.write(out);
out.writeMessageEnd();
out.getTransport().flush();
return true;
}
process(msg.seqid, msg.name, in, out, fn);
return true;
}
示例4: encodeRequest
import org.apache.thrift.protocol.TProtocol; //导入依赖的package包/类
protected void encodeRequest(Channel channel, ChannelBuffer buffer, Request request)
throws IOException {
Invocation invocation = (Invocation) request.getData();
TProtocol protocol = newProtocol(channel.getUrl(), buffer);
try {
protocol.writeMessageBegin(new TMessage(
invocation.getMethodName(), TMessageType.CALL,
thriftSeq.getAndIncrement()));
protocol.writeStructBegin(new TStruct(invocation.getMethodName() + "_args"));
for(int i = 0; i < invocation.getParameterTypes().length; i++) {
Class<?> type = invocation.getParameterTypes()[i];
}
} catch (TException e) {
throw new IOException(e.getMessage(), e);
}
}
示例5: writeRequest
import org.apache.thrift.protocol.TProtocol; //导入依赖的package包/类
private static void writeRequest(MethodMetadata method, List<Object> parameters, TProtocol protocol)
throws Exception
{
TMessage requestMessage = new TMessage(method.getName(), CALL, SEQUENCE_ID);
protocol.writeMessageBegin(requestMessage);
// write the parameters
ProtocolWriter writer = new ProtocolWriter(new ThriftToDriftProtocolWriter(protocol));
writer.writeStructBegin(method.getName() + "_args");
for (int i = 0; i < parameters.size(); i++) {
Object value = parameters.get(i);
ParameterMetadata parameter = method.getParameters().get(i);
writer.writeField(parameter.getName(), parameter.getId(), parameter.getCodec(), value);
}
writer.writeStructEnd();
protocol.writeMessageEnd();
protocol.getTransport().flush();
}
示例6: createModelBridge
import org.apache.thrift.protocol.TProtocol; //导入依赖的package包/类
/**
* Creates a Model and a Thrift Bridge to this model.
*/
protected static EBMI createModelBridge(String host, String pythonExecutable, File opendaPythonPath, File modelPythonPath,
String modelPythonModuleName, String modelPythonClassName, File modelRunDir) throws IOException {
// start local server.
int port = getFreePort();
if (host == null) {
//localhost
host = "127.0.0.1";
}
Process process = startModelProcess(host, port, pythonExecutable, opendaPythonPath, modelPythonPath,
modelPythonModuleName, modelPythonClassName, modelRunDir);
// connect to server.
TTransport transport = connectToCode(host, port, process);
// create client.
TProtocol protocol = new TBinaryProtocol(transport);
BMIService.Client client = new BMIService.Client(protocol);
return new ThriftBmiBridge(client, process, transport);
}
示例7: testBlockSync
import org.apache.thrift.protocol.TProtocol; //导入依赖的package包/类
@Test
public void testBlockSync() throws TException {
AskerServer server = new AskerServer(port, true);
server.start();
try (TTransport transport = transport(port)) {
transport.open();
TProtocol protocol = new TCompactProtocol(transport);
final Asker.Client client = new Asker.Client(protocol);
Helper helper = new Helper(collector);
helper.checkEcho(client);
helper.checkCount(client);
helper.checkReverse(client);
helper.checkUpperCast(client);
helper.checkLowerCast(client);
helper.checkRandom(client, 5 + random.nextInt(10));
}
server.stop();
}
示例8: testNonBlockSync
import org.apache.thrift.protocol.TProtocol; //导入依赖的package包/类
@Test
public void testNonBlockSync() throws TException {
AskerServer server = new AskerServer(port, false);
server.start();
try (TTransport transport = new TFramedTransport(transport(port))) {
transport.open();
TProtocol protocol = new TCompactProtocol(transport);
final Asker.Client client = new Asker.Client(protocol);
Helper helper = new Helper(collector);
helper.checkEcho(client);
helper.checkCount(client);
helper.checkReverse(client);
helper.checkUpperCast(client);
helper.checkLowerCast(client);
helper.checkRandom(client, 5 + random.nextInt(10));
}
server.stop();
}
示例9: testScribeMessage
import org.apache.thrift.protocol.TProtocol; //导入依赖的package包/类
@Test
public void testScribeMessage() throws Exception {
TTransport transport = new TFramedTransport(new TSocket("localhost", port));
TProtocol protocol = new TBinaryProtocol(transport);
Scribe.Client client = new Scribe.Client(protocol);
transport.open();
LogEntry logEntry = new LogEntry("INFO", "Sending info msg to scribe source");
List<LogEntry> logEntries = new ArrayList<LogEntry>(1);
logEntries.add(logEntry);
client.Log(logEntries);
// try to get it from Channels
Transaction tx = memoryChannel.getTransaction();
tx.begin();
Event e = memoryChannel.take();
Assert.assertNotNull(e);
Assert.assertEquals("Sending info msg to scribe source", new String(e.getBody()));
tx.commit();
tx.close();
}
示例10: load
import org.apache.thrift.protocol.TProtocol; //导入依赖的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);
}
示例11: startClient
import org.apache.thrift.protocol.TProtocol; //导入依赖的package包/类
public static void startClient(String ip ,int port ,int timeout) throws Exception
{
TTransport transport = new TSocket(ip,port,timeout);
TProtocol protocol = new TBinaryProtocol(transport);
leafrpc.Client client = new leafrpc.Client(protocol);
transport.open();
int i = 0;
while(i < 2000000)
{
client.getID("");
++i;
}
transport.close();
}
示例12: startClient2
import org.apache.thrift.protocol.TProtocol; //导入依赖的package包/类
public static void startClient2(String ip ,int port ,int timeout) throws Exception
{
TTransport transport = new TFramedTransport(new TSocket(ip,port,timeout));
TProtocol protocol = new TBinaryProtocol(transport);
leafrpc.Client client = new leafrpc.Client(protocol);
transport.open();
for(int i = 0; i< 1000000; i++)
{
client.getID("");
if (i % 100000 == 0)
{
System.out.println(Thread.currentThread().getName() + " " + client.getID(""));
}
//ai.incrementAndGet();
}
transport.close();
}
示例13: makeObject
import org.apache.thrift.protocol.TProtocol; //导入依赖的package包/类
@Override
public TServiceClient makeObject() throws Exception {
InetSocketAddress address = serverAddressProvider.selector();
if(address==null){
new ThriftException("No provider available for remote service");
}
TSocket tsocket = new TSocket(address.getHostName(), address.getPort());
TTransport transport = new TFramedTransport(tsocket);
TProtocol protocol = new TBinaryProtocol(transport);
TServiceClient client = this.clientFactory.getClient(protocol);
transport.open();
if (callback != null) {
try {
callback.make(client);
} catch (Exception e) {
logger.warn("makeObject:{}", e);
}
}
return client;
}
示例14: deflateNonNull
import org.apache.thrift.protocol.TProtocol; //导入依赖的package包/类
/**
* Encodes a thrift object into a DEFLATE-compressed binary array.
*
* @param tBase Object to encode.
* @return Deflated, encoded object.
* @throws CodingException If the object could not be encoded.
*/
public static byte[] deflateNonNull(TBase<?, ?> tBase) throws CodingException {
requireNonNull(tBase);
// NOTE: Buffering is needed here for performance.
// There are actually 2 buffers in play here - the BufferedOutputStream prevents thrift from
// causing a call to deflate() on every encoded primitive. The DeflaterOutputStream buffer
// allows the underlying Deflater to operate on a larger chunk at a time without stopping to
// copy the intermediate compressed output to outBytes.
// See http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4986239
ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
TTransport transport = new TIOStreamTransport(
new BufferedOutputStream(
new DeflaterOutputStream(outBytes, new Deflater(DEFLATE_LEVEL), DEFLATER_BUFFER_SIZE),
DEFLATER_BUFFER_SIZE));
try {
TProtocol protocol = PROTOCOL_FACTORY.getProtocol(transport);
tBase.write(protocol);
transport.close(); // calls finish() on the underlying stream, completing the compression
return outBytes.toByteArray();
} catch (TException e) {
throw new CodingException("Failed to serialize: " + tBase, e);
} finally {
transport.close();
}
}
示例15: inflateNonNull
import org.apache.thrift.protocol.TProtocol; //导入依赖的package包/类
/**
* Decodes a thrift object from a DEFLATE-compressed byte array into a target type.
*
* @param clazz Class to instantiate and deserialize to.
* @param buffer Compressed buffer to decode.
* @return A populated message.
* @throws CodingException If the message could not be decoded.
*/
public static <T extends TBase<T, ?>> T inflateNonNull(Class<T> clazz, byte[] buffer)
throws CodingException {
requireNonNull(clazz);
requireNonNull(buffer);
T tBase = newInstance(clazz);
TTransport transport = new TIOStreamTransport(
new InflaterInputStream(new ByteArrayInputStream(buffer)));
try {
TProtocol protocol = PROTOCOL_FACTORY.getProtocol(transport);
tBase.read(protocol);
return tBase;
} catch (TException e) {
throw new CodingException("Failed to deserialize: " + e, e);
} finally {
transport.close();
}
}