Search in sources :

Example 46 with Message

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);
    }
}
Also used : Message(com.google.protobuf.Message) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 47 with Message

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;
}
Also used : Message(com.google.protobuf.Message) RequestRoutingType(voldemort.server.RequestRoutingType) ByteArray(voldemort.utils.ByteArray) ByteString(com.google.protobuf.ByteString) VoldemortRequest(voldemort.client.protocol.pb.VProto.VoldemortRequest) VoldemortException(voldemort.VoldemortException)

Example 48 with Message

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");
}
Also used : Message(com.google.protobuf.Message) ByteArray(voldemort.utils.ByteArray)

Example 49 with Message

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);
    }
}
Also used : Message(com.google.protobuf.Message)

Example 50 with Message

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();
    }
}
Also used : UnsynchronizedBuffer(org.apache.calcite.avatica.util.UnsynchronizedBuffer) WireMessage(org.apache.calcite.avatica.proto.Common.WireMessage) Message(com.google.protobuf.Message)

Aggregations

Message (com.google.protobuf.Message)185 Test (org.junit.Test)62 Any (com.google.protobuf.Any)30 Command (io.spine.core.Command)14 EntityRecord (io.spine.server.entity.EntityRecord)10 ByteString (com.google.protobuf.ByteString)9 Event (io.spine.core.Event)8 Event (io.spine.base.Event)7 CommandEnvelope (io.spine.core.CommandEnvelope)7 TypeUrl (io.spine.type.TypeUrl)7 IOException (java.io.IOException)7 Timestamp (com.google.protobuf.Timestamp)5 Error (io.spine.base.Error)5 Rejection (io.spine.core.Rejection)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 Method (java.lang.reflect.Method)5 FieldMask (com.google.protobuf.FieldMask)4 GeneratedMessage (com.google.protobuf.GeneratedMessage)4 ThrowableMessage (io.spine.base.ThrowableMessage)4 EntityFilters (io.spine.client.EntityFilters)4