Search in sources :

Example 36 with DistributionMessage

use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.

the class DistributedLockServiceDUnitTest method testDestroyLockServiceAfterGrantResponse.

@Test
public void testDestroyLockServiceAfterGrantResponse() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    final String serviceName = getUniqueName();
    vm0.invoke(new SerializableRunnable("Create the grantor") {

        public void run() {
            connectDistributedSystem();
            final DistributedLockService service = DistributedLockService.create(serviceName, dlstSystem);
            // lock and unlock to make sure this vm is grantor
            assertTrue(service.lock("obj", -1, -1));
            service.unlock("obj");
        }
    });
    DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

        @Override
        public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
            if (message instanceof DLockResponseMessage) {
                DistributedLockService.destroy(serviceName);
            }
        }
    });
    connectDistributedSystem();
    final DistributedLockService service = DistributedLockService.create(serviceName, dlstSystem);
    try {
        service.lock("obj", -1, -1);
        fail("The lock service should have been destroyed");
    } catch (LockServiceDestroyedException expected) {
    // Do nothing
    }
    vm0.invoke(new SerializableRunnable("check to make sure the lock is not orphaned") {

        public void run() {
            final DistributedLockService service = DistributedLockService.getServiceNamed(serviceName);
            // lock and unlock to make sure this vm is grantor
            assertTrue(service.lock("obj", -1, -1));
            service.unlock("obj");
        }
    });
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) DLockResponseMessage(org.apache.geode.distributed.internal.locks.DLockRequestProcessor.DLockResponseMessage) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) DLockTest(org.apache.geode.test.junit.categories.DLockTest)

Example 37 with DistributionMessage

use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.

the class Connection method processNIOBuffer.

/**
   * processes the current NIO buffer. If there are complete messages in the buffer, they are
   * deserialized and passed to TCPConduit for further processing
   */
