Package co.paralleluniverse.galaxy.core

Examples of co.paralleluniverse.galaxy.core.Message$BACKUPACK


    }

    @Override
    protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
        final ChannelBuffer buffer = (ChannelBuffer) msg;
        final Message message = Message.fromByteBuffer(buffer.toByteBuffer());
        return message;
    }
View Full Code Here


        numBuffers += 1 + message.getNumDataBuffers();
    }

    public boolean removeMessage(Message m) {
        int index = messages.indexOf(m);
        Message message = messages.get(index); // m != message. often m will be the response to message
        if (index >= 0) {
            messages.remove(index);
            messageRemoved(message);
            return true;
        } else
View Full Code Here

            return false;
    }

    public boolean removeMessage(long id) {
        for (Iterator<Message> it = messages.iterator(); it.hasNext();) {
            final Message message = it.next();
            if (message.getMessageId() != id)
                continue;

            it.remove();
            messageRemoved(message);
            return true;
View Full Code Here

    public Message getMessage(Message m) {
        int index = messages.indexOf(m);
        if(index < 0)
            return null;
        Message message = messages.get(index); // m != message. often m will be the response to message
        return message;
    }
View Full Code Here

        return messages.contains(m);
    }

    public boolean contains(long id) {
        for (Iterator<Message> it = messages.iterator(); it.hasNext();) {
            final Message message = it.next();
            if (message.getMessageId() != id)
                continue;

            return true;
        }
        return false;
View Full Code Here

    public void fromByteBuffer(ByteBuffer buffer) {
        while (buffer.hasRemaining()) {
            if (LOG.isDebugEnabled())
                LOG.debug("decoding. remaining "+buffer.remaining());
            final Message fromByteBuffer = Message.fromByteBuffer(buffer);
            if (LOG.isDebugEnabled())
                LOG.debug("decoded "+fromByteBuffer);
            addMessage(fromByteBuffer);
        }
    }
View Full Code Here

            public void run() {
                final long now = System.nanoTime();

                if (pendingBroadcasts != null) {
                    for (BroadcastEntry entry : pendingBroadcasts.values()) {
                        final Message message = entry.message;
                        if (message.getType() != Message.Type.INVACK && now - message.getTimestamp() > timeoutNano) {
                            if (pendingBroadcasts.remove(message.getMessageId()) != null) {
                                LOG.debug("Timeout on message {}", message);
                                receive(Message.TIMEOUT((LineMessage) message).setIncoming());
                            }
                        }
                    }
                }
                for (Deque<Message> pending : pendingReply.values()) {
                    for (Message message : reverse(pending)) {
                        if (message.getType() != Message.Type.INVACK && now - message.getTimestamp() > timeoutNano) {
                            if (pending.removeLastOccurrence(message)) {// we're using this instead of iterators to safeguard against the case that a reply just arrives
                                LOG.debug("Timeout on message {}", message);
                                receive(Message.TIMEOUT((LineMessage) message).setIncoming());
                            }
                        } else
View Full Code Here

            if (getCluster().getMyAddress() != null && msg.getSrc() != null && getCluster().getMyAddress().equals(msg.getSrc()))
                return; // discard own (cannot set the flag because it screws up th control channel. not much to do about it - annoing up handler in JChannel)
            final byte[] buffer = msg.getRawBuffer();
            if (buffer.length == 0)
                return; // probably just a flush
            final Message message = Message.fromByteArray(buffer);
            final Address source = msg.getSrc();

            if (message.isResponse()) {
                final Deque<Message> pending = pendingReply.get(message.getNode());

                if (pending != null) {
                    boolean res = pending.removeLastOccurrence(message); // relies on Message.equals that matches request/reply
                    if (res)
                        LOG.debug("Message {} is a reply! (removing from pending)", message);
                }
            }

            if (message.isResponse()) {
                final BroadcastEntry entry = pendingBroadcasts.get(message.getMessageId());
                if (entry != null) {
                    if (message.getType() != Message.Type.ACK) {// this is a response - no need to wait for further acks
                        LOG.debug("Message {} is a reply to a broadcast! (discarding pending)", message);
                        pendingBroadcasts.remove(message.getMessageId());
                    } else
                        removeFromPendingBroadcasts(message.getMessageId(), message.getNode());
                }
            }

            final short sourceNode = getNode(source);
            if (sourceNode < 0)
                throw new RuntimeException("Node not found for source address " + source);
            message.setNode(sourceNode);
            receive(message);
        } catch (Exception ex) {
            LOG.error("Error receiving message", ex);
        }
    }
View Full Code Here

    }
    ///////////////////////////////////////////////

    @Test
    public void testSimpleSendMessage() throws Exception {
        final Message m = Message.GET(sh(2), 1234L);
        comm.send(m);
        await();
        verify(channel, atLeastOnce()).write(argThat(is(packetThatContains(m))), eq(node2Address));
    }
View Full Code Here

    }

    @Test
    public void whenSeveralMessagesThenAggregateInPacketUntilMaxDelay() throws Exception {
        // we test on responses because requests actually send immediately when comm.send() is called
        final Message m1 = Message.INVACK(Message.INV(sh(2), id(1111L), sh(10))).setMessageId(10001);
        final Message m2 = Message.INVACK(Message.INV(sh(2), id(2222L), sh(10))).setMessageId(10002);
        final Message m3 = Message.INVACK(Message.INV(sh(2), id(3333L), sh(10))).setMessageId(10003);
        final Message m4 = Message.INVACK(Message.INV(sh(2), id(4444L), sh(10))).setMessageId(10004);
        comm.send(m1);
        comm.send(m2);
        comm.send(m3);
        sleep(10); // more than min delay since last
        comm.send(m4);
View Full Code Here

TOP

Related Classes of co.paralleluniverse.galaxy.core.Message$BACKUPACK

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.