use of org.apache.geode.internal.cache.wan.GatewaySenderException in project geode by apache.
the class WANConfigurationJUnitTest method test_GatewaySenderWithGatewaySenderEventListener1.
@Test
public void test_GatewaySenderWithGatewaySenderEventListener1() {
cache = new CacheFactory().set(MCAST_PORT, "0").create();
InternalGatewaySenderFactory fact = (InternalGatewaySenderFactory) cache.createGatewaySenderFactory();
AsyncEventListener listener = new MyGatewaySenderEventListener();
((InternalGatewaySenderFactory) fact).addAsyncEventListener(listener);
try {
fact.create("ln", 2);
fail("Expected GatewaySenderException. When a sender is added , remoteDSId should not be provided.");
} catch (Exception e) {
if (e instanceof GatewaySenderException && e.getMessage().contains("cannot define a remote site because at least AsyncEventListener is already added.")) {
} else {
fail("Expected GatewaySenderException but received :" + e);
}
}
}
use of org.apache.geode.internal.cache.wan.GatewaySenderException in project geode by apache.
the class RemoteParallelGatewaySenderEventProcessor method shouldSendVersionEvents.
/**
* Returns if corresponding receiver WAN site of this GatewaySender has GemfireVersion > 7.0.1
*
* @param disp
* @return true if remote site Gemfire Version is >= 7.0.1
*/
private boolean shouldSendVersionEvents(GatewaySenderEventDispatcher disp) throws GatewaySenderException {
try {
GatewaySenderEventRemoteDispatcher remoteDispatcher = (GatewaySenderEventRemoteDispatcher) disp;
// This will create a new connection if no batch has been sent till
// now.
Connection conn = remoteDispatcher.getConnection(false);
if (conn != null) {
short remoteSiteVersion = conn.getWanSiteVersion();
if (Version.GFE_701.compareTo(remoteSiteVersion) <= 0) {
return true;
}
}
} catch (GatewaySenderException e) {
Throwable cause = e.getCause();
if (cause instanceof IOException || e instanceof GatewaySenderConfigurationException || cause instanceof ConnectionDestroyedException) {
try {
int sleepInterval = GatewaySender.CONNECTION_RETRY_INTERVAL;
if (logger.isDebugEnabled()) {
logger.debug("Sleeping for {} milliseconds", sleepInterval);
}
Thread.sleep(sleepInterval);
} catch (InterruptedException ie) {
// log the exception
if (logger.isDebugEnabled()) {
logger.debug(ie.getMessage(), ie);
}
}
}
throw e;
}
return false;
}
use of org.apache.geode.internal.cache.wan.GatewaySenderException in project geode by apache.
the class PartitionedRegion method destroyParallelGatewaySenderRegion.
public void destroyParallelGatewaySenderRegion(Operation op, boolean cacheWrite, boolean lock, boolean callbackEvents) {
if (logger.isDebugEnabled()) {
logger.debug("Destoying parallel queue region for senders: {}", this.getParallelGatewaySenderIds());
}
boolean keepWaiting = true;
while (true) {
List<String> pausedSenders = new ArrayList<String>();
List<ConcurrentParallelGatewaySenderQueue> parallelQueues = new ArrayList<ConcurrentParallelGatewaySenderQueue>();
isDestroyedForParallelWAN = true;
int countOfQueueRegionsToBeDestroyed = 0;
for (String senderId : this.getParallelGatewaySenderIds()) {
AbstractGatewaySender sender = (AbstractGatewaySender) this.cache.getGatewaySender(senderId);
if (sender == null || sender.getEventProcessor() == null) {
continue;
}
if (cacheWrite) {
// resumed
if (sender.isPaused()) {
pausedSenders.add(senderId);
continue;
}
}
if (pausedSenders.isEmpty()) {
// if there are puase sender then only
// check for other pause senders instead
// of creating list of shadowPR
AbstractGatewaySenderEventProcessor ep = sender.getEventProcessor();
if (ep == null)
continue;
ConcurrentParallelGatewaySenderQueue parallelQueue = (ConcurrentParallelGatewaySenderQueue) ep.getQueue();
PartitionedRegion parallelQueueRegion = parallelQueue.getRegion(this.getFullPath());
// this may be removed in previous iteration
if (parallelQueueRegion == null || parallelQueueRegion.isDestroyed || parallelQueueRegion.isClosed) {
continue;
}
parallelQueues.add(parallelQueue);
countOfQueueRegionsToBeDestroyed++;
}
}
if (!pausedSenders.isEmpty()) {
String exception = null;
if (pausedSenders.size() == 1) {
exception = LocalizedStrings.PartitionedRegion_GATEWAYSENDER_0_IS_PAUSED_RESUME_IT_BEFORE_DESTROYING_USER_REGION_1.toLocalizedString(pausedSenders, this.getName());
} else {
exception = LocalizedStrings.PartitionedRegion_GATEWAYSENDERS_0_ARE_PAUSED_RESUME_THEM_BEFORE_DESTROYING_USER_REGION_1.toLocalizedString(pausedSenders, this.getName());
}
isDestroyedForParallelWAN = false;
throw new GatewaySenderException(exception);
}
if (countOfQueueRegionsToBeDestroyed == 0) {
break;
}
for (ConcurrentParallelGatewaySenderQueue parallelQueue : parallelQueues) {
PartitionedRegion parallelQueueRegion = parallelQueue.getRegion(this.getFullPath());
// keepWaiting : comes from the MAXIMUM_SHUTDOWN_WAIT_TIME case handled
if (cacheWrite && parallelQueueRegion.size() != 0 && keepWaiting) {
continue;
} else {
// In any case, destroy shadow PR locally. distributed destroy of
// userPR will take care of detsroying shadowPR locally on other
// nodes.
RegionEventImpl event = null;
if (op.isClose()) {
// In case of cache close operation, we want SPR's basic destroy to go
// through CACHE_CLOSE condition of postDestroyRegion not
// closePartitionedRegion code
event = new RegionEventImpl(parallelQueueRegion, op, null, false, getMyId(), generateEventID());
} else {
event = new RegionEventImpl(parallelQueueRegion, Operation.REGION_LOCAL_DESTROY, null, false, getMyId(), generateEventID());
}
parallelQueueRegion.basicDestroyRegion(event, false, lock, callbackEvents);
parallelQueue.removeShadowPR(this.getFullPath());
countOfQueueRegionsToBeDestroyed--;
continue;
}
}
if (countOfQueueRegionsToBeDestroyed == 0) {
break;
}
if (cacheWrite) {
if (AbstractGatewaySender.MAXIMUM_SHUTDOWN_WAIT_TIME == -1) {
keepWaiting = true;
try {
Thread.sleep(5000);
} catch (InterruptedException ignore) {
// interrupted
}
} else {
try {
Thread.sleep(AbstractGatewaySender.MAXIMUM_SHUTDOWN_WAIT_TIME * 1000);
} catch (InterruptedException ignore) {
/* ignore */
// interrupted
}
keepWaiting = false;
}
}
}
}
Aggregations