Search in sources :

Example 76 with EventID

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

the class CacheClientProxy method notifySecondariesAndClient.

private void notifySecondariesAndClient(String regionName, Object keyOfInterest, boolean isDurable, boolean receiveValues, int interestType) {
    // Notify all secondary proxies of a change in interest
    ClientInterestMessageImpl message = new ClientInterestMessageImpl(new EventID(this._cache.getDistributedSystem()), regionName, keyOfInterest, interestType, (byte) 0, isDurable, !receiveValues, ClientInterestMessageImpl.UNREGISTER);
    notifySecondariesOfInterestChange(message);
    // Modify interest registration
    if (keyOfInterest instanceof List) {
        unregisterClientInterest(regionName, (List) keyOfInterest, false);
    } else {
        unregisterClientInterest(regionName, keyOfInterest, interestType, false);
    }
    // Enqueue the interest unregistration message for the client.
    enqueueInterestRegistrationMessage(message);
}
Also used : EventID(org.apache.geode.internal.cache.EventID) List(java.util.List)

Example 77 with EventID

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

the class SerialGatewaySenderEventProcessor method reapOld.

/**
   * Call to check if a cleanup of tokens needs to be done
   */
private void reapOld(final GatewaySenderStats statistics, boolean forceEventReap) {
    synchronized (this.unprocessedEventsLock) {
        if (uncheckedCount > REAP_THRESHOLD) {
            // only check every X events
            uncheckedCount = 0;
            long now = System.currentTimeMillis();
            if (!forceEventReap && this.unprocessedTokens.size() > REAP_THRESHOLD) {
                Iterator<Map.Entry<EventID, Long>> it = this.unprocessedTokens.entrySet().iterator();
                int count = 0;
                while (it.hasNext()) {
                    Map.Entry<EventID, Long> me = it.next();
                    long meValue = me.getValue().longValue();
                    if (meValue <= now) {
                        // @todo log fine level message here
                        // it has expired so remove it
                        it.remove();
                        count++;
                    } else {
                        // all done try again
                        break;
                    }
                }
                if (count > 0) {
                // statistics.incUnprocessedTokensRemovedByTimeout(count);
                }
            }
            if (forceEventReap || this.unprocessedEvents.size() > REAP_THRESHOLD) {
                Iterator<Map.Entry<EventID, EventWrapper>> it = this.unprocessedEvents.entrySet().iterator();
                int count = 0;
                while (it.hasNext()) {
                    Map.Entry<EventID, EventWrapper> me = it.next();
                    EventWrapper ew = me.getValue();
                    if (ew.timeout <= now) {
                        // @todo log fine level message here
                        // it has expired so remove it
                        it.remove();
                        ew.event.release();
                        count++;
                    } else {
                        // all done try again
                        break;
                    }
                }
                if (count > 0) {
                // statistics.incUnprocessedEventsRemovedByTimeout(count);
                }
            }
        } else {
            uncheckedCount++;
        }
    }
}
Also used : EventID(org.apache.geode.internal.cache.EventID) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) EventWrapper(org.apache.geode.internal.cache.wan.AbstractGatewaySender.EventWrapper)

Example 78 with EventID

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

the class SerialGatewaySenderEventProcessor method handleFailover.

/**
   * Handle failover. This method is called when a secondary <code>GatewaySender</code> becomes a
   * primary <code>GatewaySender</code>.
   * 
   * Once this secondary becomes the primary, it must:
   * <ul>
   * <li>Remove the queue's CacheListener
   * <li>Process the map of unprocessed events (those it has seen but the previous primary had not
   * yet processed before it crashed). These will include both queued and unqueued events. Remove
   * from the queue any events that were already sent
   * <li>Clear the unprocessed events map
   * </ul>
   */