private void processNIOBuffer() throws ConnectionException, IOException {
    if (nioInputBuffer != null) {
        nioInputBuffer.flip();
    }
    boolean done = false;
    while (!done && connected) {
        this.owner.getConduit().getCancelCriterion().checkCancelInProgress(null);
        // long startTime = DistributionStats.getStatTime();
        int remaining = nioInputBuffer.remaining();
        if (nioLengthSet || remaining >= MSG_HEADER_BYTES) {
            if (!nioLengthSet) {
                int headerStartPos = nioInputBuffer.position();
                nioMessageLength = nioInputBuffer.getInt();
                /* nioMessageVersion = */
                calcHdrVersion(nioMessageLength);
                nioMessageLength = calcMsgByteSize(nioMessageLength);
                nioMessageType = nioInputBuffer.get();
                nioMsgId = nioInputBuffer.getShort();
                directAck = (nioMessageType & DIRECT_ACK_BIT) != 0;
                if (directAck) {
                    // clear the ack bit
                    nioMessageType &= ~DIRECT_ACK_BIT;
                }
                // Following validation fixes bug 31145
                if (!validMsgType(nioMessageType)) {
                    Integer nioMessageTypeInteger = Integer.valueOf(nioMessageType);
                    logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_UNKNOWN_P2P_MESSAGE_TYPE_0, nioMessageTypeInteger));
                    this.readerShuttingDown = true;
                    requestClose(LocalizedStrings.Connection_UNKNOWN_P2P_MESSAGE_TYPE_0.toLocalizedString(nioMessageTypeInteger));
                    break;
                }
                nioLengthSet = true;
                // keep the header "in" the buffer until we have read the entire msg.
                // Trust me: this will reduce copying on large messages.
                nioInputBuffer.position(headerStartPos);
            }
            if (remaining >= nioMessageLength + MSG_HEADER_BYTES) {
                nioLengthSet = false;
                nioInputBuffer.position(nioInputBuffer.position() + MSG_HEADER_BYTES);
                // don't trust the message deserialization to leave the position in
                // the correct spot. Some of the serialization uses buffered
                // streams that can leave the position at the wrong spot
                int startPos = nioInputBuffer.position();
                int oldLimit = nioInputBuffer.limit();
                nioInputBuffer.limit(startPos + nioMessageLength);
                if (this.handshakeRead) {
                    if (nioMessageType == NORMAL_MSG_TYPE) {
                        this.owner.getConduit().stats.incMessagesBeingReceived(true, nioMessageLength);
                        ByteBufferInputStream bbis = remoteVersion == null ? new ByteBufferInputStream(nioInputBuffer) : new VersionedByteBufferInputStream(nioInputBuffer, remoteVersion);
                        DistributionMessage msg = null;
                        try {
                            ReplyProcessor21.initMessageRPId();
                            // add serialization stats
                            long startSer = this.owner.getConduit().stats.startMsgDeserialization();
                            msg = (DistributionMessage) InternalDataSerializer.readDSFID(bbis);
                            this.owner.getConduit().stats.endMsgDeserialization(startSer);
                            if (bbis.available() != 0) {
                                logger.warn(LocalizedMessage.create(LocalizedStrings.Connection_MESSAGE_DESERIALIZATION_OF_0_DID_NOT_READ_1_BYTES, new Object[] { msg, Integer.valueOf(bbis.available()) }));
                            }
                            try {
                                if (!dispatchMessage(msg, nioMessageLength, directAck)) {
                                    directAck = false;
                                }
                            } catch (MemberShunnedException e) {
                                // don't respond (bug39117)
                                directAck = false;
                            } catch (Exception de) {
                                this.owner.getConduit().getCancelCriterion().checkCancelInProgress(de);
                                logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_ERROR_DISPATCHING_MESSAGE), de);
                            } catch (ThreadDeath td) {
                                throw td;
                            } catch (VirtualMachineError err) {
                                SystemFailure.initiateFailure(err);
                                // now, so don't let this thread continue.
                                throw err;
                            } catch (Throwable t) {
                                // Whenever you catch Error or Throwable, you must also
                                // catch VirtualMachineError (see above). However, there is
                                // _still_ a possibility that you are dealing with a cascading
                                // error condition, so you also need to check to see if the JVM
                                // is still usable:
                                SystemFailure.checkFailure();
                                logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_THROWABLE_DISPATCHING_MESSAGE), t);
                            }
                        } catch (VirtualMachineError err) {
                            SystemFailure.initiateFailure(err);
                            // now, so don't let this thread continue.
                            throw err;
                        } catch (Throwable t) {
                            // Whenever you catch Error or Throwable, you must also
                            // catch VirtualMachineError (see above). However, there is
                            // _still_ a possibility that you are dealing with a cascading
                            // error condition, so you also need to check to see if the JVM
                            // is still usable:
                            SystemFailure.checkFailure();
                            sendFailureReply(ReplyProcessor21.getMessageRPId(), LocalizedStrings.Connection_ERROR_DESERIALIZING_MESSAGE.toLocalizedString(), t, directAck);
                            if (t instanceof ThreadDeath) {
                                throw (ThreadDeath) t;
                            }
                            if (t instanceof CancelException) {
                                if (!(t instanceof CacheClosedException)) {
                                    // CacheClosedException; see bug 43543
                                    throw (CancelException) t;
                                }
                            }
                            logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_ERROR_DESERIALIZING_MESSAGE), t);
                        } finally {
                            ReplyProcessor21.clearMessageRPId();
                        }
                    } else if (nioMessageType == CHUNKED_MSG_TYPE) {
                        MsgDestreamer md = obtainMsgDestreamer(nioMsgId, remoteVersion);
                        this.owner.getConduit().stats.incMessagesBeingReceived(md.size() == 0, nioMessageLength);
                        try {
                            md.addChunk(nioInputBuffer, nioMessageLength);
                        } catch (IOException ex) {
                            logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_FAILED_HANDLING_CHUNK_MESSAGE), ex);
                        }
                    } else /* (nioMessageType == END_CHUNKED_MSG_TYPE) */
                    {
                        // logger.info("END_CHUNK msgId="+nioMsgId);
                        MsgDestreamer md = obtainMsgDestreamer(nioMsgId, remoteVersion);
                        this.owner.getConduit().stats.incMessagesBeingReceived(md.size() == 0, nioMessageLength);
                        try {
                            md.addChunk(nioInputBuffer, nioMessageLength);
                        } catch (IOException ex) {
                            logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_FAILED_HANDLING_END_CHUNK_MESSAGE), ex);
                        }
                        DistributionMessage msg = null;
                        int msgLength = 0;
                        String failureMsg = null;
                        Throwable failureEx = null;
                        int rpId = 0;
                        boolean interrupted = false;
                        try {
                            msg = md.getMessage();
                        } catch (ClassNotFoundException ex) {
                            this.owner.getConduit().stats.decMessagesBeingReceived(md.size());
                            failureMsg = LocalizedStrings.Connection_CLASSNOTFOUND_DESERIALIZING_MESSAGE.toLocalizedString();
                            failureEx = ex;
                            rpId = md.getRPid();
                            logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_CLASSNOTFOUND_DESERIALIZING_MESSAGE_0, ex));
                        } catch (IOException ex) {
                            this.owner.getConduit().stats.decMessagesBeingReceived(md.size());
                            failureMsg = LocalizedStrings.Connection_IOEXCEPTION_DESERIALIZING_MESSAGE.toLocalizedString();
                            failureEx = ex;
                            rpId = md.getRPid();
                            logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_IOEXCEPTION_DESERIALIZING_MESSAGE), failureEx);
                        } catch (InterruptedException ex) {
                            interrupted = true;
                            this.owner.getConduit().getCancelCriterion().checkCancelInProgress(ex);
                        } catch (VirtualMachineError err) {
                            SystemFailure.initiateFailure(err);
                            // now, so don't let this thread continue.
                            throw err;
                        } catch (Throwable ex) {
                            // Whenever you catch Error or Throwable, you must also
                            // catch VirtualMachineError (see above). However, there is
                            // _still_ a possibility that you are dealing with a cascading
                            // error condition, so you also need to check to see if the JVM
                            // is still usable:
                            SystemFailure.checkFailure();
                            this.owner.getConduit().getCancelCriterion().checkCancelInProgress(ex);
                            this.owner.getConduit().stats.decMessagesBeingReceived(md.size());
                            failureMsg = LocalizedStrings.Connection_UNEXPECTED_FAILURE_DESERIALIZING_MESSAGE.toLocalizedString();
                            failureEx = ex;
                            rpId = md.getRPid();
                            logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_UNEXPECTED_FAILURE_DESERIALIZING_MESSAGE), failureEx);
                        } finally {
                            msgLength = md.size();
                            releaseMsgDestreamer(nioMsgId, md);
                            if (interrupted) {
                                Thread.currentThread().interrupt();
                            }
                        }
                        if (msg != null) {
                            try {
                                if (!dispatchMessage(msg, msgLength, directAck)) {
                                    directAck = false;
                                }
                            } catch (MemberShunnedException e) {
                                // not a member anymore - don't reply
                                directAck = false;
                            } catch (Exception de) {
                                this.owner.getConduit().getCancelCriterion().checkCancelInProgress(de);
                                logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_ERROR_DISPATCHING_MESSAGE), de);
                            } catch (ThreadDeath td) {
                                throw td;
                            } catch (VirtualMachineError err) {
                                SystemFailure.initiateFailure(err);
                                // now, so don't let this thread continue.
                                throw err;
                            } catch (Throwable t) {
                                // Whenever you catch Error or Throwable, you must also
                                // catch VirtualMachineError (see above). However, there is
                                // _still_ a possibility that you are dealing with a cascading
                                // error condition, so you also need to check to see if the JVM
                                // is still usable:
                                SystemFailure.checkFailure();
                                logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_THROWABLE_DISPATCHING_MESSAGE), t);
                            }
                        } else if (failureEx != null) {
                            sendFailureReply(rpId, failureMsg, failureEx, directAck);
                        }
                    }
                } else {
                    // read HANDSHAKE
                    ByteBufferInputStream bbis = new ByteBufferInputStream(nioInputBuffer);
                    DataInputStream dis = new DataInputStream(bbis);
                    if (!this.isReceiver) {
                        try {
                            this.replyCode = dis.readUnsignedByte();
                            if (this.replyCode == REPLY_CODE_OK_WITH_ASYNC_INFO) {
                                this.asyncDistributionTimeout = dis.readInt();
                                this.asyncQueueTimeout = dis.readInt();
                                this.asyncMaxQueueSize = (long) dis.readInt() * (1024 * 1024);
                                if (this.asyncDistributionTimeout != 0) {
                                    logger.info(LocalizedMessage.create(LocalizedStrings.Connection_0_ASYNC_CONFIGURATION_RECEIVED_1, new Object[] { p2pReaderName(), " asyncDistributionTimeout=" + this.asyncDistributionTimeout + " asyncQueueTimeout=" + this.asyncQueueTimeout + " asyncMaxQueueSize=" + (this.asyncMaxQueueSize / (1024 * 1024)) }));
                                }
                                // read the product version ordinal for on-the-fly serialization
                                // transformations (for rolling upgrades)
                                this.remoteVersion = Version.readVersion(dis, true);
                            }
                        } catch (Exception e) {
                            this.owner.getConduit().getCancelCriterion().checkCancelInProgress(e);
                            logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_ERROR_DESERIALIZING_P2P_HANDSHAKE_REPLY), e);
                            this.readerShuttingDown = true;
                            requestClose(LocalizedStrings.Connection_ERROR_DESERIALIZING_P2P_HANDSHAKE_REPLY.toLocalizedString());
                            return;
                        } catch (ThreadDeath td) {
                            throw td;
                        } catch (VirtualMachineError err) {
                            SystemFailure.initiateFailure(err);
                            // now, so don't let this thread continue.
                            throw err;
                        } catch (Throwable t) {
                            // Whenever you catch Error or Throwable, you must also
                            // catch VirtualMachineError (see above). However, there is
                            // _still_ a possibility that you are dealing with a cascading
                            // error condition, so you also need to check to see if the JVM
                            // is still usable:
                            SystemFailure.checkFailure();
                            logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_THROWABLE_DESERIALIZING_P2P_HANDSHAKE_REPLY), t);
                            this.readerShuttingDown = true;
                            requestClose(LocalizedStrings.Connection_THROWABLE_DESERIALIZING_P2P_HANDSHAKE_REPLY.toLocalizedString());
                            return;
                        }
                        if (this.replyCode != REPLY_CODE_OK && this.replyCode != REPLY_CODE_OK_WITH_ASYNC_INFO) {
                            StringId err = LocalizedStrings.Connection_UNKNOWN_HANDSHAKE_REPLY_CODE_0_NIOMESSAGELENGTH_1_PROCESSORTYPE_2;
                            Object[] errArgs = new Object[] { Integer.valueOf(this.replyCode), Integer.valueOf(nioMessageLength) };
                            if (replyCode == 0 && logger.isDebugEnabled()) {
                                // bug 37113
                                logger.debug(err.toLocalizedString(errArgs) + " (peer probably departed ungracefully)");
                            } else {
                                logger.fatal(LocalizedMessage.create(err, errArgs));
                            }
                            this.readerShuttingDown = true;
                            requestClose(err.toLocalizedString(errArgs));
                            return;
                        }
                        notifyHandshakeWaiter(true);
                    } else {
                        try {
                            byte b = dis.readByte();
                            if (b != 0) {
                                throw new IllegalStateException(LocalizedStrings.Connection_DETECTED_OLD_VERSION_PRE_501_OF_GEMFIRE_OR_NONGEMFIRE_DURING_HANDSHAKE_DUE_TO_INITIAL_BYTE_BEING_0.toLocalizedString(new Byte(b)));
                            }
                            byte handShakeByte = dis.readByte();
                            if (handShakeByte != HANDSHAKE_VERSION) {
                                throw new IllegalStateException(LocalizedStrings.Connection_DETECTED_WRONG_VERSION_OF_GEMFIRE_PRODUCT_DURING_HANDSHAKE_EXPECTED_0_BUT_FOUND_1.toLocalizedString(new Object[] { new Byte(HANDSHAKE_VERSION), new Byte(handShakeByte) }));
                            }
                            InternalDistributedMember remote = DSFIDFactory.readInternalDistributedMember(dis);
                            setRemoteAddr(remote);
                            this.sharedResource = dis.readBoolean();
                            this.preserveOrder = dis.readBoolean();
                            this.uniqueId = dis.readLong();
                            // read the product version ordinal for on-the-fly serialization
                            // transformations (for rolling upgrades)
                            this.remoteVersion = Version.readVersion(dis, true);
                            int dominoNumber = 0;
                            if (this.remoteVersion == null || (this.remoteVersion.compareTo(Version.GFE_80) >= 0)) {
                                dominoNumber = dis.readInt();
                                if (this.sharedResource) {
                                    dominoNumber = 0;
                                }
                                dominoCount.set(dominoNumber);
                            // this.senderName = dis.readUTF();
                            }
                            if (!this.sharedResource) {
                                if (tipDomino()) {
                                    logger.info(LocalizedMessage.create(LocalizedStrings.Connection_THREAD_OWNED_RECEIVER_FORCING_ITSELF_TO_SEND_ON_THREAD_OWNED_SOCKETS));
                                // bug #49565 - if domino count is >= 2 use shared resources.
                                // Also see DistributedCacheOperation#supportsDirectAck
                                } else {
                                    // if (dominoNumber < 2) {
                                    ConnectionTable.threadWantsOwnResources();
                                    if (logger.isDebugEnabled()) {
                                        logger.debug("thread-owned receiver with domino count of {} will prefer sending on thread-owned sockets", dominoNumber);
                                    }
                                // } else {
                                // ConnectionTable.threadWantsSharedResources();
                                }
                                this.conduit.stats.incThreadOwnedReceivers(1L, dominoNumber);
                                // Because this thread is not shared resource, it will be used for direct
                                // ack. Direct ack messages can be large. This call will resize the send
                                // buffer.
                                setSendBufferSize(this.socket);
                            }
                            // String name = owner.getDM().getConfig().getName();
                            // if (name == null) {
                            // name = "pid="+OSProcess.getId();
                            // }
                            setThreadName(dominoNumber);
                        } catch (Exception e) {
                            // bug 37101
                            this.owner.getConduit().getCancelCriterion().checkCancelInProgress(e);
                            logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_ERROR_DESERIALIZING_P2P_HANDSHAKE_MESSAGE), e);
                            this.readerShuttingDown = true;
                            requestClose(LocalizedStrings.Connection_ERROR_DESERIALIZING_P2P_HANDSHAKE_MESSAGE.toLocalizedString());
                            return;
                        }
                        if (logger.isDebugEnabled()) {
                            logger.debug("P2P handshake remoteAddr is {}{}", this.remoteAddr, (this.remoteVersion != null ? " (" + this.remoteVersion + ')' : ""));
                        }
                        try {
                            String authInit = System.getProperty(DistributionConfigImpl.SECURITY_SYSTEM_PREFIX + SECURITY_PEER_AUTH_INIT);
                            boolean isSecure = authInit != null && authInit.length() != 0;
                            if (isSecure) {
                                if (owner.getConduit().waitForMembershipCheck(this.remoteAddr)) {
                                    // fix for bug 33224
                                    sendOKHandshakeReply();
                                    notifyHandshakeWaiter(true);
                                } else {
                                    // ARB: check if we need notifyHandshakeWaiter() call.
                                    notifyHandshakeWaiter(false);
                                    logger.warn(LocalizedMessage.create(LocalizedStrings.Connection_0_TIMED_OUT_DURING_A_MEMBERSHIP_CHECK, p2pReaderName()));
                                    return;
                                }
                            } else {
                                // fix for bug 33224
                                sendOKHandshakeReply();
                                try {
                                    notifyHandshakeWaiter(true);
                                } catch (Exception e) {
                                    logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_UNCAUGHT_EXCEPTION_FROM_LISTENER), e);
                                }
                            }
                        } catch (IOException ex) {
                            final String err = LocalizedStrings.Connection_FAILED_SENDING_HANDSHAKE_REPLY.toLocalizedString();
                            if (logger.isDebugEnabled()) {
                                logger.debug(err, ex);
                            }
                            this.readerShuttingDown = true;
                            requestClose(err + ": " + ex);
                            return;
                        }
                    }
                }
                if (!connected) {
                    continue;
                }
                accessed();
                nioInputBuffer.limit(oldLimit);
                nioInputBuffer.position(startPos + nioMessageLength);
            } else {
                done = true;
                compactOrResizeBuffer(nioMessageLength);
            }
        } else {
            done = true;
            if (nioInputBuffer.position() != 0) {
                nioInputBuffer.compact();
            } else {
                nioInputBuffer.position(nioInputBuffer.limit());
                nioInputBuffer.limit(nioInputBuffer.capacity());
            }
        }
    }
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) CacheClosedException(org.apache.geode.cache.CacheClosedException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CancelException(org.apache.geode.CancelException) CancelledKeyException(java.nio.channels.CancelledKeyException) InterruptedIOException(java.io.InterruptedIOException) SocketException(java.net.SocketException) CacheClosedException(org.apache.geode.cache.CacheClosedException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) ReplyException(org.apache.geode.distributed.internal.ReplyException) ClosedSelectorException(java.nio.channels.ClosedSelectorException) StringId(org.apache.geode.i18n.StringId) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) CancelException(org.apache.geode.CancelException)

