@Override protected void initializeMessageQueue(String id) { for (int i = 0; i < sender.getDispatcherThreads(); i++) { processors.add(new SerialGatewaySenderEventProcessor(this.sender, id + "." + i)); if (logger.isDebugEnabled()) { logger.debug("Created the SerialGatewayEventProcessor_{}->{}", i, processors.get(i)); } } }
public void run() { basicHandlePrimaryDestroy(gatewayEvent); } });
public void run() { basicHandlePrimaryEvent(gatewayEvent); } });
@Override public void run() { try { setRunningStatus(); if (!waitForPrimary()) { return; completeFailover(); if (getLogger().fineEnabled()) { getLogger().fine("Beginning to process the message queue"); getLogger() .warning( LocalizedStrings.GatewayImpl_ABOUT_TO_PROCESS_THE_MESSAGE_QUEUE_BUT_NOT_THE_PRIMARY); processQueue(); } catch (CancelException e) { if (!this.isStopped()) { getLogger() .info( LocalizedStrings.GatewayImpl_A_CANCELLATION_OCCURRED_STOPPING_THE_DISPATCHER); setIsStopped(true); getLogger() .severe( LocalizedStrings.GatewayImpl_MESSAGE_DISPATCH_FAILED_DUE_TO_UNEXPECTED_EXCEPTION,
getLogger() .info( LocalizedStrings.GatewayImpl_GATEWAY_FAILOVER_INITIATED_PROCESSING_0_UNPROCESSED_EVENTS, this.unprocessedEvents.size()); GatewaySenderStats statistics = this.sender.getStatistics(); statistics.setQueueSize(eventQueueSize()); // to capture an initial reapOld(statistics, true); // to get rid of timed out events while (it.hasNext() && !stopped()) { Object o = it.next(); if (o != null && o instanceof GatewaySenderEventImpl) { if (stopped()) break; Map.Entry<EventID, EventWrapper> me = it.next(); EventWrapper ew = me.getValue(); boolean queuedEvent = false; try { queuePrimaryEvent(gatewayEvent); queuedEvent = true; } catch (IOException ex) { if (!stopped()) { getLogger() .warning( LocalizedStrings.GatewayImpl_EVENT_DROPPED_DURING_FAILOVER_0, if (!stopped()) { getLogger()
} catch (InterruptedException e) { if (!stopped()) { getLogger() .severe( LocalizedStrings.GatewayImpl_AN_INTERRUPTEDEXCEPTION_OCCURRED_THE_THREAD_WILL_EXIT, e); shutdownListenerExecutor(); return false; shutdownListenerExecutor(); if (!stopped()) { handleFailover(); } else { return false; if (!stopped()) { getLogger().fine("Terminating due to " + e); if (!stopped()) { getLogger().fine("Terminating due to " + e); completeFailover();
if (getLogger().fineEnabled()) { getLogger().fine( sender.getId() + ": Queueing event (" + (statistics.getEventsQueued() + 1) + "): " + gatewayEvent); getSender().getCancelCriterion().checkCancelInProgress(e); if (getLogger().fineEnabled()) { getLogger().fine( sender.getId() + ": Queued event (" + (statistics.getEventsQueued()) + "): " + gatewayEvent); int queueSize = eventQueueSize(); statistics.incQueueSize(1); if (!this.eventQueueSizeWarning && queueSize >= AbstractGatewaySender.QUEUE_SIZE_THRESHOLD) { getLogger() .warning( LocalizedStrings.GatewayImpl_0_THE_EVENT_QUEUE_SIZE_HAS_REACHED_THE_THRESHOLD_1,
private void waitForRunningStatus() { for (SerialGatewaySenderEventProcessor serialProcessor : this.processors) { synchronized (serialProcessor.runningStateLock) { while (serialProcessor.getException() == null && serialProcessor.isStopped()) { try { serialProcessor.runningStateLock.wait(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } Exception ex = serialProcessor.getException(); if (ex != null) { throw new GatewaySenderException( LocalizedStrings.Sender_COULD_NOT_START_GATEWAYSENDER_0_BECAUSE_OF_EXCEPTION_1 .toLocalizedString(new Object[] { this.getId(), ex.getMessage() }), ex.getCause()); } } } }
getSender().getCancelCriterion().checkCancelInProgress(e); int queueSize = eventQueueSize(); statistics.incQueueSize(1); if (!this.eventQueueSizeWarning
@Override public void closeProcessor() { for (SerialGatewaySenderEventProcessor processor : processors) { processor.closeProcessor(); } }
/** * @param sender */ public ConcurrentSerialGatewaySenderEventProcessor( AbstractGatewaySender sender) { super(LoggingThreadGroup.createThreadGroup("Event Processor for GatewaySender_" + sender.getId(), logger), "Event Processor for GatewaySender_" + sender.getId(), sender); this.sender = sender; initializeMessageQueue(sender.getId()); queues = new HashSet<RegionQueue>(); for (SerialGatewaySenderEventProcessor processor : processors) { queues.add(processor.getQueue()); } setDaemon(true); }
/** * Update an unprocessed event in the unprocessed events map. This method is * called by a secondary <code>GatewaySender</code> to store a gateway event until * it is processed by a primary <code>GatewaySender</code>. The complexity of this * method is the fact that the event could be processed first by either the * primary or secondary <code>GatewaySender</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.wan.serial.SerialSecondaryGatewayListener#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.wan.serial.SerialSecondaryGatewayListener#afterDestroy} * ), it will then be removed from the map. * * @param senderEvent * The event being processed */ protected void handleSecondaryEvent(GatewaySenderEventImpl senderEvent) { basicHandleSecondaryEvent(senderEvent); }
serialProcessor.enqueueEvent(operation, clonedEvent, substituteValue); } finally { clonedEvent.release(); serialProcessor.enqueueEvent(operation, event, substituteValue);
@Override public void run() { try { setRunningStatus(); if (!waitForPrimary()) { return; completeFailover(); processQueue(); } catch (CancelException e) { if (!this.isStopped()) { logger.info(LocalizedMessage.create(LocalizedStrings.GatewayImpl_A_CANCELLATION_OCCURRED_STOPPING_THE_DISPATCHER)); setIsStopped(true);
} catch (InterruptedException e) { if (!stopped()) { logger.fatal(LocalizedMessage.create(LocalizedStrings.GatewayImpl_AN_INTERRUPTEDEXCEPTION_OCCURRED_THE_THREAD_WILL_EXIT), e); shutdownListenerExecutor(); return false; shutdownListenerExecutor(); if (!stopped()) { handleFailover(); } else { return false; if (!stopped()) { logger.debug("Terminating due to {}", e.getMessage(), e); if (!stopped()) { logger.debug("Terminating due to {}", e.getMessage(), e); completeFailover();
private void waitForRunningStatus() { for (SerialGatewaySenderEventProcessor serialProcessor : this.processors) { synchronized (serialProcessor.runningStateLock) { while (serialProcessor.getException() == null && serialProcessor.isStopped()) { try { serialProcessor.runningStateLock.wait(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } Exception ex = serialProcessor.getException(); if (ex != null) { throw new GatewaySenderException( LocalizedStrings.Sender_COULD_NOT_START_GATEWAYSENDER_0_BECAUSE_OF_EXCEPTION_1 .toLocalizedString(new Object[] { this.getId(), ex.getMessage() }), ex.getCause()); } } } }
@Override public void closeProcessor() { for (SerialGatewaySenderEventProcessor processor : processors) { processor.closeProcessor(); } }
/** * @param sender */ public ConcurrentSerialGatewaySenderEventProcessor( SerialGatewaySenderImpl sender) { super(LogWriterImpl.createThreadGroup("Event Processor for GatewaySender_" + sender.getId(), sender.getLogger()), "Event Processor for GatewaySender_" + sender.getId(), sender); this.sender = sender; initializeMessageQueue(sender.getId()); queues = new HashSet<RegionQueue>(); for (SerialGatewaySenderEventProcessor processor : processors) { queues.add(processor.getQueue()); } setDaemon(true); }
/** * Update an unprocessed event in the unprocessed events map. This method is * called by a secondary <code>GatewaySender</code> to store a gateway event until * it is processed by a primary <code>GatewaySender</code>. The complexity of this * method is the fact that the event could be processed first by either the * primary or secondary <code>GatewaySender</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 senderEvent * The event being processed */ protected void handleSecondaryEvent(GatewaySenderEventImpl senderEvent) { basicHandleSecondaryEvent(senderEvent); }
serialProcessor.enqueueEvent(operation, clonedEvent); } finally { clonedEvent.release(); serialProcessor.enqueueEvent(operation, event);