Search in sources :

Example 6 with ReplyMessage

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

the class AddCacheServerProfileMessage method process.

@Override
protected void process(DistributionManager dm) {
    int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.BEFORE_INITIAL_IMAGE);
    try {
        InternalCache cache = GemFireCacheImpl.getInstance();
        // will be null if not initialized
        if (cache != null && !cache.isClosed()) {
            operateOnCache(cache);
        }
    } finally {
        LocalRegion.setThreadInitLevelRequirement(oldLevel);
        ReplyMessage reply = new ReplyMessage();
        reply.setProcessorId(this.processorId);
        reply.setRecipient(getSender());
        try {
            dm.putOutgoing(reply);
        } catch (CancelException ignore) {
        // can't send a reply, so ignore the exception
        }
    }
}
Also used : CancelException(org.apache.geode.CancelException) ReplyMessage(org.apache.geode.distributed.internal.ReplyMessage)

Example 7 with ReplyMessage

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

the class Connection method readAck.

/**
   * @param msToWait number of milliseconds to wait for an ack. If 0 then wait forever.
   * @param msInterval interval between checks
   * @throws SocketTimeoutException if msToWait expires.
   * @throws ConnectionException if ack is not received (fixes bug 34312)
   */
public void readAck(final int msToWait, final long msInterval, final DirectReplyProcessor processor) throws SocketTimeoutException, ConnectionException {
    if (isSocketClosed()) {
        throw new ConnectionException(LocalizedStrings.Connection_CONNECTION_IS_CLOSED.toLocalizedString());
    }
    synchronized (this.stateLock) {
        this.connectionState = STATE_READING_ACK;
    }
    boolean origSocketInUse = this.socketInUse;
    this.socketInUse = true;
    MsgReader msgReader = null;
    DMStats stats = owner.getConduit().stats;
    final Version version = getRemoteVersion();
    try {
        if (useNIO()) {
            msgReader = new NIOMsgReader(this, version);
        } else {
            msgReader = new OioMsgReader(this, version);
        }
        Header header = msgReader.readHeader();
        ReplyMessage msg;
        int len;
        if (header.getNioMessageType() == NORMAL_MSG_TYPE) {
            msg = (ReplyMessage) msgReader.readMessage(header);
            len = header.getNioMessageLength();
        } else {
            MsgDestreamer destreamer = obtainMsgDestreamer(header.getNioMessageId(), version);
            while (header.getNioMessageType() == CHUNKED_MSG_TYPE) {
                msgReader.readChunk(header, destreamer);
                header = msgReader.readHeader();
            }
            msgReader.readChunk(header, destreamer);
            msg = (ReplyMessage) destreamer.getMessage();
            releaseMsgDestreamer(header.getNioMessageId(), destreamer);
            len = destreamer.size();
        }
        // I'd really just like to call dispatchMessage here. However,
        // that call goes through a bunch of checks that knock about
        // 10% of the performance. Since this direct-ack stuff is all
        // about performance, we'll skip those checks. Skipping them
        // should be legit, because we just sent a message so we know
        // the member is already in our view, etc.
        DistributionManager dm = (DistributionManager) owner.getDM();
        msg.setBytesRead(len);
        msg.setSender(remoteAddr);
        stats.incReceivedMessages(1L);
        stats.incReceivedBytes(msg.getBytesRead());
        stats.incMessageChannelTime(msg.resetTimestamp());
        msg.process(dm, processor);
    // dispatchMessage(msg, len, false);
    } catch (MemberShunnedException e) {
    // do nothing
    } catch (SocketTimeoutException timeout) {
        throw timeout;
    } catch (IOException e) {
        final String err = LocalizedStrings.Connection_ACK_READ_IO_EXCEPTION_FOR_0.toLocalizedString(this);
        if (!isSocketClosed()) {
            if (logger.isDebugEnabled() && !isIgnorableIOException(e)) {
                logger.debug(err, e);
            }
        }
        try {
            requestClose(err + ": " + e);
        } catch (Exception ex) {
        }
        throw new ConnectionException(LocalizedStrings.Connection_UNABLE_TO_READ_DIRECT_ACK_BECAUSE_0.toLocalizedString(e));
    } catch (ConnectionException e) {
        this.owner.getConduit().getCancelCriterion().checkCancelInProgress(e);
        throw e;
    } catch (Exception e) {
        this.owner.getConduit().getCancelCriterion().checkCancelInProgress(e);
        if (!isSocketClosed()) {
            logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_ACK_READ_EXCEPTION), e);
        }
        try {
            requestClose(LocalizedStrings.Connection_ACK_READ_EXCEPTION_0.toLocalizedString(e));
        } catch (Exception ex) {
        }
        throw new ConnectionException(LocalizedStrings.Connection_UNABLE_TO_READ_DIRECT_ACK_BECAUSE_0.toLocalizedString(e));
    } finally {
        stats.incProcessedMessages(1L);
        accessed();
        this.socketInUse = origSocketInUse;
        if (this.ackTimedOut) {
            logger.info(LocalizedMessage.create(LocalizedStrings.Connection_FINISHED_WAITING_FOR_REPLY_FROM_0, new Object[] { getRemoteAddress() }));
            this.ackTimedOut = false;
        }
        if (msgReader != null) {
            msgReader.close();
        }
    }
    synchronized (stateLock) {
        this.connectionState = STATE_RECEIVED_ACK;
    }
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) ReplyMessage(org.apache.geode.distributed.internal.ReplyMessage) 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) SocketTimeoutException(java.net.SocketTimeoutException) Header(org.apache.geode.internal.tcp.MsgReader.Header) Version(org.apache.geode.internal.Version) DistributionManager(org.apache.geode.distributed.internal.DistributionManager)