Example 38 with DistributionMessage

use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.

the class MsgReader method readMessage.

/**
   * Block until you can read a message. Returns null if the message was a message chunk.
   * 
   * @return the message, or null if we only received a chunk of the message
   * @throws ClassNotFoundException
   * @throws IOException
   * @throws InterruptedException
   */
public DistributionMessage readMessage(Header header) throws IOException, ClassNotFoundException, InterruptedException {
    ByteBuffer nioInputBuffer = readAtLeast(header.nioMessageLength);
    this.getStats().incMessagesBeingReceived(true, header.nioMessageLength);
    long startSer = this.getStats().startMsgDeserialization();
    try {
        bbis.setBuffer(nioInputBuffer);
        DistributionMessage msg = null;
        ReplyProcessor21.initMessageRPId();
        // add serialization stats
        msg = (DistributionMessage) InternalDataSerializer.readDSFID(bbis);
        return msg;
    } finally {
        this.getStats().endMsgDeserialization(startSer);
        this.getStats().decMessagesBeingReceived(header.nioMessageLength);
    }
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) ByteBuffer(java.nio.ByteBuffer)

Example 39 with DistributionMessage

use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.

the class MsgStreamer method realFlush.

public void realFlush(boolean lastFlushForMessage) {
    if (isOverflowMode()) {
        if (this.overflowBuf == null) {
            this.overflowBuf = new HeapDataOutputStream(this.buffer.capacity() - Connection.MSG_HEADER_BYTES, Version.CURRENT);
        }
        return;
    }
    this.buffer.flip();
    setMessageHeader();
    final int serializedBytes = this.buffer.limit();
    this.flushedBytes += serializedBytes;
    DistributionMessage conflationMsg = null;
    if (this.normalMsg) {
        // we can't conflate chunked messages; this fixes bug 36633
        conflationMsg = this.msg;
    }
    this.stats.endMsgSerialization(this.serStartTime);
    for (Iterator it = this.cons.iterator(); it.hasNext(); ) {
        Connection con = (Connection) it.next();
        try {
            con.sendPreserialized(this.buffer, lastFlushForMessage && this.msg.containsRegionContentChange(), conflationMsg);
        } catch (IOException ex) {
            it.remove();
            if (this.ce == null)
                this.ce = new ConnectExceptions();
            this.ce.addFailure(con.getRemoteAddress(), ex);
            con.closeForReconnect(LocalizedStrings.MsgStreamer_CLOSING_DUE_TO_0.toLocalizedString("IOException"));
        } catch (ConnectionException ex) {
            it.remove();
            if (this.ce == null)
                this.ce = new ConnectExceptions();
            this.ce.addFailure(con.getRemoteAddress(), ex);
            con.closeForReconnect(LocalizedStrings.MsgStreamer_CLOSING_DUE_TO_0.toLocalizedString("ConnectionException"));
        }
        this.buffer.rewind();
    }
    startSerialization();
    this.buffer.clear();
    this.buffer.position(Connection.MSG_HEADER_BYTES);
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) Iterator(java.util.Iterator) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator) IOException(java.io.IOException)

