use of com.google.protobuf.Message in project core-java by SpineEventEngine.
the class CommandHandlerMethod method invokeHandler.
/**
* Invokes the handler method in the passed object.
*
* @return the list of events produced by the handler method
*/
public static List<? extends Message> invokeHandler(Object object, Message command, CommandContext context) {
checkNotNull(object);
checkNotNull(command);
checkNotNull(context);
final Message commandMessage = ensureCommandMessage(command);
try {
final CommandHandlerMethod method = forMessage(object.getClass(), commandMessage);
final List<? extends Message> eventMessages = method.invoke(object, commandMessage, context);
return eventMessages;
} catch (InvocationTargetException e) {
throw illegalStateWithCauseOf(e);
}
}
use of com.google.protobuf.Message in project voldemort by voldemort.
the class ProtoBuffRequestHandler method handleRequest.
@Override
public StreamRequestHandler handleRequest(final DataInputStream inputStream, final DataOutputStream outputStream, final ByteBufferContainer outputContainer) throws IOException {
VoldemortRequest.Builder request = ProtoUtils.readToBuilder(inputStream, VoldemortRequest.newBuilder());
boolean shouldRoute = request.getShouldRoute();
RequestRoutingType type = RequestRoutingType.getRequestRoutingType(shouldRoute, false);
if (request.hasRequestRouteType()) {
type = RequestRoutingType.getRequestRoutingType(request.getRequestRouteType());
}
String storeName = request.getStore();
Store<ByteArray, byte[], byte[]> store = getStore(storeName, type);
Message response;
if (store == null) {
response = unknownStore(storeName, request.getType());
} else {
switch(request.getType()) {
case GET:
response = handleGet(request.getGet(), store);
break;
case GET_ALL:
response = handleGetAll(request.getGetAll(), store);
break;
case PUT:
response = handlePut(request.getPut(), store);
break;
case DELETE:
response = handleDelete(request.getDelete(), store);
break;
case GET_VERSION:
response = handleGetVersion(request.getGet(), store);
break;
default:
throw new VoldemortException("Unknown operation " + request.getType());
}
}
if (outputContainer != null) {
outputContainer.getBuffer().clear();
outputContainer.ensureSpace(response.getSerializedSize());
}
ProtoUtils.writeMessage(outputStream, response);
return null;
}
use of com.google.protobuf.Message in project voldemort by voldemort.
the class FullScanFetchKeysRequestHandler method handleRequest.
@Override
public StreamRequestHandlerState handleRequest(DataInputStream inputStream, DataOutputStream outputStream) throws IOException {
if (!keyIterator.hasNext()) {
return StreamRequestHandlerState.COMPLETE;
}
// NOTE: Storage time is accounted for somewhat incorrectly because
// .hasNext() is invoked at end of method for the common case.
long startNs = System.nanoTime();
ByteArray key = keyIterator.next();
reportStorageOpTime(startNs);
throttler.maybeThrottle(key.length());
if (isItemAccepted(key.get())) {
if (filter.accept(key, null)) {
accountForFetchedKey(key.get());
VAdminProto.FetchPartitionEntriesResponse.Builder response = VAdminProto.FetchPartitionEntriesResponse.newBuilder();
response.setKey(ProtoUtils.encodeBytes(key));
Message message = response.build();
sendMessage(outputStream, message);
}
}
accountForScanProgress("keys");
return determineRequestHandlerState("keys");
}
use of com.google.protobuf.Message in project heron by twitter.
the class HeronServer method handlePacket.
/**
* Handle an incomingPacket and invoke either onRequest or
* onMessage() to handle it
*/
private void handlePacket(SelectableChannel channel, IncomingPacket incomingPacket) {
String typeName = incomingPacket.unpackString();
REQID rid = incomingPacket.unpackREQID();
Message.Builder bldr = requestMap.get(typeName);
boolean isRequest = false;
if (bldr != null) {
// This is a request
isRequest = true;
} else {
bldr = messageMap.get(typeName);
}
if (bldr != null) {
// Clear the earlier state of Message.Builder
// Otherwise it would merge new Message with old state
bldr.clear();
incomingPacket.unpackMessage(bldr);
if (bldr.isInitialized()) {
Message msg = bldr.build();
if (isRequest) {
onRequest(rid, (SocketChannel) channel, msg);
} else {
onMessage((SocketChannel) channel, msg);
}
} else {
// Message failed to be deser
LOG.severe("Could not deserialize protobuf of type " + typeName);
handleError(channel);
}
return;
} else {
LOG.severe("Unexpected protobuf type received " + typeName);
handleError(channel);
}
}
use of com.google.protobuf.Message in project calcite-avatica by apache.
the class ProtobufTranslationImpl method serializeResponse.
@Override
public byte[] serializeResponse(Response response) throws IOException {
// Avoid BAOS for its synchronized write methods, we don't need that concurrency control
UnsynchronizedBuffer out = threadLocalBuffer.get();
try {
Message responseMsg = response.serialize();
// Serialization of the response may be large
if (LOG.isTraceEnabled()) {
LOG.trace("Serializing response '{}'", TextFormat.shortDebugString(responseMsg));
}
serializeMessage(out, responseMsg);
return out.toArray();
} finally {
out.reset();
}
}
Aggregations