Search in sources :

Example 6 with AsyncEvent

use of org.apache.geode.cache.asyncqueue.AsyncEvent in project geode by apache.

the class SerialGatewaySenderQueue method initializeRegion.

/**
   * Initializes the <code>Region</code> backing this queue. The <code>Region</code>'s scope is
   * DISTRIBUTED_NO_ACK and mirror type is KEYS_VALUES and is set to overflow to disk based on the
   * <code>GatewayQueueAttributes</code>.
   * 
   * @param sender The GatewaySender <code>SerialGatewaySenderImpl</code>
   * @param listener The GemFire <code>CacheListener</code>. The <code>CacheListener</code> can be
   *        null.
   */
@SuppressWarnings({ "unchecked", "rawtypes" })
private void initializeRegion(AbstractGatewaySender sender, CacheListener listener) {
    final InternalCache gemCache = sender.getCache();
    this.region = gemCache.getRegion(this.regionName);
    if (this.region == null) {
        AttributesFactory<Long, AsyncEvent> factory = new AttributesFactory<Long, AsyncEvent>();
        factory.setScope(NO_ACK ? Scope.DISTRIBUTED_NO_ACK : Scope.DISTRIBUTED_ACK);
        factory.setDataPolicy(this.enablePersistence ? DataPolicy.PERSISTENT_REPLICATE : DataPolicy.REPLICATE);
        if (logger.isDebugEnabled()) {
            logger.debug("The policy of region is {}", (this.enablePersistence ? DataPolicy.PERSISTENT_REPLICATE : DataPolicy.REPLICATE));
        }
        // when the user of this queue is a secondary VM.
        if (listener != null) {
            factory.addCacheListener(listener);
        }
        // allow for no overflow directory
        EvictionAttributes ea = EvictionAttributes.createLIFOMemoryAttributes(this.maximumQueueMemory, EvictionAction.OVERFLOW_TO_DISK);
        factory.setEvictionAttributes(ea);
        factory.setConcurrencyChecksEnabled(false);
        factory.setDiskStoreName(this.diskStoreName);
        // In case of persistence write to disk sync and in case of eviction write in async
        factory.setDiskSynchronous(this.isDiskSynchronous);
        // Create the region
        if (logger.isDebugEnabled()) {
            logger.debug("{}: Attempting to create queue region: {}", this, this.regionName);
        }
        final RegionAttributes<Long, AsyncEvent> ra = factory.create();
        try {
            SerialGatewaySenderQueueMetaRegion meta = new SerialGatewaySenderQueueMetaRegion(this.regionName, ra, null, gemCache, sender);
            try {
                this.region = gemCache.createVMRegion(this.regionName, ra, new InternalRegionArguments().setInternalMetaRegion(meta).setDestroyLockFlag(true).setSnapshotInputStream(null).setImageTarget(null).setIsUsedForSerialGatewaySenderQueue(true).setInternalRegion(true).setSerialGatewaySender(sender));
            } catch (IOException veryUnLikely) {
                logger.fatal(LocalizedMessage.create(LocalizedStrings.SingleWriteSingleReadRegionQueue_UNEXPECTED_EXCEPTION_DURING_INIT_OF_0, this.getClass()), veryUnLikely);
            } catch (ClassNotFoundException alsoUnlikely) {
                logger.fatal(LocalizedMessage.create(LocalizedStrings.SingleWriteSingleReadRegionQueue_UNEXPECTED_EXCEPTION_DURING_INIT_OF_0, this.getClass()), alsoUnlikely);
            }
            if (logger.isDebugEnabled()) {
                logger.debug("{}: Created queue region: {}", this, this.region);
            }
        } catch (CacheException e) {
            logger.fatal(LocalizedMessage.create(LocalizedStrings.SingleWriteSingleReadRegionQueue_0_THE_QUEUE_REGION_NAMED_1_COULD_NOT_BE_CREATED, new Object[] { this, this.regionName }), e);
        }
    } else {
        throw new IllegalStateException("Queue region " + this.region.getFullPath() + " already exists.");
    }
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) CacheException(org.apache.geode.cache.CacheException) InternalCache(org.apache.geode.internal.cache.InternalCache) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) IOException(java.io.IOException) AsyncEvent(org.apache.geode.cache.asyncqueue.AsyncEvent) AttributesFactory(org.apache.geode.cache.AttributesFactory) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 7 with AsyncEvent

use of org.apache.geode.cache.asyncqueue.AsyncEvent in project geode by apache.

the class SerialGatewaySenderQueue method optimalGet.

/**
   * Does a get that gets the value without fault values in from disk.
   */
private AsyncEvent optimalGet(Long k) {
    // Get the object at that key (to remove the index).
    LocalRegion lr = (LocalRegion) this.region;
    Object o = null;
    try {
        o = lr.getValueInVMOrDiskWithoutFaultIn(k);
        if (o != null && o instanceof CachedDeserializable) {
            o = ((CachedDeserializable) o).getDeserializedValue(lr, lr.getRegionEntry(k));
        }
    } catch (EntryNotFoundException ok) {
    // just return null;
    }
    // bug #46023 do not return a destroyed entry marker
    if (o == Token.TOMBSTONE) {
        o = null;
    }
    return (AsyncEvent) o;
}
Also used : CachedDeserializable(org.apache.geode.internal.cache.CachedDeserializable) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) AsyncEvent(org.apache.geode.cache.asyncqueue.AsyncEvent)

