本文整理汇总了Java中org.apache.avro.Protocol.Message方法的典型用法代码示例。如果您正苦于以下问题:Java Protocol.Message方法的具体用法?Java Protocol.Message怎么用?Java Protocol.Message使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.Protocol
的用法示例。
在下文中一共展示了Protocol.Message方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractParams
import org.apache.avro.Protocol; //导入方法依赖的package包/类
/**
* Extracts parameters from RPC call to List or converts to object of appropriate type
* if only one parameter set.
*
* @param message Avro message
* @param request Avro request
* @param singleParameter Indicates that called method has single parameter
* @param dataResolver Extracts type of parameters in call
* @return Parameters of RPC method invocation
*/
private static Object extractParams(Protocol.Message message, Object request, boolean singleParameter, SpecificData dataResolver) {
if (singleParameter) {
Schema.Field field = message.getRequest().getFields().get(0);
return dataResolver.getField(request, field.name(), field.pos());
} else {
int i = 0;
Object[] params = new Object[message.getRequest().getFields().size()];
for (Schema.Field param : message.getRequest().getFields()) {
params[i] = dataResolver.getField(request, param.name(), param.pos());
i++;
}
return params;
}
}
示例2: respond
import org.apache.avro.Protocol; //导入方法依赖的package包/类
public Object respond(Protocol.Message message, Object request, SpecificData data) throws Exception {
AvroConsumer consumer = this.defaultConsumer;
if (this.consumerRegistry.containsKey(message.getName())) {
consumer = this.consumerRegistry.get(message.getName());
}
if (consumer == null) {
throw new AvroComponentException("No consumer defined for message: " + message.getName());
}
Object params = extractParams(message, request, consumer.getEndpoint().getConfiguration().isSingleParameter(), data);
return processExchange(consumer, message, params);
}
示例3: processExchange
import org.apache.avro.Protocol; //导入方法依赖的package包/类
/**
* Creates exchange and processes it.
*
* @param consumer Holds processor and exception handler
* @param message Message on which exchange is created
* @param params Params of exchange
* @return Response of exchange processing
* @throws Exception
*/
private static Object processExchange(AvroConsumer consumer, Protocol.Message message, Object params) throws Exception {
Object response;
Exchange exchange = consumer.getEndpoint().createExchange(message, params);
try {
consumer.getProcessor().process(exchange);
} catch (Throwable e) {
consumer.getExceptionHandler().handleException(e);
}
if (ExchangeHelper.isOutCapable(exchange)) {
response = exchange.getOut().getBody();
} else {
response = null;
}
boolean failed = exchange.isFailed();
if (failed) {
if (exchange.getException() != null) {
throw exchange.getException();
} else {
// failed and no exception, must be a fault
throw new AvroComponentException("Camel processing error.");
}
}
return response;
}
示例4: createExchange
import org.apache.avro.Protocol; //导入方法依赖的package包/类
public Exchange createExchange(Protocol.Message message, Object request) {
ExchangePattern pattern = ExchangePattern.InOut;
if (message.getResponse().equals(Schema.Type.NULL)) {
pattern = ExchangePattern.InOnly;
}
Exchange exchange = createExchange(pattern);
exchange.getIn().setBody(request);
exchange.getIn().setHeader(AvroConstants.AVRO_MESSAGE_NAME, message.getName());
return exchange;
}
示例5: applyToConfiguration
import org.apache.avro.Protocol; //导入方法依赖的package包/类
/**
* Applies endpoint parameters to configuration & resolves protocol and other required configuration properties.
*/
private void applyToConfiguration(AvroConfiguration config, URI endpointUri, Map<String, Object> parameters) throws Exception {
config.parseURI(endpointUri, parameters, this);
setProperties(config, parameters);
if (config.getProtocol() == null && config.getProtocolClassName() != null) {
Class<?> protocolClass = getCamelContext().getClassResolver().resolveClass(config.getProtocolClassName());
if (protocolClass != null) {
try {
Field f = protocolClass.getField("PROTOCOL");
if (f != null) {
Protocol protocol = (Protocol)f.get(null);
config.setProtocol(protocol);
}
} catch (NoSuchFieldException e) {
ReflectData reflectData = ReflectData.get();
config.setProtocol(reflectData.getProtocol(protocolClass));
config.setReflectionProtocol(true);
}
}
}
if (config.getProtocol() == null) {
throw new IllegalArgumentException("Avro configuration does not contain protocol");
}
if (config.getMessageName() != null && !config.getProtocol().getMessages().containsKey(config.getMessageName())) {
throw new IllegalArgumentException("Message " + config.getMessageName() + " is not defined in protocol");
}
if (config.isSingleParameter()) {
Map<String, Protocol.Message> messageMap = config.getProtocol().getMessages();
Iterable<Protocol.Message> messagesToCheck = config.getMessageName() == null
? messageMap.values()
: Collections.singleton(messageMap.get(config.getMessageName()));
for (Protocol.Message message : messagesToCheck) {
if (message.getRequest().getFields().size() != 1) {
throw new IllegalArgumentException("Single parameter option can't be used with message "
+ message.getName() + " because it has " + message.getRequest().getFields().size()
+ " parameters defined"
);
}
}
}
}
示例6: respond
import org.apache.avro.Protocol; //导入方法依赖的package包/类
@Override
public Object respond(Protocol.Message message, Object request) throws Exception {
return listener.respond(message, request, SpecificData.get());
}
示例7: respond
import org.apache.avro.Protocol; //导入方法依赖的package包/类
@Override
public Object respond(Protocol.Message message, Object request) throws Exception {
return listener.respond(message, request, ReflectData.get());
}