Example 8 with ReplyMessage

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

the class CheckTypeRegistryState method process.

@Override
protected void process(DistributionManager dm) {
    ReplyException e = null;
    try {
        InternalCache cache = GemFireCacheImpl.getInstance();
        if (cache != null && !cache.isClosed()) {
            TypeRegistry pdxRegistry = cache.getPdxRegistry();
            if (pdxRegistry != null) {
                TypeRegistration registry = pdxRegistry.getTypeRegistration();
                if (registry instanceof PeerTypeRegistration) {
                    PeerTypeRegistration peerRegistry = (PeerTypeRegistration) registry;
                    peerRegistry.verifyConfiguration();
                }
            }
        }
    } catch (Exception ex) {
        e = new ReplyException(ex);
    } finally {
        ReplyMessage rm = new ReplyMessage();
        rm.setException(e);
        rm.setProcessorId(processorId);
        rm.setRecipient(getSender());
        dm.putOutgoing(rm);
    }
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache) ReplyException(org.apache.geode.distributed.internal.ReplyException) PdxInitializationException(org.apache.geode.pdx.PdxInitializationException) IOException(java.io.IOException) ReplyException(org.apache.geode.distributed.internal.ReplyException) ReplyMessage(org.apache.geode.distributed.internal.ReplyMessage)

Example 9 with ReplyMessage

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

the class DataTypeJUnitTest method testDataSerializableFixedIDByte.

@Test
public void testDataSerializableFixedIDByte() throws IOException {
    DataSerializableFixedID value = new ReplyMessage();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(baos);
    InternalDataSerializer.writeDSFID(value, out);
    byte[] bytes = baos.toByteArray();
    String type = DataType.getDataType(bytes);
    assertEquals("org.apache.geode.internal.DataSerializableFixedID:" + ReplyMessage.class.getName(), type);
}
Also used : DataOutputStream(java.io.DataOutputStream) DataSerializableFixedID(org.apache.geode.internal.DataSerializableFixedID) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ReplyMessage(org.apache.geode.distributed.internal.ReplyMessage) UnitTest(org.apache.geode.test.junit.categories.UnitTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with ReplyMessage

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

the class FunctionStreamingResultCollector method process.

@Override
public void process(DistributionMessage msg) {
    if (!waitingOnMember(msg.getSender())) {
        return;
    }
    this.msgsBeingProcessed.incrementAndGet();
    try {
        ReplyMessage m = (ReplyMessage) msg;
        if (m.getException() == null) {
            FunctionStreamingReplyMessage functionReplyMsg = (FunctionStreamingReplyMessage) m;
            Object result = functionReplyMsg.getResult();
            boolean isLast = false;
            synchronized (processSingleResult) {
                isLast = trackMessage(functionReplyMsg);
                this.functionResultWaiter.processData(result, isLast, msg.getSender());
            }
            if (isLast) {
                // removes from members and cause us
                super.process(msg, false);
            // to ignore future messages received from that member
            }
        } else {
            if (execution.forwardExceptions || (execution.waitOnException)) {
                // send BucketMovedException forward which will be handled by LocalResultCollectorImpl
                synchronized (processSingleResult) {
                    this.functionResultWaiter.processData(m.getException().getCause(), true, msg.getSender());
                }
            }
            super.process(msg, false);
        }
    } finally {
        this.msgsBeingProcessed.decrementAndGet();
        // check to see if decrementing msgsBeingProcessed requires signalling to
        checkIfDone();
    // proceed
    }
}
Also used : FunctionStreamingReplyMessage(org.apache.geode.internal.cache.FunctionStreamingReplyMessage) ReplyMessage(org.apache.geode.distributed.internal.ReplyMessage) FunctionStreamingReplyMessage(org.apache.geode.internal.cache.FunctionStreamingReplyMessage)

Aggregations

ReplyMessage (org.apache.geode.distributed.internal.ReplyMessage)13 ReplyException (org.apache.geode.distributed.internal.ReplyException)8 CancelException (org.apache.geode.CancelException)7 Cache (org.apache.geode.cache.Cache)4 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)4 Region (org.apache.geode.cache.Region)3 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)3 LocalRegion (org.apache.geode.internal.cache.LocalRegion)3 Bucket (org.apache.geode.internal.cache.partitioned.Bucket)3 IOException (java.io.IOException)2 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)2 InternalCache (org.apache.geode.internal.cache.InternalCache)2 Test (org.junit.Test)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 InterruptedIOException (java.io.InterruptedIOException)1 ConnectException (java.net.ConnectException)1 SocketException (java.net.SocketException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 CancelledKeyException (java.nio.channels.CancelledKeyException)1