Search in sources :

Example 11 with ReplyMessage

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

the class MembershipFlushRequest method process.

@Override
protected void process(DistributionManager dm) {
    int initLevel = LocalRegion.ANY_INIT;
    int oldLevel = LocalRegion.setThreadInitLevelRequirement(initLevel);
    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());
        PartitionedRegion region = (PartitionedRegion) cache.getRegion(this.regionPath);
        if (region != null && region.getRegionAdvisor().isInitialized()) {
            ProxyBucketRegion[] proxyBuckets = region.getRegionAdvisor().getProxyBucketArray();
            // buckets are null if initPRInternals is still not complete
            if (proxyBuckets != null) {
                for (ProxyBucketRegion bucket : proxyBuckets) {
                    final BucketPersistenceAdvisor persistenceAdvisor = bucket.getPersistenceAdvisor();
                    if (persistenceAdvisor != null) {
                        persistenceAdvisor.flushMembershipChanges();
                    }
                }
            }
        }
    } catch (RegionDestroyedException e) {
    // ignore
    } catch (CancelException e) {
    // ignore
    } 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 : BucketPersistenceAdvisor(org.apache.geode.internal.cache.BucketPersistenceAdvisor) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) ProxyBucketRegion(org.apache.geode.internal.cache.ProxyBucketRegion) CancelException(org.apache.geode.CancelException) ReplyException(org.apache.geode.distributed.internal.ReplyException) ReplyMessage(org.apache.geode.distributed.internal.ReplyMessage) Cache(org.apache.geode.cache.Cache)

Example 12 with ReplyMessage

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

the class PersistentStateQueryMessage 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;
    PersistentMemberID myInitializingId = null;
    DiskStoreID diskStoreId = null;
    HashSet<PersistentMemberID> onlineMembers = null;
    ReplyException exception = null;
    boolean successfulReply = false;
    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) {
                state = persistenceAdvisor.getPersistedStateOfMember(id);
            }
            if (initializingId != null && state == null) {
                state = persistenceAdvisor.getPersistedStateOfMember(initializingId);
            }
            myId = persistenceAdvisor.getPersistentID();
            myInitializingId = persistenceAdvisor.getInitializingID();
            onlineMembers = persistenceAdvisor.getPersistedOnlineOrEqualMembers();
            diskStoreId = persistenceAdvisor.getDiskStoreID();
            successfulReply = true;
        }
    } 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;
        if (successfulReply) {
            PersistentStateQueryReplyMessage persistentReplyMessage = new PersistentStateQueryReplyMessage();
            persistentReplyMessage.myId = myId;
            persistentReplyMessage.persistedStateOfPeer = state;
            persistentReplyMessage.myInitializingId = myInitializingId;
            persistentReplyMessage.diskStoreId = diskStoreId;
            persistentReplyMessage.onlineMembers = onlineMembers;
            replyMsg = persistentReplyMessage;
        } else {
            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 : 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 13 with ReplyMessage

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

the class DestroyLuceneIndexMessage method process.

@Override
protected void process(DistributionManager dm) {
    ReplyException replyException = null;
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("DestroyLuceneIndexMessage: Destroying regionPath=" + this.regionPath + "; indexName=" + this.indexName);
        }
        try {
            InternalCache cache = GemFireCacheImpl.getInstance();
            LuceneServiceImpl impl = (LuceneServiceImpl) LuceneServiceProvider.get(cache);
            impl.destroyIndex(this.indexName, this.regionPath, false);
            if (logger.isDebugEnabled()) {
                logger.debug("DestroyLuceneIndexMessage: Destroyed regionPath=" + this.regionPath + "; indexName=" + this.indexName);
            }
        } catch (Throwable e) {
            replyException = new ReplyException(e);
            if (logger.isDebugEnabled()) {
                logger.debug("DestroyLuceneIndexMessage: Caught the following exception attempting to destroy indexName=" + this.indexName + "; regionPath=" + this.regionPath + ":", e);
            }
        }
    } finally {
        ReplyMessage replyMsg = new ReplyMessage();
        replyMsg.setRecipient(getSender());
        replyMsg.setProcessorId(this.processorId);
        if (replyException != null) {
            replyMsg.setException(replyException);
        }
        dm.putOutgoing(replyMsg);
    }
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache) ReplyException(org.apache.geode.distributed.internal.ReplyException) 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