Package co.paralleluniverse.galaxy.core

Examples of co.paralleluniverse.galaxy.core.Message


            if (broadcast || sentPacket == null || sentPacket.isEmpty())
                return;

            final long timeoutNanos = NANOSECONDS.convert(getTimeout(), MILLISECONDS);
            for (Iterator<Message> it = sentPacket.reverseIterator(); it.hasNext();) {
                final Message message = it.next();
                if (message.getType() != Message.Type.INV && now - message.getTimestamp() > timeoutNanos) {
                    if (message.isResponse() || message.isBroadcast())
                        continue;
                    if (message instanceof LineMessage) {
                        LOG.debug("Timeout on message {}", message);
                        received.add(Message.TIMEOUT((LineMessage) message).setIncoming());
                    }
View Full Code Here


            // the packet, only it can't b/c its sentPacket is also full - we got a deadlock.
            // as I see it, the only way to truly resolve it is to have multi-part packets, but we don't want to do that.
            // what we do is that we don't allow a packet with requests only to be full - we always leave room for a response.

            // assumes hasRequests and requestsOnly are up to date.
            Message next = overflow;
            overflow = null;
            if (next == null)
                next = queue.poll();
            for (;;) {
                if (next == null)
                    break;
                overflow = next; // we put the next message into overflow. if we _don't_ break out of the loop and use the message, we'll nul overflow

                final boolean unicastBroadcast = next.isBroadcast() && unicastBroadcasts.remove(next);

                if (broadcast && (!next.isBroadcast() || unicastBroadcast))
                    break; // we're not taking any non-broadcast messages during broadcast

                if (!broadcast && next.isBroadcast() && !unicastBroadcast) {
                    if (sentPacket == null || sentPacket.isEmpty()) {
                        LOG.debug("Node peer {} going into broadcast mode for message {}.", this, next);
                        broadcast = true;
                    }
                    // else, we add message to packet, and continue transmitting.
                    // if the packet had responses only, the new broadcast request would force a re-send and expedite matters
                    // if a response for the broadcast is received before we get a chance to multicast, that's ok because we simply remove the node
                    // from the BroadcastEntry
                }

                if (next.size() > maxPacketSize) {
                    LOG.error("Message {} is larger than the maximum packet size {}", next, maxPacketSize);
                    throw new RuntimeException("Message is larger than maxPacketSize");
                }

                if (next.size() + sentPacketSizeInBytes() > maxPacketSize) {
                    if (next.isResponse() && requestsOnly)
                        LOG.warn("IMPORTANT: Response message {} does not fit in packet {} which contains only requests. THIS MAY CAUSE A DEADLOCK!", next, sentPacket);
                    break;
                }

                if (!next.isResponse()) {
                    if (requestsOnly && next.size() + sentPacketSizeInBytes() > maxRequestOnlyPacketSize)
                        break;
                    hasRequests = true;
                } else
                    requestsOnly = false;

                if (next.isResponse())
                    pendingRequests.remove(next.getMessageId());

                LOG.debug("Adding message {} to sent-packet", next);
                if (sentPacket == null)
                    sentPacket = new MessagePacket();
                sentPacket.addMessage(next);
View Full Code Here

            LOG.trace("BroadcastPeer CALL DONE");
            return null;
        }

        private void handleQueue(long start) throws InterruptedException {
            Message next = overflow;
            overflow = null;
            if (next == null)
                next = queue.poll();
            loop:
            for (;;) {
                if (next == null)
                    break;

                overflow = next; // we put the next message into overflow. if we _don't_ break out of the loop and use the message, we'll nul overflow

                if (next.size() > maxPacketSize) {
                    LOG.error("Message {} is larger than the maximum packet size {}", next, maxPacketSize);
                    throw new RuntimeException("Message is larger than maxPacketSize");
                }

                if (sentPacket != null && next.size() + sentPacket.sizeInBytes() > maxPacketSize)
                    break;

                LOG.debug("Waiting for peers to enter broadcast mode for message {}", next);
                BroadcastEntry entry = broadcasts.get(next.getMessageId());

                if (entry != null) {
                    if (entry.nodes.isEmpty()) {
                        broadcasts.remove(next.getMessageId());
                        if (next instanceof LineMessage) {
                            LOG.debug("No other nodes in cluster. Responding with NOT_FOUND to message {}", next);
                            receive(Message.NOT_FOUND((LineMessage) next).setIncoming());
                        }
                        entry = null;
                    }
                }

                if (entry != null) {
                    for (TShortIterator it = entry.nodes.iterator(); it.hasNext();) {
                        final short node = it.next();
                        final NodePeer peer = peers.get(node);
                        synchronized (peer) {
                            if (!(peer.isBroadcast() && peer.sentPacket.contains(next.getMessageId()))) {
                                LOG.trace("Waiting for peer {}.", peer);
                                break loop;
                            }
                            LOG.trace("Peer {} ok (broadcast {})", peer, next);
                        }
View Full Code Here

                return;
            final long timeoutNanos = NANOSECONDS.convert(getTimeout(), MILLISECONDS);

            for (Iterator<BroadcastEntry> it = broadcasts.values().iterator(); it.hasNext();) {
                final BroadcastEntry entry = it.next();
                final Message message = entry.message;
                if (message.getType() != Message.Type.INV && now - message.getTimestamp() > timeoutNanos) {
                    if (message instanceof LineMessage) {
                        LOG.debug("Timeout on message {}", message);
                        received.add(Message.TIMEOUT((LineMessage) message).setIncoming());
                    }
                    it.remove();
                    releasePeers(entry, (short) -1);
                    addTimeout(message);
                    if (sentPacket != null)
                        sentPacket.removeMessage(message.getMessageId());
                }
            }
            if (sentPacket != null && sentPacket.isEmpty())
                sentPacket = null;
View Full Code Here

                    sentPacket = null;
            }
        }

        private void releasePeers(BroadcastEntry entry, short node) {
            final Message message = entry.message;
            for (TShortIterator it = entry.nodes.iterator(); it.hasNext();) {
                final NodePeer peer = peers.get(it.next());
                if (peer.isBroadcast()) {
                    LOG.debug("Broadcast releasing peer {} for message {}", peer, message);
                    if (peer.node != node) {
View Full Code Here

TOP

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

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.