Example 40 with DistributionMessage

use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.

the class TCPConduit method messageReceived.

/**
   * connections send messageReceived when a message object has been read.
   * 
   * @param bytesRead number of bytes read off of network to get this message
   */
protected void messageReceived(Connection receiver, DistributionMessage message, int bytesRead) {
    if (logger.isTraceEnabled()) {
        logger.trace("{} received {} from {}", id, message, receiver);
    }
    if (directChannel != null) {
        DistributionMessage msg = message;
        msg.setBytesRead(bytesRead);
        msg.setSender(receiver.getRemoteAddress());
        msg.setSharedReceiver(receiver.isSharedResource());
        directChannel.receive(msg, bytesRead);
    }
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage)

Aggregations

DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)51 Test (org.junit.Test)34 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)29 DistributionMessageObserver (org.apache.geode.distributed.internal.DistributionMessageObserver)29 VM (org.apache.geode.test.dunit.VM)28 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)28 Host (org.apache.geode.test.dunit.Host)27 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)22 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)13 IOException (java.io.IOException)11 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)11 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)11 Cache (org.apache.geode.cache.Cache)9 IgnoredException (org.apache.geode.test.dunit.IgnoredException)9 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)8 DataInputStream (java.io.DataInputStream)7 RequestImageMessage (org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage)7 Properties (java.util.Properties)6 CacheClosedException (org.apache.geode.cache.CacheClosedException)6 Region (org.apache.geode.cache.Region)6