Example 8 with AsyncEvent

use of org.apache.geode.cache.asyncqueue.AsyncEvent in project geode by apache.

the class SerialGatewaySenderQueue method getObjectInSerialSenderQueue.

private AsyncEvent getObjectInSerialSenderQueue(Long currentKey) {
    AsyncEvent object = optimalGet(currentKey);
    if ((null != object) && logger.isDebugEnabled()) {
        logger.debug("{}: Peeked {}->{}", this, currentKey, object);
    }
    if (object != null && object instanceof GatewaySenderEventImpl) {
        GatewaySenderEventImpl copy = ((GatewaySenderEventImpl) object).makeHeapCopyIfOffHeap();
        if (copy == null) {
            logger.debug("Unable to make heap copy and will not be added to peekedIds for object" + " : {} ", object.toString());
        }
        object = copy;
    }
    return object;
}
Also used : GatewaySenderEventImpl(org.apache.geode.internal.cache.wan.GatewaySenderEventImpl) AsyncEvent(org.apache.geode.cache.asyncqueue.AsyncEvent)

Example 9 with AsyncEvent

use of org.apache.geode.cache.asyncqueue.AsyncEvent in project geode by apache.

the class LuceneEventListenerJUnitTest method shouldThrowAndCaptureIOException.

@Test
public void shouldThrowAndCaptureIOException() throws BucketNotFoundException {
    RepositoryManager manager = Mockito.mock(RepositoryManager.class);
    Mockito.when(manager.getRepository(any(), any(), any())).thenThrow(IOException.class);
    AtomicReference<Throwable> lastException = new AtomicReference<>();
    LuceneEventListener.setExceptionObserver(lastException::set);
    LuceneEventListener listener = new LuceneEventListener(manager);
    AsyncEvent event = Mockito.mock(AsyncEvent.class);
    try {
        listener.processEvents(Arrays.asList(new AsyncEvent[] { event }));
        fail("should have thrown an exception");
    } catch (InternalGemFireError expected) {
        assertEquals(expected, lastException.get());
    }
}
Also used : RepositoryManager(org.apache.geode.cache.lucene.internal.repository.RepositoryManager) AtomicReference(java.util.concurrent.atomic.AtomicReference) AsyncEvent(org.apache.geode.cache.asyncqueue.AsyncEvent) InternalGemFireError(org.apache.geode.InternalGemFireError) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 10 with AsyncEvent

use of org.apache.geode.cache.asyncqueue.AsyncEvent in project geode by apache.

the class MyGatewayEventSubstitutionFilter method validateAsyncEventForOperationDetail.

public static void validateAsyncEventForOperationDetail(String asyncQueueId, final int expectedSize, boolean isLoad, boolean isPutAll) {
    AsyncEventListener theListener = null;
    Set<AsyncEventQueue> asyncEventQueues = cache.getAsyncEventQueues();
    for (AsyncEventQueue asyncQueue : asyncEventQueues) {
        if (asyncQueueId.equals(asyncQueue.getId())) {
            theListener = asyncQueue.getAsyncEventListener();
        }
    }
    final Map eventsMap = ((MyAsyncEventListener_CacheLoader) theListener).getEventsMap();
    assertNotNull(eventsMap);
    WaitCriterion wc = new WaitCriterion() {

        public boolean done() {
            if (eventsMap.size() == expectedSize) {
                return true;
            }
            return false;
        }

        public String description() {
            return "Expected map entries: " + expectedSize + " but actual entries: " + eventsMap.size();
        }
    };
    // TODO:Yogs
    Wait.waitForCriterion(wc, 60000, 500, true);
    Collection values = eventsMap.values();
    Iterator itr = values.iterator();
    while (itr.hasNext()) {
        AsyncEvent asyncEvent = (AsyncEvent) itr.next();
        if (isLoad)
            assertTrue(asyncEvent.getOperation().isLoad());
        if (isPutAll)
            assertTrue(asyncEvent.getOperation().isPutAll());
    }
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) Iterator(java.util.Iterator) Collection(java.util.Collection) AsyncEvent(org.apache.geode.cache.asyncqueue.AsyncEvent) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener)

Aggregations

AsyncEvent (org.apache.geode.cache.asyncqueue.AsyncEvent)16 AsyncEventListener (org.apache.geode.cache.asyncqueue.AsyncEventListener)4 IOException (java.io.IOException)3 AsyncEventQueue (org.apache.geode.cache.asyncqueue.AsyncEventQueue)3 RepositoryManager (org.apache.geode.cache.lucene.internal.repository.RepositoryManager)3 UnitTest (org.apache.geode.test.junit.categories.UnitTest)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 InternalGemFireError (org.apache.geode.InternalGemFireError)2 AttributesFactory (org.apache.geode.cache.AttributesFactory)2 Cache (org.apache.geode.cache.Cache)2 Region (org.apache.geode.cache.Region)2 IndexRepository (org.apache.geode.cache.lucene.internal.repository.IndexRepository)2 BucketNotFoundException (org.apache.geode.internal.cache.BucketNotFoundException)2 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)2 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)2