Search in sources :

Example 26 with Conflatable

use of org.apache.geode.internal.cache.Conflatable in project geode by apache.

the class CacheClientNotifier method singletonNotifyClients.

private void singletonNotifyClients(InternalCacheEvent event, ClientUpdateMessage cmsg) {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    final boolean isTraceEnabled = logger.isTraceEnabled();
    FilterInfo filterInfo = event.getLocalFilterInfo();
    FilterProfile regionProfile = ((LocalRegion) event.getRegion()).getFilterProfile();
    if (filterInfo != null) {
        // if the routing was made using an old profile we need to recompute it
        if (isTraceEnabled) {
            logger.trace("Event isOriginRemote={}", event.isOriginRemote());
        }
    }
    if ((filterInfo == null || (filterInfo.getCQs() == null && filterInfo.getInterestedClients() == null && filterInfo.getInterestedClientsInv() == null))) {
        return;
    }
    long startTime = this.statistics.startTime();
    ClientUpdateMessageImpl clientMessage;
    if (cmsg == null) {
        clientMessage = constructClientMessage(event);
    } else {
        clientMessage = (ClientUpdateMessageImpl) cmsg;
    }
    if (clientMessage == null) {
        return;
    }
    // Holds the clientIds to which filter message needs to be sent.
    Set<ClientProxyMembershipID> filterClients = new HashSet();
    // Add CQ info.
    if (filterInfo.getCQs() != null) {
        for (Map.Entry<Long, Integer> e : filterInfo.getCQs().entrySet()) {
            Long cqID = e.getKey();
            String cqName = regionProfile.getRealCqID(cqID);
            if (cqName == null) {
                continue;
            }
            ServerCQ cq = regionProfile.getCq(cqName);
            if (cq != null) {
                ClientProxyMembershipID id = cq.getClientProxyId();
                filterClients.add(id);
                if (isDebugEnabled) {
                    logger.debug("Adding cq routing info to message for id: {} and cq: {}", id, cqName);
                }
                clientMessage.addClientCq(id, cq.getName(), e.getValue());
            }
        }
    }
    // Add interestList info.
    if (filterInfo.getInterestedClientsInv() != null) {
        Set<Object> rawIDs = regionProfile.getRealClientIDs(filterInfo.getInterestedClientsInv());
        Set<ClientProxyMembershipID> ids = getProxyIDs(rawIDs, true);
        if (ids.remove(event.getContext())) {
            // don't send to member of origin
            CacheClientProxy ccp = getClientProxy(event.getContext());
            if (ccp != null) {
                ccp.getStatistics().incMessagesNotQueuedOriginator();
            }
        }
        if (!ids.isEmpty()) {
            if (isTraceEnabled) {
                logger.trace("adding invalidation routing to message for {}", ids);
            }
            clientMessage.addClientInterestList(ids, false);
            filterClients.addAll(ids);
        }
    }
    if (filterInfo.getInterestedClients() != null) {
        Set<Object> rawIDs = regionProfile.getRealClientIDs(filterInfo.getInterestedClients());
        Set<ClientProxyMembershipID> ids = getProxyIDs(rawIDs, true);
        if (ids.remove(event.getContext())) {
            // don't send to member of origin
            CacheClientProxy ccp = getClientProxy(event.getContext());
            if (ccp != null) {
                ccp.getStatistics().incMessagesNotQueuedOriginator();
            }
        }
        if (!ids.isEmpty()) {
            if (isTraceEnabled) {
                logger.trace("adding routing to message for {}", ids);
            }
            clientMessage.addClientInterestList(ids, true);
            filterClients.addAll(ids);
        }
    }
    Conflatable conflatable = null;
    if (clientMessage instanceof ClientTombstoneMessage) {
        // bug #46832 - HAEventWrapper deserialization can't handle subclasses
        // of ClientUpdateMessageImpl, so don't wrap them
        conflatable = clientMessage;
        // Remove clients older than 70 from the filterClients if the message is
        // ClientTombstoneMessage. Fix for #46591.
        Object[] objects = filterClients.toArray();
        for (Object id : objects) {
            CacheClientProxy ccp = getClientProxy((ClientProxyMembershipID) id, true);
            if (ccp != null && ccp.getVersion().compareTo(Version.GFE_70) < 0) {
                filterClients.remove(id);
            }
        }
    } else {
        HAEventWrapper wrapper = new HAEventWrapper(clientMessage);
        // Set the putInProgress flag to true before starting the put on proxy's
        // HA queues. Nowhere else, this flag is being set to true.
        wrapper.setPutInProgress(true);
        conflatable = wrapper;
    }
    singletonRouteClientMessage(conflatable, filterClients);
    this.statistics.endEvent(startTime);
    // destroyed are removed after the event is placed in clients HAQueue.
    if (filterInfo.filterProcessedLocally) {
        removeDestroyTokensFromCqResultKeys(event, filterInfo);
    }
}
Also used : LocalRegion(org.apache.geode.internal.cache.LocalRegion) FilterProfile(org.apache.geode.internal.cache.FilterProfile) ServerCQ(org.apache.geode.cache.query.internal.cq.ServerCQ) Conflatable(org.apache.geode.internal.cache.Conflatable) FilterInfo(org.apache.geode.internal.cache.FilterRoutingInfo.FilterInfo) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HAContainerMap(org.apache.geode.internal.cache.ha.HAContainerMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet)

