Search in sources :

Example 11 with MessageType

use of org.neo4j.cluster.com.message.MessageType in project neo4j by neo4j.

the class StateMachineProxyFactory method invoke.

Object invoke(StateMachine stateMachine, Method method, Object arg) throws Throwable {
    if (method.getName().equals("toString")) {
        return me.toString();
    }
    if (method.getName().equals("equals")) {
        return ((StateMachineProxyHandler) Proxy.getInvocationHandler(arg)).getStateMachineProxyFactory().me.equals(me);
    }
    String conversationId = conversations.getNextConversationId();
    try {
        Class<? extends MessageType> messageType = stateMachine.getMessageType();
        MessageType typeAsEnum = (MessageType) Enum.valueOf((Class<? extends Enum>) messageType, method.getName());
        Message<?> message = Message.internal(typeAsEnum, arg);
        if (me != null) {
            message.setHeader(Message.CONVERSATION_ID, conversationId).setHeader(Message.CREATED_BY, me.toString());
        }
        if (method.getReturnType().equals(Void.TYPE)) {
            stateMachines.process(message);
            return null;
        } else {
            ResponseFuture future = new ResponseFuture(conversationId, typeAsEnum, responseFutureMap);
            responseFutureMap.put(conversationId, future);
            log.debug("Added response future for conversation id %s", conversationId);
            stateMachines.process(message);
            return future;
        }
    } catch (IllegalArgumentException e) {
        throw new IllegalStateException("No state machine can handle the method " + method.getName());
    }
}
Also used : MessageType(org.neo4j.cluster.com.message.MessageType)

Example 12 with MessageType

use of org.neo4j.cluster.com.message.MessageType in project neo4j by neo4j.

the class MessageDeliveryAction method messageCopy.

private Message<? extends MessageType> messageCopy() throws URISyntaxException {
    URI to = new URI(message.getHeader(Message.TO));
    Message<MessageType> copy = Message.to(message.getMessageType(), to, message.getPayload());
    return message.copyHeadersTo(copy);
}
Also used : URI(java.net.URI) MessageType(org.neo4j.cluster.com.message.MessageType)

Aggregations

MessageType (org.neo4j.cluster.com.message.MessageType)12 Test (org.junit.Test)10 Message (org.neo4j.cluster.com.message.Message)10 MessageHolder (org.neo4j.cluster.com.message.MessageHolder)9 ArrayList (java.util.ArrayList)6 InstanceId (org.neo4j.cluster.InstanceId)5 URI (java.net.URI)4 LinkedList (java.util.LinkedList)3 Mockito.doAnswer (org.mockito.Mockito.doAnswer)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Answer (org.mockito.stubbing.Answer)3 AtomicBroadcastMessage (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AtomicBroadcastMessage)2 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)2 ClusterContext (org.neo4j.cluster.protocol.cluster.ClusterContext)2 ClusterMessage (org.neo4j.cluster.protocol.cluster.ClusterMessage)2 InetSocketAddress (java.net.InetSocketAddress)1 Collection (java.util.Collection)1 Executor (java.util.concurrent.Executor)1 Channel (org.jboss.netty.channel.Channel)1 ChannelHandlerContext (org.jboss.netty.channel.ChannelHandlerContext)1