Search in sources :

Example 1 with ReplyMessage

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

the class BackupDUnitTest method testBackupWhileBucketIsMovedBackupAfterSendDestroy.

@Test
public void testBackupWhileBucketIsMovedBackupAfterSendDestroy() throws Throwable {
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final VM vm2 = host.getVM(2);
    DistributionMessageObserver observer = new SerializableDistributionMessageObserver() {

        private volatile boolean done;

        private AtomicInteger count = new AtomicInteger();

        private volatile int replyId = -0xBAD;

        @Override
        public void beforeSendMessage(DistributionManager dm, DistributionMessage msg) {
            // The bucket move will send a destroy region message.
            if (msg instanceof DestroyRegionOperation.DestroyRegionMessage && !done) {
                this.replyId = msg.getProcessorId();
            }
        }

        @Override
        public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
            if (message instanceof ReplyMessage && replyId != -0xBAD && replyId == message.getProcessorId() && !done && // we need two replies
            count.incrementAndGet() == 2) {
                backup(vm2);
                done = true;
            }
        }
    };
    backupWhileBucketIsMoved(observer);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) ReplyMessage(org.apache.geode.distributed.internal.ReplyMessage) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 2 with ReplyMessage

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

the class ReleaseClearLockMessage method process.

@Override
protected void process(DistributionManager dm) {
    ReplyException exception = null;
    try {
        DistributedRegion region = DistributedClearOperation.regionUnlocked(getSender(), regionPath);
        if (region != null && region.getVersionVector() != null) {
            region.getVersionVector().unlockForClear(getSender());
        }
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable t) {
        SystemFailure.checkFailure();
        exception = new ReplyException(t);
    } finally {
        ReplyMessage replyMsg = new ReplyMessage();
        replyMsg.setProcessorId(processorId);
        replyMsg.setRecipient(getSender());
        if (exception != null) {
            replyMsg.setException(exception);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Received {}, replying with {}", this, replyMsg);
        }
        dm.putOutgoing(replyMsg);
    }
}
Also used : ReplyException(org.apache.geode.distributed.internal.ReplyException) ReplyMessage(org.apache.geode.distributed.internal.ReplyMessage)

Example 3 with ReplyMessage

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

the class PrepareNewPersistentMemberMessage method process.

@Override
protected void process(DistributionManager dm) {
    // Set thread local flag to allow entrance through initialization Latch
    int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.ANY_INIT);
    PersistentMemberState state = null;
    PersistentMemberID myId = null;
    ReplyException exception = null;
    try {
        // get the region from the path, but do NOT wait on initialization,
        // otherwise we could have a distributed deadlock
        Cache cache = CacheFactory.getInstance(dm.getSystem());
        Region region = cache.getRegion(this.regionPath);
        PersistenceAdvisor persistenceAdvisor = null;
        if (region instanceof DistributedRegion) {
            persistenceAdvisor = ((DistributedRegion) region).getPersistenceAdvisor();
        } else if (region == null) {
            Bucket proxy = PartitionedRegionHelper.getProxyBucketRegion(GemFireCacheImpl.getInstance(), this.regionPath, false);
            if (proxy != null) {
                persistenceAdvisor = proxy.getPersistenceAdvisor();
            }
        }
        if (persistenceAdvisor != null) {
            persistenceAdvisor.prepareNewMember(getSender(), oldId, newId);
        }
    } catch (RegionDestroyedException e) {
        logger.debug("<RegionDestroyed> {}", this);
    } catch (CancelException e) {
        logger.debug("<CancelException> {}", this);
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable t) {
        SystemFailure.checkFailure();
        exception = new ReplyException(t);
    } finally {
        LocalRegion.setThreadInitLevelRequirement(oldLevel);
        ReplyMessage replyMsg = new ReplyMessage();
        replyMsg.setRecipient(getSender());
        replyMsg.setProcessorId(processorId);
        if (exception != null) {
            replyMsg.setException(exception);
        }
        dm.putOutgoing(replyMsg);
    }
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) ReplyException(org.apache.geode.distributed.internal.ReplyException) ReplyMessage(org.apache.geode.distributed.internal.ReplyMessage) Bucket(org.apache.geode.internal.cache.partitioned.Bucket) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) CancelException(org.apache.geode.CancelException) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Cache(org.apache.geode.cache.Cache)

Example 4 with ReplyMessage

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

the class RemovePersistentMemberMessage method process.

@Override
protected void process(DistributionManager dm) {
    // Set thread local flag to allow entrance through initialization Latch
    int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.ANY_INIT);
    PersistentMemberState state = null;
    PersistentMemberID myId = null;
    ReplyException exception = null;
    try {
        // get the region from the path, but do NOT wait on initialization,
        // otherwise we could have a distributed deadlock
        Cache cache = CacheFactory.getInstance(dm.getSystem());
        Region region = cache.getRegion(this.regionPath);
        PersistenceAdvisor persistenceAdvisor = null;
        if (region instanceof DistributedRegion) {
            persistenceAdvisor = ((DistributedRegion) region).getPersistenceAdvisor();
        } else if (region == null) {
            Bucket proxy = PartitionedRegionHelper.getProxyBucketRegion(GemFireCacheImpl.getInstance(), this.regionPath, false);
            if (proxy != null) {
                persistenceAdvisor = proxy.getPersistenceAdvisor();
            }
        }
        if (persistenceAdvisor != null) {
            if (id != null) {
                persistenceAdvisor.removeMember(id);
            }
            if (initializingId != null) {
                persistenceAdvisor.removeMember(initializingId);
            }
        }
    } catch (RegionDestroyedException e) {
        logger.debug("<RegionDestroyed> {}", this);
    } catch (CancelException e) {
        logger.debug("<CancelException> {}", this);
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable t) {
        SystemFailure.checkFailure();
        exception = new ReplyException(t);
    } finally {
        LocalRegion.setThreadInitLevelRequirement(oldLevel);
        ReplyMessage replyMsg = new ReplyMessage();
        replyMsg.setRecipient(getSender());
        replyMsg.setProcessorId(processorId);
        if (exception != null) {
            replyMsg.setException(exception);
        }
        dm.putOutgoing(replyMsg);
    }
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) ReplyException(org.apache.geode.distributed.internal.ReplyException) ReplyMessage(org.apache.geode.distributed.internal.ReplyMessage) Bucket(org.apache.geode.internal.cache.partitioned.Bucket) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) CancelException(org.apache.geode.CancelException) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Cache(org.apache.geode.cache.Cache)

Example 5 with ReplyMessage

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

the class ServerInterestRegistrationMessage method process.

@Override
protected void process(DistributionManager dm) {
    // Get the proxy for the proxy id
    try {
        CacheClientNotifier clientNotifier = CacheClientNotifier.getInstance();
        if (clientNotifier != null) {
            CacheClientProxy proxy = clientNotifier.getClientProxy(this.clientId);
            // message on to the proxy for processing
            if (proxy != null) {
                proxy.processInterestMessage(this.clientMessage);
            }
        }
    } finally {
        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)

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