protected void handleFailover() {
    /*
     * We must hold this lock while we're processing these maps to prevent us from handling a
     * secondary event while failover occurs. See enqueueEvent
     */
    synchronized (this.unprocessedEventsLock) {
        // Remove the queue's CacheListener
        this.queue.removeCacheListener();
        this.unprocessedTokens = null;
        // Process the map of unprocessed events
        logger.info(LocalizedMessage.create(LocalizedStrings.GatewayImpl_GATEWAY_FAILOVER_INITIATED_PROCESSING_0_UNPROCESSED_EVENTS, this.unprocessedEvents.size()));
        GatewaySenderStats statistics = this.sender.getStatistics();
        if (!this.unprocessedEvents.isEmpty()) {
            // do a reap for bug 37603
            // to get rid of timed out events
            reapOld(statistics, true);
            // now iterate over the region queue to figure out what unprocessed
            // events are already in the queue
            {
                Iterator it = this.queue.getRegion().values().iterator();
                while (it.hasNext() && !stopped()) {
                    Object o = it.next();
                    if (o != null && o instanceof GatewaySenderEventImpl) {
                        GatewaySenderEventImpl ge = (GatewaySenderEventImpl) o;
                        EventWrapper unprocessedEvent = this.unprocessedEvents.remove(ge.getEventId());
                        if (unprocessedEvent != null) {
                            unprocessedEvent.event.release();
                            if (this.unprocessedEvents.isEmpty()) {
                                break;
                            }
                        }
                    }
                }
            }
            // now for every unprocessed event add it to the end of the queue
            {
                Iterator<Map.Entry<EventID, EventWrapper>> it = this.unprocessedEvents.entrySet().iterator();
                while (it.hasNext()) {
                    if (stopped())
                        break;
                    Map.Entry<EventID, EventWrapper> me = it.next();
                    EventWrapper ew = me.getValue();
                    GatewaySenderEventImpl gatewayEvent = ew.event;
                    // Initialize each gateway event. This initializes the key,
                    // value
                    // and callback arg based on the EntryEvent.
                    // TODO:wan70, remove dependencies from old code
                    gatewayEvent.initialize();
                    // Verify that they GatewayEventCallbackArgument is initialized.
                    // If not, initialize it. It won't be initialized if a client to
                    // this GatewayHub VM was the creator of this event. This Gateway
                    // will be the first one to process it. If will be initialized if
                    // this event was sent to this Gateway from another GatewayHub
                    // (either directly or indirectly).
                    GatewaySenderEventCallbackArgument seca = gatewayEvent.getSenderCallbackArgument();
                    if (seca.getOriginatingDSId() == GatewaySender.DEFAULT_DISTRIBUTED_SYSTEM_ID) {
                        seca.setOriginatingDSId(sender.getMyDSId());
                        seca.initializeReceipientDSIds(Collections.singletonList(sender.getRemoteDSId()));
                    }
                    it.remove();
                    boolean queuedEvent = false;
                    try {
                        queuedEvent = queuePrimaryEvent(gatewayEvent);
                    } catch (IOException ex) {
                        if (!stopped()) {
                            logger.warn(LocalizedMessage.create(LocalizedStrings.GatewayImpl_EVENT_DROPPED_DURING_FAILOVER_0, gatewayEvent), ex);
                        }
                    } catch (CacheException ex) {
                        if (!stopped()) {
                            logger.warn(LocalizedMessage.create(LocalizedStrings.GatewayImpl_EVENT_DROPPED_DURING_FAILOVER_0, gatewayEvent), ex);
                        }
                    } finally {
                        if (!queuedEvent) {
                            gatewayEvent.release();
                        }
                    }
                }
            }
            // Clear the unprocessed events map
            statistics.clearUnprocessedMaps();
        }
        // Iterate the entire queue and mark all events as possible
        // duplicate
        logger.info(LocalizedMessage.create(LocalizedStrings.GatewayImpl_0__MARKING__1__EVENTS_AS_POSSIBLE_DUPLICATES, new Object[] { getSender(), Integer.valueOf(this.queue.size()) }));
        Iterator it = this.queue.getRegion().values().iterator();
        while (it.hasNext() && !stopped()) {
            Object o = it.next();
            if (o != null && o instanceof GatewaySenderEventImpl) {
                GatewaySenderEventImpl ge = (GatewaySenderEventImpl) o;
                ge.setPossibleDuplicate(true);
            }
        }
        releaseUnprocessedEvents();
    }
// synchronized
}
Also used : GatewaySenderStats(org.apache.geode.internal.cache.wan.GatewaySenderStats) CacheException(org.apache.geode.cache.CacheException) Iterator(java.util.Iterator) GatewaySenderEventImpl(org.apache.geode.internal.cache.wan.GatewaySenderEventImpl) EventID(org.apache.geode.internal.cache.EventID) GatewaySenderEventCallbackArgument(org.apache.geode.internal.cache.wan.GatewaySenderEventCallbackArgument) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) EventWrapper(org.apache.geode.internal.cache.wan.AbstractGatewaySender.EventWrapper)

