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


Java TMessage类代码示例

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


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

示例1: process

import org.apache.thrift.protocol.TMessage; //导入依赖的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;
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:27,代码来源:TProtobufProcessor.java

示例2: encodeRequest

import org.apache.thrift.protocol.TMessage; //导入依赖的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);
    }

}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:19,代码来源:ThriftNativeCodec.java

示例3: writeRequest

import org.apache.thrift.protocol.TMessage; //导入依赖的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();
}
 
开发者ID:airlift,项目名称:drift,代码行数:20,代码来源:ApacheThriftMethodInvoker.java

示例4: beforeWrite

import org.apache.thrift.protocol.TMessage; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes" })
@Override
public void beforeWrite(TMessage msg, TBase args, TBase result) {
	// reuse message's buffer when write? yes, we use the pool.
	ByteBuf readedBuf = message.getContent();
	int refCount = readedBuf.refCnt();
	if (refCount > 0) {
		readedBuf.release(refCount);
	}
	// voidMethod's return message is very short
	int initialCapacity = serverDef.trafficForecast.getInitBytesForWrite(msg.name);
	// logger.debug("initialCapacity = {} , msg = {}",initialCapacity, msg);
	ByteBuf buf = ctx.alloc().buffer(initialCapacity, serverDef.maxFrameSize);
	message.setContent(buf).beforeWrite(ctx);
	transport.setOutputBuffer(buf);
}
 
开发者ID:houkx,项目名称:nettythrift,代码行数:17,代码来源:DefaultWriterListener.java

示例5: writeResult

import org.apache.thrift.protocol.TMessage; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private void writeResult(final TProtocol out, final TMessage msg, final WriterHandler onComplete, TBase args,
		final TBase result) {
	try {
		onComplete.beforeWrite(msg, args, result);
		// if (!isOneway()) {
		out.writeMessageBegin(new TMessage(msg.name, TMessageType.REPLY, msg.seqid));
		if (result != null) {
			result.write(out);
		} else {
			out.writeStructBegin(null);
			out.writeFieldStop();
			out.writeStructEnd();
		}
		out.writeMessageEnd();
		out.getTransport().flush();
		// }
		onComplete.afterWrite(msg, null, TMessageType.REPLY, args, result);
	} catch (Throwable e) {
		onComplete.afterWrite(msg, e, TMessageType.EXCEPTION, args, result);
	}
}
 
开发者ID:houkx,项目名称:nettythrift,代码行数:23,代码来源:DefaultNettyProcessor.java

示例6: process

