Search in sources :

Example 1 with Message

use of org.apache.geode.internal.cache.tier.sockets.Message in project geode by apache.

the class CommitCommandTest method testWriteNullResponse.

/**
   * Test for GEODE-537 No NPE should be thrown from the
   * {@link CommitCommand#writeCommitResponse(org.apache.geode.internal.cache.TXCommitMessage, Message, ServerConnection)}
   * if the response message is null as it is the case when JTA transaction is rolled back with
   * TX_SYNCHRONIZATION AFTER_COMPLETION STATUS_ROLLEDBACK
   */
@Test
public void testWriteNullResponse() throws Exception {
    InternalCache cache = mock(InternalCache.class);
    Message origMsg = mock(Message.class);
    ServerConnection servConn = mock(ServerConnection.class);
    when(servConn.getResponseMessage()).thenReturn(mock(Message.class));
    when(servConn.getCache()).thenReturn(cache);
    when(cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class));
    CommitCommand.writeCommitResponse(null, origMsg, servConn);
}
Also used : Message(org.apache.geode.internal.cache.tier.sockets.Message) CancelCriterion(org.apache.geode.CancelCriterion) InternalCache(org.apache.geode.internal.cache.InternalCache) ServerConnection(org.apache.geode.internal.cache.tier.sockets.ServerConnection) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 2 with Message

use of org.apache.geode.internal.cache.tier.sockets.Message in project geode by apache.

the class Destroy65 method writeReply.

protected void writeReply(Message origMsg, ServerConnection servConn, boolean entryNotFound, VersionTag tag) throws IOException {
    Message replyMsg = servConn.getReplyMessage();
    servConn.getCache().getCancelCriterion().checkCancelInProgress(null);
    replyMsg.setMessageType(MessageType.REPLY);
    replyMsg.setNumberOfParts(2);
    replyMsg.setTransactionId(origMsg.getTransactionId());
    replyMsg.addBytesPart(okBytes());
    replyMsg.addIntPart(entryNotFound ? 1 : 0);
    replyMsg.send(servConn);
    if (logger.isTraceEnabled()) {
        logger.trace("{}: rpl tx: {} parts={}", servConn.getName(), origMsg.getTransactionId(), replyMsg.getNumberOfParts());
    }
}
Also used : Message(org.apache.geode.internal.cache.tier.sockets.Message) LocalizedMessage(org.apache.geode.internal.logging.log4j.LocalizedMessage)

Example 3 with Message

use of org.apache.geode.internal.cache.tier.sockets.Message in project geode by apache.

the class Destroy70 method writeReplyWithRefreshMetadata.

@Override
protected void writeReplyWithRefreshMetadata(Message origMsg, ServerConnection servConn, PartitionedRegion pr, boolean entryNotFoundForRemove, byte nwHop, VersionTag versionTag) throws IOException {
    Message replyMsg = servConn.getReplyMessage();
    servConn.getCache().getCancelCriterion().checkCancelInProgress(null);
    replyMsg.setMessageType(MessageType.REPLY);
    int flags = 0;
    int numParts = 3;
    if (versionTag != null) {
        flags |= DestroyOp.HAS_VERSION_TAG;
        numParts++;
    }
    flags |= DestroyOp.HAS_ENTRY_NOT_FOUND_PART;
    // if (logger.isDebugEnabled()) {
    // logger.fine("writing response with metadata and " + numParts + " parts");
    // }
    replyMsg.setNumberOfParts(numParts);
    replyMsg.setTransactionId(origMsg.getTransactionId());
    replyMsg.addIntPart(flags);
    if (versionTag != null) {
        replyMsg.addObjPart(versionTag);
    }
    replyMsg.addBytesPart(new byte[] { pr.getMetadataVersion(), nwHop });
    replyMsg.addIntPart(entryNotFoundForRemove ? 1 : 0);
    pr.getPrStats().incPRMetaDataSentCount();
    replyMsg.send(servConn);
    if (logger.isTraceEnabled()) {
        logger.trace("{}: rpl with REFRESH_METADATA tx: {}", servConn.getName(), origMsg.getTransactionId());
    }
}
Also used : Message(org.apache.geode.internal.cache.tier.sockets.Message)

Example 4 with Message

use of org.apache.geode.internal.cache.tier.sockets.Message in project geode by apache.

the class Destroy70 method writeReply.

