if (this.isAlive()) { if (getLogger().fineEnabled()) { getLogger().fine(this + ":Notifying the dispatcher to terminate"); if (getGateway().getPrimary()) { int numberOfPeeks = 0; try { setIsStopped(true); if (this.isAlive()) { this.interrupt(); if (getLogger().fineEnabled()) { getLogger().fine(this + ":Joining with the dispatcher thread upto limit of 5 seconds"); this.join(5000); // wait for our thread to stop if (this.isAlive()) { getLogger().warning( LocalizedStrings.GatewayImpl_0_DISPATCHER_STILL_ALIVE_EVEN_AFTER_JOIN_OF_5_SECONDS, this); if (getLogger().warningEnabled()) { getLogger().warning( LocalizedStrings.GatewayImpl_0_INTERRUPTEDEXCEPTION_IN_JOINING_WITH_DISPATCHER_THREAD, this); closeProcessor();
GatewayStats statistics = getGateway().getStatistics(); if (getLogger().finerEnabled()) { try { gatewayEvent.initialize(); if (getLogger().finerEnabled()) { getLogger().finer(GatewayImpl.this + ": fromPrimary " + " event " + gatewayEvent.getEventId() + ":" + gatewayEvent.getKey() + "->" + deserialize(gatewayEvent.getValue()) + " added to unprocessed token map."); if (getLogger().finerEnabled()) { try { gatewayEvent.initialize(); getLogger().finer(GatewayImpl.this + ": Primary create/update event " + gatewayEvent.getEventId() + ":" + gatewayEvent.getKey() + "->" + deserialize(gatewayEvent.getValue()) + " removed from unprocessed events map"); reapOld(statistics, false);
private void processQueue() { GatewayQueueAttributes gqa = getGateway().getQueueAttributes(); final int batchSize = gqa.getBatchSize(); final int batchTimeInterval = gqa.getBatchTimeInterval(); final int alertThreshold = gqa.getAlertThreshold(); final GatewayStats statistics = getGateway().getStatistics(); List events = null; for (;;) { if (stopped()) { break; waitForResumption(); if (getLogger().fineEnabled()) { getLogger().fine("Attempting to peek a batch of " + batchSize + " events"); if (stopped()) { break; waitForResumption(); logBatchFine("During normal processing, dispatching the following ", events); boolean success = this._eventDispatcher.dispatchBatch(events, true); if (getLogger().fineEnabled()) { getLogger().fine("During normal processing, " + (success ? "" : "un") + "successfully dispatched " + events.size() + " events (batch #" + getBatchId() + ")" + " queue size=" + eventQueueSize());
getLogger().info(LocalizedStrings.GatewayImpl_GATEWAY_FAILOVER_INITIATED_PROCESSING_0_UNPROCESSED_EVENTS, this.unprocessedEvents.size()); GatewayStats statistics = getGateway().getStatistics(); statistics.setQueueSize(eventQueueSize()); // to capture an initial size if (!this.unprocessedEvents.isEmpty()) { reapOld(statistics, true); // to get rid of timed out events while (it.hasNext() && !stopped()) { Object o = it.next(); if (o != null && o instanceof GatewayEventImpl) { getLogger().info(LocalizedStrings.GatewayImpl_GATEWAY_FAILOVER_INITIATED_ADDING_0_UNPROCESSED_EVENTS, this.unprocessedEvents.size()); Iterator it = this.unprocessedEvents.values().iterator(); while (it.hasNext() && !stopped()) { EventWrapper ew = (EventWrapper)it.next(); GatewayEventImpl gatewayEvent = ew.event; getLogger().warning( LocalizedStrings.GatewayImpl_EVENT_FAILED_TO_BE_INITIALIZED_0, gatewayEvent, e); if (geca.getOriginatingGatewayHubId() == null) { geca .setOriginatingGatewayHubId(getGateway().getGatewayHubId()); geca.initializeRecipientGateways(getGateway().getGatewayHub() .getGatewayIds()); if (getLogger().fineEnabled()) { getLogger().fine(getGateway() + ": Queueing unprocessed event: " + gatewayEvent);
GatewayStats statistics = this.eventProcessor.getGateway().getStatistics(); boolean success = false; try { if (this.eventProcessor.getGateway().getProxy().isDestroyed()) { this.eventProcessor.logBatchFine("Because of IOException, failed to dispatch the following ", events); try {Thread.sleep(5000);} catch (InterruptedException ie) { if (!this.eventProcessor.getIsStopped()) { this.logger.severe(LocalizedStrings.GatewayEventRemoteDispatcher_AN_INTERRUPTEDEXCEPTION_OCCURRED_BUT_THE_PROCESSOR_IS_NOT_STOPPED, e); this.eventProcessor.incrementBatchId(); this.eventProcessor.eventQueueRemove(be.getIndex()); GatewayEventImpl ge = (GatewayEventImpl) this.eventProcessor.eventQueueTake(); statistics.setQueueSize(this.eventProcessor.eventQueueSize()); if (logWarning) { this.logger.warning(LocalizedStrings.GatewayEventRemoteDispatcher_THE_EVENT_BEING_PROCESSED_WHEN_THE_BATCHEXCEPTION_OCCURRED_WAS__0, ge); this.eventProcessor.setIsStopped(true); this.eventProcessor.setIsStopped(true); throw e; this.eventProcessor.setIsStopped(true);
private void basicHandleSecondaryEvent(final GatewayEventImpl gatewayEvent) { GatewayStats statistics = getGateway().getStatistics(); if (getLogger().finerEnabled()) { try { gatewayEvent.initialize(); getLogger().finer(GatewayImpl.this + ": fromSecondary " + " event " + gatewayEvent.getEventId() + ":" + gatewayEvent.getKey() + "->" + deserialize(gatewayEvent.getValue()) + " added to unprocessed events map."); if (getLogger().warningEnabled()) { try { gatewayEvent.initialize(); getLogger().warning( LocalizedStrings. GatewayImpl_EVENT_FAILED_TO_BE_INITIALIZED_0, gatewayEvent, e); getLogger().warning( LocalizedStrings.GatewayImpl_0_THE_UNPROCESSED_EVENTS_MAP_ALREADY_CONTAINED_AN_EVENT_FROM_THE_HUB_1_SO_IGNORING_NEW_EVENT_2, new Object[] {GatewayImpl.this, GatewayImpl.this.getGatewayHubId(), gatewayEvent}); if (getLogger().finerEnabled()) { try { gatewayEvent.initialize(); getLogger().finer(GatewayImpl.this
ev.enqueueEvent(operation, event);
GatewayStats statistics = getGateway().getStatistics(); if (getLogger().fineEnabled()) { getLogger().fine(getGateway() + ": Queueing event (" + (statistics.getEventsQueued() + 1) + "): " + gatewayEvent); if(shouldEnqueue(gatewayEvent)) { this._eventQueue.put(gatewayEvent); if (getLogger().fineEnabled()) { getLogger().fine(getGateway() + ": Queued event (" + (statistics.getEventsQueued()) + "): " + gatewayEvent); int queueSize = eventQueueSize(); statistics.setQueueSize(queueSize); if (!this._eventQueueSizeWarning && queueSize >= QUEUE_SIZE_THRESHOLD) { getLogger().warning( LocalizedStrings.GatewayImpl_0_THE_EVENT_QUEUE_SIZE_HAS_REACHED_THE_THRESHOLD_1, new Object[] {getGateway(), Integer.valueOf(QUEUE_SIZE_THRESHOLD)}); this._eventQueueSizeWarning = true;
/** * Update an unprocessed event in the unprocessed events map. This method is * called by a secondary <code>Gateway</code> to store a gateway event * until it is processed by a primary <code>Gateway</code>. The * complexity of this method is the fact that the event could be processed * first by either the primary or secondary <code>Gateway</code>. * * If the primary processes the event first, the map will already contain an * entry for the event (through * {@link com.gemstone.gemfire.internal.cache.GatewayImpl.SecondaryGatewayListener#afterDestroy}). * When the secondary processes the event, it will remove it from the map. * * If the secondary processes the event first, it will add it to the map. * When the primary processes the event (through * {@link com.gemstone.gemfire.internal.cache.GatewayImpl.SecondaryGatewayListener#afterDestroy}), * it will then be removed from the map. * * @param gatewayEvent * The event being processed */ protected void handleSecondaryEvent(GatewayEventImpl gatewayEvent) { basicHandleSecondaryEvent(gatewayEvent); }
public void run() { basicHandlePrimaryEvent(gatewayEvent); } });
public void run() { basicHandlePrimaryDestroy(gatewayEvent); } });
/** * Initializes this <code>Gateway</code>'s <code>GatewayEventProcessor</code> */ private GatewayEventProcessor initializeEventProcessor() { GatewayEventProcessor ev = new GatewayEventProcessor(this); this._eventProcessor = ev; if (this.getLogger().fineEnabled()) { this.getLogger().fine(this + ": Created event processor " + ev); } return ev; }