Example 79 with EventID

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

the class SerialGatewaySenderEventProcessor method releaseUnprocessedEvents.

private void releaseUnprocessedEvents() {
    synchronized (this.unprocessedEventsLock) {
        Map<EventID, EventWrapper> m = this.unprocessedEvents;
        if (m != null) {
            for (EventWrapper ew : m.values()) {
                GatewaySenderEventImpl gatewayEvent = ew.event;
                gatewayEvent.release();
            }
            this.unprocessedEvents = null;
        }
    }
}
Also used : GatewaySenderEventImpl(org.apache.geode.internal.cache.wan.GatewaySenderEventImpl) EventID(org.apache.geode.internal.cache.EventID) EventWrapper(org.apache.geode.internal.cache.wan.AbstractGatewaySender.EventWrapper)

Example 80 with EventID

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

the class HAEventWrapper method toData.

/**
   * Calls toData() on its clientUpdateMessage present in the haContainer (client-messages-region or
   * the map).
   * 
   * @param out The output stream which the object should be written to.
   */
public void toData(DataOutput out) throws IOException {
    ClientUpdateMessageImpl cum = (ClientUpdateMessageImpl) this.haContainer.get(this);
    // by sending false boolean value.
    if (cum != null) {
        DataSerializer.writePrimitiveBoolean(true, out);
        DataSerializer.writeObject(cum.getEventId(), out);
    } else {
        DataSerializer.writePrimitiveBoolean(false, out);
        DataSerializer.writeObject(new EventID(), out);
        // Create a dummy ClientUpdateMessageImpl instance
        cum = new ClientUpdateMessageImpl(EnumListenerEvent.AFTER_CREATE, new ClientProxyMembershipID(), null);
    }
    InternalDataSerializer.invokeToData(cum, out);
    if (cum.hasCqs()) {
        DataSerializer.writeConcurrentHashMap(cum.getClientCqs(), out);
    }
}
Also used : EventID(org.apache.geode.internal.cache.EventID)

Aggregations

EventID (org.apache.geode.internal.cache.EventID)147 Test (org.junit.Test)66 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)60 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)58 IOException (java.io.IOException)41 Map (java.util.Map)33 CacheException (org.apache.geode.cache.CacheException)31 Conflatable (org.apache.geode.internal.cache.Conflatable)29 LocalRegion (org.apache.geode.internal.cache.LocalRegion)23 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)20 HashMap (java.util.HashMap)16 Part (org.apache.geode.internal.cache.tier.sockets.Part)16 ByteBuffer (java.nio.ByteBuffer)14 Iterator (java.util.Iterator)14 List (java.util.List)14 LinkedHashMap (java.util.LinkedHashMap)13 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)13 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)13 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)13 ConcurrentMap (java.util.concurrent.ConcurrentMap)12