Example 27 with Conflatable

use of org.apache.geode.internal.cache.Conflatable in project geode by apache.

the class CacheClientProxy method initializeMessageDispatcher.

/**
   * Initializes the message dispatcher thread. The <code>MessageDispatcher</code> processes the
   * message queue.
   *
   * @throws CacheException
   */
public void initializeMessageDispatcher() throws CacheException {
    // Initialization process.
    this.messageDispatcherInit = true;
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("{}: Initializing message dispatcher with capacity of {} entries", this, _maximumMessageCount);
        }
        String name = "Client Message Dispatcher for " + getProxyID().getDistributedMember() + (isDurable() ? " (" + getDurableId() + ")" : "");
        this._messageDispatcher = new MessageDispatcher(this, name);
        // as we can without synchronization.
        if (logger.isDebugEnabled()) {
            logger.debug("{} draining {} events from init queue into intialized queue", this, this.queuedEvents.size());
        }
        Conflatable nextEvent;
        while ((nextEvent = queuedEvents.poll()) != null) {
            this._messageDispatcher.enqueueMessage(nextEvent);
        }
        // sure we don't miss any events.
        synchronized (this.queuedEventsSync) {
            while ((nextEvent = queuedEvents.poll()) != null) {
                this._messageDispatcher.enqueueMessage(nextEvent);
            }
            // Done initialization.
            this.messageDispatcherInit = false;
        }
    } finally {
        if (this.messageDispatcherInit) {
            // If its not successfully completed.
            this._statistics.close();
        }
    }
}
Also used : Conflatable(org.apache.geode.internal.cache.Conflatable)

Example 28 with Conflatable

use of org.apache.geode.internal.cache.Conflatable in project geode by apache.

the class SerialGatewaySenderQueue method putAndGetKey.

private long putAndGetKey(Object object) throws CacheException {
    // Get the tail key
    Long key = Long.valueOf(getTailKey());
    // Put the object into the region at that key
    this.region.put(key, (AsyncEvent) object);
    // Increment the tail key
    // It is important that we increment the tail
    // key after putting in the region, this is the
    // signal that a new object is available.
    incrementTailKey();
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Inserted {} -> {}", this, key, object);
    }
    if (object instanceof Conflatable) {
        removeOldEntry((Conflatable) object, key);
    }
    return key.longValue();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Conflatable(org.apache.geode.internal.cache.Conflatable)

Example 29 with Conflatable

use of org.apache.geode.internal.cache.Conflatable in project geode by apache.

the class BlockingHARQAddOperationJUnitTest method doBlockingTake.

/**
   * This method performs the following steps :<br>
   * 1)Create a blocking queue and start a thread which does take() on it. 2)Verify after
   * significant time that the thread is still alive as it should be blocked on take() since there
   * are no events in the queue.<br>
   * 3)Do a put into the queue and verify that the take thread returns with the same object.
   * 
   * @param conflationEnabled - whether conflation is enabled or not
   * @throws Exception
   * 
   */
