@Override public boolean done() { if (sender != null && ((AbstractGatewaySender) sender).isPrimary()) { return true; } return false; }
public boolean isPrimary() { return ((AbstractGatewaySender) sender).isPrimary(); }
public void closeProcessor() { if (logger.isDebugEnabled()) { logger.debug("Closing dispatcher"); } try { if (this.sender.isPrimary() && this.queue.size() > 0) { logger.warn("Destroying GatewayEventDispatcher with actively queued data."); } } catch (RegionDestroyedException ignore) { } catch (CancelException ignore) { } catch (CacheException ignore) { // just checking in case we should log a warning } finally { this.queue.close(); if (logger.isDebugEnabled()) { logger.debug("Closed dispatcher"); } } }
@Override protected void initializeMessageQueue(String id) { // Create the region name StringBuffer regionNameBuffer = new StringBuffer(); regionNameBuffer.append(id).append("_SERIAL_GATEWAY_SENDER_QUEUE"); String regionName = regionNameBuffer.toString(); CacheListener listener = null; if (!this.sender.isPrimary()) { listener = new SerialSecondaryGatewayListener(this); initializeListenerExecutor(); } // Create the region queue this.queue = new SerialGatewaySenderQueue(sender, regionName, listener); if (logger.isDebugEnabled()) { logger.debug("Created queue: {}", this.queue); } }
/** * When the sender profile is removed, then check for the primary members if they are not * available then this secondary sender should volunteer for primary */ @Override protected void profileRemoved(Profile profile) { if (profile instanceof GatewaySenderProfile) { GatewaySenderProfile sp = (GatewaySenderProfile) profile; if (!sp.isParallel) {// SerialGatewaySender // if there is a primary sender, then don't volunteer for primary if (advisePrimaryGatewaySender() != null) { return; } if (!this.sender.isPrimary()) {// IF this sender is not primary if (!adviseEldestGatewaySender()) {// AND this is not the eldest sender if (logger.isDebugEnabled()) { logger.debug( "Sender {} is not the eldest in the system. Giving preference to eldest sender to become primary...", this.sender); } return; } launchLockObtainingVolunteerThread(); } } } }
/** * Just remove the event from the unprocessed events map if it is present. This method added to * fix bug 37603 */ protected boolean basicHandlePrimaryDestroy(final EventID eventId) { if (this.sender.isPrimary()) { // no need to do anything if we have become the primary return false; } GatewaySenderStats statistics = this.sender.getStatistics(); // Get the event from the map synchronized (unprocessedEventsLock) { if (this.unprocessedEvents == null) return false; // now we can safely use the unprocessedEvents field EventWrapper ew = this.unprocessedEvents.remove(eventId); if (ew != null) { ew.event.release(); statistics.incUnprocessedEventsRemovedByPrimary(); return true; } } return false; }
if (!this.sender.isPrimary()) { if (!adviseEldestGatewaySender()) {// AND this is not the eldest
@Override public void afterDestroy(EntryEvent event) { if (this.sender.isPrimary()) { return; } // fix bug 37603 // There is a small window where queue has not been created fully yet. The region is created, // and it receives afterDestroy callback. final Set<RegionQueue> queues = this.sender.getQueues(); if (queues != null && !queues.isEmpty()) { this.sender.getStatistics().decQueueSize(); } // Send event to the event dispatcher Object oldValue = event.getOldValue(); if (oldValue instanceof GatewaySenderEventImpl) { GatewaySenderEventImpl senderEvent = (GatewaySenderEventImpl) oldValue; if (logger.isDebugEnabled()) { logger.debug("Received after Destroy for Secondary event {} the key was {}", senderEvent, event.getKey()); } this.processor.handlePrimaryDestroy(senderEvent); } } }
if (this.sender.isPrimary()) { if (AbstractGatewaySender.MAXIMUM_SHUTDOWN_WAIT_TIME == -1) { try {
@Override public void afterCreate(EntryEvent event) { if (this.sender.isPrimary()) { // The secondary has failed over to become the primary. There is a small // window where the secondary has become the primary, but the listener // is // still set. Ignore any updates to the map at this point. It is unknown // what the state of the map is. This may result in duplicate events // being sent. return; } // There is a small window where queue has not been created fully yet. // The underlying region of the queue is created, and it receives afterDestroy callback final Set<RegionQueue> queues = this.sender.getQueues(); if (queues != null && !queues.isEmpty()) { this.sender.getStatistics().incQueueSize(); } // fix bug 35730 // Send event to the event dispatcher GatewaySenderEventImpl senderEvent = (GatewaySenderEventImpl) event.getNewValue(); this.processor.handlePrimaryEvent(senderEvent); }
public static Boolean killSender(String senderId) { final IgnoredException exln = IgnoredException.addIgnoredException("Could not connect"); IgnoredException exp = IgnoredException.addIgnoredException(CacheClosedException.class.getName()); IgnoredException exp1 = IgnoredException.addIgnoredException(ForceReattemptException.class.getName()); try { Set<GatewaySender> senders = cache.getGatewaySenders(); AbstractGatewaySender sender = null; for (GatewaySender s : senders) { if (s.getId().equals(senderId)) { sender = (AbstractGatewaySender) s; break; } } if (sender.isPrimary()) { LogWriterUtils.getLogWriter().info("Gateway sender is killed by a test"); cache.getDistributedSystem().disconnect(); return Boolean.TRUE; } return Boolean.FALSE; } finally { exp.remove(); exp1.remove(); exln.remove(); } }
protected void basicHandlePrimaryEvent(final GatewaySenderEventImpl gatewayEvent) { if (this.sender.isPrimary()) {
if (this.sender.isPrimary()) { if (sender.getServerLocation() == null) { sender.setServerLocation(con.getServer());
if (this.sender.isPrimary() && (this.connection != null)) { if (this.ackReaderThread == null || !this.ackReaderThread.isRunning()) { this.ackReaderThread = new AckReaderThread(this.sender, this.processor);