import org.apache.thrift.protocol.TMessage; //导入依赖的package包/类
@Override
public final boolean process(final TProtocol in, final TProtocol out)
    throws TException {
  final TMessage msg = in.readMessageBegin();
  final ProcessFunction<LocatorServiceImpl, ?> fn = this.fnMap
      .get(msg.name);
  if (fn != null) {
    fn.process(msg.seqid, in, out, this.inst);
    // terminate connection on receiving closeConnection
    // direct class comparison should be the fastest way
    return fn.getClass() != LocatorService.Processor.closeConnection.class;
  }
  else {
    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;
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:27,代码来源:LocatorServiceImpl.java

示例7: serialize

import org.apache.thrift.protocol.TMessage; //导入依赖的package包/类
@Override
public <Message extends PMessage<Message, Field>, Field extends PField>
int serialize(@Nonnull OutputStream output, @Nonnull PServiceCall<Message, Field> call)
        throws IOException {
    CountingOutputStream wrapper = new CountingOutputStream(output);
    TTransport transport = new TIOStreamTransport(wrapper);
    try {
        TProtocol protocol = protocolFactory.getProtocol(transport);
        TMessage tm = new TMessage(call.getMethod(), (byte) call.getType().asInteger(), call.getSequence());

        protocol.writeMessageBegin(tm);
        writeMessage(call.getMessage(), protocol);
        protocol.writeMessageEnd();

        transport.flush();
        wrapper.flush();
        return wrapper.getByteCount();
    } catch (TException e) {
        throw new SerializerException(e, e.getMessage());
    }
}
 
开发者ID:morimekta,项目名称:providence,代码行数:22,代码来源:TProtocolSerializer.java

示例8: serialize

import org.apache.thrift.protocol.TMessage; //导入依赖的package包/类
@Override
public <Message extends PMessage<Message, Field>, Field extends PField>
int serialize(@Nonnull OutputStream output, @Nonnull PServiceCall<Message, Field> call)
        throws IOException {
    CountingOutputStream wrapper = new CountingOutputStream(output);
    TTransport transport = new TIOStreamTransport(wrapper);
    try {
        TTupleProtocol protocol = (TTupleProtocol) protocolFactory.getProtocol(transport);
        TMessage tm = new TMessage(call.getMethod(), (byte) call.getType().asInteger(), call.getSequence());

        protocol.writeMessageBegin(tm);
        writeMessage(call.getMessage(), protocol);
        protocol.writeMessageEnd();

        transport.flush();
        wrapper.flush();
        return wrapper.getByteCount();
    } catch (TException e) {
        throw new SerializerException(e, e.getMessage());
    }
}
 
开发者ID:morimekta,项目名称:providence,代码行数:22,代码来源:TTupleProtocolSerializer.java

示例9: process

import org.apache.thrift.protocol.TMessage; //导入依赖的package包/类
@Override
public boolean process(TProtocol in, TProtocol out) throws TException {
  TMessage msg = in.readMessageBegin();
  ProcessFunction fn = processMap.get(msg.name);
  if (fn == null) {
    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;
  }
  fn.process(msg.seqid, in, out, iface);
  return true;
}
 
开发者ID:adityayadav76,项目名称:internet_of_things_simulator,代码行数:18,代码来源:TBaseProcessor.java

示例10: writeMessageBegin

import org.apache.thrift.protocol.TMessage; //导入依赖的package包/类
@Override
public void writeMessageBegin(TMessage tMessage) throws TException {
    oprot.writeStructBegin(null);
    oprot.writeString(METHOD_KEY);
    oprot.writeString(tMessage.name);
    switch (tMessage.type) {
        case TMessageType.CALL:
            oprot.writeString(ARGUMENTS_KEY);
            break;
        case TMessageType.REPLY:
            oprot.writeString(RESULT_KEY);
            break;
        case TMessageType.EXCEPTION:
            oprot.writeString(EXCEPTION_KEY);
            break;
    }
}
 
开发者ID:degupta,项目名称:human_readable_json_protocol,代码行数:18,代码来源:HumanReadableJsonProtocol.java

示例11: readApplicationException

import org.apache.thrift.protocol.TMessage; //导入依赖的package包/类
private static TApplicationException readApplicationException(int seqId, ThriftFunction func,
                                                              TProtocol inputProtocol,
                                                              TMessage msg) throws TException {
    if (msg.seqid != seqId) {
        throw new TApplicationException(TApplicationException.BAD_SEQUENCE_ID);
    }

    if (!func.name().equals(msg.name)) {
        return new TApplicationException(TApplicationException.WRONG_METHOD_NAME, msg.name);
    }

    if (msg.type == TMessageType.EXCEPTION) {
        final TApplicationException appEx = TApplicationExceptions.read(inputProtocol);
        inputProtocol.readMessageEnd();
        return appEx;
    }

    return null;
}
 
开发者ID:line,项目名称:armeria,代码行数:20,代码来源:THttpClientDelegate.java

示例12: newObjectMapper

import org.apache.thrift.protocol.TMessage; //导入依赖的package包/类
/**
 * Returns newly created {@link ObjectMapper} which is configured properly to serialize some knows classes
 * in a good way.
 */
public static ObjectMapper newObjectMapper(SimpleModule... userModules) {
    ObjectMapper objectMapper = new ObjectMapper();

    SimpleModule module = new SimpleModule();
    module.addSerializer(TMessage.class, new TMessageSerializer());
    module.addSerializer(TBase.class, new TBaseSerializer());
    module.addSerializer(TApplicationException.class, new TApplicationExceptionSerializer());
    module.addSerializer(ThriftCall.class, new ThriftCallSerializer());
    module.addSerializer(ThriftReply.class, new ThriftReplySerializer());
    objectMapper.registerModule(module);

    for (SimpleModule userModule : userModules) {
        objectMapper.registerModule(userModule);
    }

    return objectMapper;
}
 
开发者ID:line,项目名称:armeria,代码行数:22,代码来源:ThriftStructuredLogJsonFormat.java

示例13: writeMessageBegin

import org.apache.thrift.protocol.TMessage; //导入依赖的package包/类
/**
 * I believe these two messages are called for a thrift service
 * interface. We don't plan on storing any text objects of that
 * type on disk.
 */
@Override
public void writeMessageBegin(TMessage message) throws TException {
    try {
        getCurrentWriter().writeStartObject();
        getCurrentWriter().writeFieldName("method");
        getCurrentWriter().writeString(message.name);
        getCurrentWriter().writeFieldName("type");
        TypedParser.TMESSAGE_TYPE.writeValue(getCurrentWriter(), message.type);
        getCurrentWriter().writeFieldName("seqid");
        getCurrentWriter().writeNumber(message.seqid);
        getCurrentWriter().writeFieldName("args");
    } catch (IOException e) {
        throw new TTransportException(e);
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:21,代码来源:TTextProtocol.java

示例14: sendAndReceive

import org.apache.thrift.protocol.TMessage; //导入依赖的package包/类
@Test
public void sendAndReceive() throws TException {
  // GIVEN
  TMessage msg = new TMessage("a", (byte) 0, 0);
  int content = 100;

  outputIntegrityValidatingProtocol.writeMessageBegin(msg);
  outputIntegrityValidatingProtocol.writeI32(content);
  outputIntegrityValidatingProtocol.writeMessageEnd();

  inputMemoryTrans.reset(outputMemoryBuf.getArray(), 0, outputMemoryBuf.length());

  // WHEN
  TMessage readMsg = inputIntegrityValidatingProtocol.readMessageBegin();
  int readContent = inputIntegrityValidatingProtocol.readI32();
  inputIntegrityValidatingProtocol.readMessageEnd();

  // THEN
  Assert.assertEquals(readMsg, msg, "Expected to read correct TMessage");
  Assert.assertEquals(content, readContent, "Expected to read correct content");
  // and: Expected not to have a validity exception!
}
 
开发者ID:diqube,项目名称:diqube,代码行数:23,代码来源:IntegrityCheckingProtocolTest.java

示例15: sendAndReceiveTamperedMessage

import org.apache.thrift.protocol.TMessage; //导入依赖的package包/类
@Test(expectedExceptions = IntegrityViolatedException.class)
public void sendAndReceiveTamperedMessage() throws TException {
  // GIVEN
  TMessage msg = new TMessage("a", (byte) 0, 0);
  int content = 100;

  outputIntegrityValidatingProtocol.writeMessageBegin(msg);
  outputIntegrityValidatingProtocol.writeI32(content);
  outputIntegrityValidatingProtocol.writeMessageEnd();

  byte[] wireData = outputMemoryBuf.getArray();
  // tamper with the message on the wire
  wireData[wireData.length / 2] = (byte) -wireData[wireData.length / 2];
  inputMemoryTrans.reset(wireData);

  // WHEN
  inputIntegrityValidatingProtocol.readMessageBegin();
  inputIntegrityValidatingProtocol.readI32();
  inputIntegrityValidatingProtocol.readMessageEnd();

  // THEN
  // and: Expected to have a validity exception!
}
 
开发者ID:diqube,项目名称:diqube,代码行数:24,代码来源:IntegrityCheckingProtocolTest.java


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