@Override
protected void writeReply(Message origMsg, ServerConnection servConn, boolean entryNotFound, VersionTag versionTag) throws IOException {
    if (logger.isDebugEnabled()) {
        logger.debug("Destroy70.writeReply(entryNotFound={}, tag={})", entryNotFound, versionTag);
    }
    Message replyMsg = servConn.getReplyMessage();
    servConn.getCache().getCancelCriterion().checkCancelInProgress(null);
    replyMsg.setMessageType(MessageType.REPLY);
    int flags = 0;
    int numParts = 3;
    if (versionTag != null) {
        flags |= DestroyOp.HAS_VERSION_TAG;
        numParts++;
    }
    flags |= DestroyOp.HAS_ENTRY_NOT_FOUND_PART;
    // if (logger.isDebugEnabled()) {
    // logger.fine("writing response with 1-byte metadata and " + numParts + " parts");
    // }
    replyMsg.setNumberOfParts(numParts);
    replyMsg.setTransactionId(origMsg.getTransactionId());
    replyMsg.addIntPart(flags);
    if (versionTag != null) {
        // if (logger.isDebugEnabled()) {
        // logger.fine("wrote version tag in response: " + versionTag);
        // }
        replyMsg.addObjPart(versionTag);
    // } else {
    // if (logger.isDebugEnabled()) {
    // logger.fine("response has no version tag");
    // }
    }
    // make old single-hop code happy by puting byte[]{0} here
    replyMsg.addBytesPart(okBytes());
    replyMsg.addIntPart(entryNotFound ? 1 : 0);
    replyMsg.send(servConn);
    if (logger.isTraceEnabled()) {
        logger.trace("{}: rpl tx: {} parts={}", servConn.getName(), origMsg.getTransactionId(), replyMsg.getNumberOfParts());
    }
}
Also used : Message(org.apache.geode.internal.cache.tier.sockets.Message)

Example 5 with Message

use of org.apache.geode.internal.cache.tier.sockets.Message in project geode by apache.

the class GatewayReceiverCommand method writeFatalException.

private static void writeFatalException(Message origMsg, Throwable exception, ServerConnection servConn, int batchId) throws IOException {
    Message errorMsg = servConn.getErrorResponseMessage();
    errorMsg.setMessageType(MessageType.EXCEPTION);
    errorMsg.setNumberOfParts(2);
    errorMsg.setTransactionId(origMsg.getTransactionId());
    // they can deserialize.
    if ((servConn.getClientVersion() == null || servConn.getClientVersion().compareTo(Version.GFE_80) < 0) && exception instanceof PdxRegistryMismatchException) {
        PdxConfigurationException newException = new PdxConfigurationException(exception.getMessage());
        newException.setStackTrace(exception.getStackTrace());
        exception = newException;
    }
    errorMsg.addObjPart(exception);
    // errorMsg.addStringPart(be.toString());
    errorMsg.send(servConn);
    logger.warn(LocalizedMessage.create(LocalizedStrings.ProcessBatch_0_WROTE_BATCH_EXCEPTION, servConn.getName()), exception);
}
Also used : Message(org.apache.geode.internal.cache.tier.sockets.Message) LocalizedMessage(org.apache.geode.internal.logging.log4j.LocalizedMessage) PdxRegistryMismatchException(org.apache.geode.pdx.PdxRegistryMismatchException) PdxConfigurationException(org.apache.geode.pdx.PdxConfigurationException)

Aggregations

Message (org.apache.geode.internal.cache.tier.sockets.Message)33 LocalizedMessage (org.apache.geode.internal.logging.log4j.LocalizedMessage)16 IOException (java.io.IOException)11 InternalCache (org.apache.geode.internal.cache.InternalCache)7 Region (org.apache.geode.cache.Region)4 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)4 TypeRegistry (org.apache.geode.pdx.internal.TypeRegistry)4 EnumInfo (org.apache.geode.pdx.internal.EnumInfo)3 PdxType (org.apache.geode.pdx.internal.PdxType)3 List (java.util.List)2 Cache (org.apache.geode.cache.Cache)2 PartitionResolver (org.apache.geode.cache.PartitionResolver)2 BucketServerLocation66 (org.apache.geode.internal.cache.BucketServerLocation66)2 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)2 PdxConfigurationException (org.apache.geode.pdx.PdxConfigurationException)2 PdxRegistryMismatchException (org.apache.geode.pdx.PdxRegistryMismatchException)2 ArrayList (java.util.ArrayList)1 CancelCriterion (org.apache.geode.CancelCriterion)1 CancelException (org.apache.geode.CancelException)1 CacheClosedException (org.apache.geode.cache.CacheClosedException)1