public void doBlockingTake(boolean conflationEnabled) throws Exception {
    testFailed = false;
    message = null;
    final HARegionQueue rq = createHARegionQueue("testBlockingTake");
    final List takenObjects = new ArrayList();
    Thread takeThread = new Thread() {

        public void run() {
            try {
                takenObjects.add(rq.take());
            } catch (Exception e) {
                testFailed = true;
                message.append("Exception while performing take operation " + e.getStackTrace());
            }
        }
    };
    takeThread.start();
    Wait.pause(20 * 1000);
    if (!takeThread.isAlive()) {
        fail("take() thread died ");
    }
    EventID id1 = new EventID(new byte[] { 1 }, 1, 1);
    ConflatableObject c1 = new ConflatableObject(KEY1, VALUE1, id1, conflationEnabled, "region1");
    rq.put(c1);
    ThreadUtils.join(takeThread, 20 * 1000);
    assertEquals(1, takenObjects.size());
    Conflatable obj = (Conflatable) takenObjects.get(0);
    assertNotNull(obj);
    assertEquals(id1, obj.getEventId());
    if (testFailed)
        fail("Test failed due to " + message);
}
Also used : ArrayList(java.util.ArrayList) EventID(org.apache.geode.internal.cache.EventID) ArrayList(java.util.ArrayList) List(java.util.List) Conflatable(org.apache.geode.internal.cache.Conflatable) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 30 with Conflatable

use of org.apache.geode.internal.cache.Conflatable in project geode by apache.

the class BlockingHARQAddOperationJUnitTest method testConcurrentBlockingTake.

/**
   * This test performs the following steps :<br>
   * 1)Create a blocking queue.<br>
   * 2) Start two threads which does take() on it and add the return object to a list.<br>
   * 3)Put two object into the queue. <br>
   * 4)Verify both both take() threads return with an object by ensuring that the size of the list
   * containing return objects is two.<br>
   * 
   * @throws Exception
   * 
   */
@Test
public void testConcurrentBlockingTake() throws Exception {
    this.logWriter.info("HARQAddOperationJUnitTest : testConcurrentBlockingTake BEGIN");
    testFailed = false;
    message = null;
    final HARegionQueue rq = createHARegionQueue("testBlockingTake");
    final List takenObjects = new Vector();
    final int totalTakeThreads = 2;
    Thread[] takeThreads = new Thread[totalTakeThreads];
    for (int i = 0; i < totalTakeThreads; i++) {
        takeThreads[i] = new Thread() {

            public void run() {
                try {
                    takenObjects.add(rq.take());
                } catch (Exception e) {
                    testFailed = true;
                    message.append("Exception while performing take operation " + e.getStackTrace());
                }
            }
        };
        takeThreads[i].start();
    }
    Conflatable c = null;
    EventID id = null;
    for (int i = 0; i < totalTakeThreads; i++) {
        id = new EventID(new byte[] { 1 }, 1, i);
        c = new ConflatableObject("k" + i, "v" + i, id, true, "region1");
        rq.put(c);
    }
    for (int i = 0; i < totalTakeThreads; i++) {
        ThreadUtils.join(takeThreads[i], 20 * 1000);
    }
    assertEquals(totalTakeThreads, takenObjects.size());
    for (int i = 0; i < totalTakeThreads; i++) {
        c = (Conflatable) takenObjects.get(i);
        assertNotNull(c);
    }
    if (testFailed)
        fail("Test failed due to " + message);
    this.logWriter.info("HARQAddOperationJUnitTest : testConcurrentBlockingTake END");
}
Also used : EventID(org.apache.geode.internal.cache.EventID) ArrayList(java.util.ArrayList) List(java.util.List) Conflatable(org.apache.geode.internal.cache.Conflatable) Vector(java.util.Vector) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

Conflatable (org.apache.geode.internal.cache.Conflatable)39 EventID (org.apache.geode.internal.cache.EventID)29 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)22 Test (org.junit.Test)22 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)21 AtomicLong (java.util.concurrent.atomic.AtomicLong)9 Map (java.util.Map)8 CacheException (org.apache.geode.cache.CacheException)8 HashMap (java.util.HashMap)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 ConcurrentMap (java.util.concurrent.ConcurrentMap)7 IOException (java.io.IOException)5 List (java.util.List)5 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 EntryEvent (org.apache.geode.cache.EntryEvent)3 CacheListenerAdapter (org.apache.geode.cache.util.CacheListenerAdapter)3