use of org.apache.geode.CancelException in project geode by apache.
the class HARegionQueue method updateHAContainer.
/**
* Called from destroy(), this method decrements the referenceCount of all the HAEventWrapper
* instances held by this queue. Also, removes those instances whose referenceCount becomes zero.
*
* @since GemFire 5.7
*/
private void updateHAContainer() {
try {
Object[] wrapperArray = null;
acquireReadLock();
try {
if (this.availableIDsSize() != 0) {
wrapperArray = this.availableIDsArray();
}
} finally {
releaseReadLock();
}
if (wrapperArray != null) {
final Set wrapperSet = new HashSet();
for (int i = 0; i < wrapperArray.length; i++) {
wrapperSet.add(this.region.get(wrapperArray[i]));
}
// Start a new thread which will update the clientMessagesRegion for
// each of the HAEventWrapper instances present in the wrapperSet
Thread regionCleanupTask = new Thread(new Runnable() {
public void run() {
try {
Iterator iter = wrapperSet.iterator();
while (iter.hasNext()) {
Conflatable conflatable = (Conflatable) iter.next();
if (conflatable instanceof HAEventWrapper) {
HARegionQueue.this.decAndRemoveFromHAContainer((HAEventWrapper) conflatable);
}
}
} catch (CancelException ignore) {
// we're done
return;
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("Exception in regionCleanupTask thread of HARegionQueue.updateHAContainer$run()", e);
}
}
}
});
regionCleanupTask.start();
}
} catch (CancelException e) {
throw e;
} catch (RegionDestroyedException e) {
// TODO does this really generate a CancelException, or do we still
// get a warning in the logs?
// Odds are we're shutting down...
this.getRegion().getCache().getCancelCriterion().checkCancelInProgress(e);
// If we get back, this is Really Weird. Treat it like the
// Exception case below.
logger.warn("HARegionQueue.updateHAContainer: underlying region has been destroyed", e);
} catch (Exception e) {
logger.warn(LocalizedMessage.create(LocalizedStrings.HARegionQueue_TASK_TO_DECREMENT_THE_REF_COUNT_MAY_NOT_HAVE_BEEN_STARTED), e);
}
}
use of org.apache.geode.CancelException in project geode by apache.
the class AcceptorImpl method accept.
/**
* {@linkplain ServerSocket#accept Listens}for a client to connect and then creates a new
* {@link ServerConnection}to handle messages from that client.
*/
@Override
public void accept() {
while (isRunning()) {
if (SystemFailure.getFailure() != null) {
// Allocate no objects here!
ServerSocket s = serverSock;
if (s != null) {
try {
s.close();
} catch (IOException e) {
// don't care
}
}
// throws
SystemFailure.checkFailure();
}
// moved this check out of the try. If we are cancelled then we need
// to break out of this while loop.
// throws
crHelper.checkCancelInProgress(null);
Socket s = null;
try {
s = serverSock.accept();
// throws
crHelper.checkCancelInProgress(null);
// Optionally enable SO_KEEPALIVE in the OS network protocol.
s.setKeepAlive(SocketCreator.ENABLE_TCP_KEEP_ALIVE);
synchronized (this.syncLock) {
if (!isRunning()) {
closeSocket(s);
break;
}
}
this.loggedAcceptError = false;
handOffNewClientConnection(s);
} catch (InterruptedIOException e) {
// Solaris only
closeSocket(s);
if (isRunning()) {
if (logger.isDebugEnabled()) {
logger.debug("Aborted due to interrupt: {}", e);
}
}
} catch (IOException e) {
if (isRunning()) {
if (e instanceof SSLException) {
try {
// Try to send a proper rejection message
ServerHandShakeProcessor.refuse(s.getOutputStream(), e.toString(), HandShake.REPLY_EXCEPTION_AUTHENTICATION_FAILED);
} catch (IOException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Bridge server: Unable to write SSL error");
}
}
}
}
closeSocket(s);
if (isRunning()) {
if (!this.loggedAcceptError) {
this.loggedAcceptError = true;
logger.error(LocalizedMessage.create(LocalizedStrings.AcceptorImpl_CACHE_SERVER_UNEXPECTED_IOEXCEPTION_FROM_ACCEPT, e));
}
// Why sleep?
// try {Thread.sleep(3000);} catch (InterruptedException ie) {}
}
} catch (CancelException e) {
closeSocket(s);
throw e;
} catch (Exception e) {
closeSocket(s);
if (isRunning()) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.AcceptorImpl_CACHE_SERVER_UNEXPECTED_EXCEPTION, e));
}
}
}
}
use of org.apache.geode.CancelException in project geode by apache.
the class AcceptorImpl method drainSelectorQueue.
private void drainSelectorQueue() {
ServerConnection sc = (ServerConnection) this.selectorQueue.poll();
CancelException cce = null;
while (sc != null) {
try {
finishCon(sc);
} catch (CancelException e) {
if (cce == null) {
cce = e;
}
}
sc = (ServerConnection) this.selectorQueue.poll();
}
Iterator it = selectorRegistrations.iterator();
while (it.hasNext()) {
try {
finishCon((ServerConnection) it.next());
} catch (CancelException e) {
if (cce == null) {
cce = e;
}
}
}
// while
if (cce != null) {
throw cce;
}
}
use of org.apache.geode.CancelException in project geode by apache.
the class AcceptorImpl method checkRegisteredKeys.
private int checkRegisteredKeys(int count) {
int result = count;
CancelException cce = null;
if (count > 0) {
Iterator it = this.selectorRegistrations.iterator();
while (it.hasNext()) {
ServerConnection sc = (ServerConnection) it.next();
if (isRegisteredObjectClosed(sc)) {
result--;
it.remove();
try {
finishCon(sc);
} catch (CancelException e) {
if (cce == null) {
cce = e;
}
}
}
}
// while
}
if (cce != null) {
throw cce;
}
return result;
}
use of org.apache.geode.CancelException in project geode by apache.
the class CacheClientNotifier method closeDeadProxies.
/**
* Close dead <code>CacheClientProxy</code> instances
*
* @param deadProxies The list of <code>CacheClientProxy</code> instances to close
*/
private void closeDeadProxies(List deadProxies, boolean stoppedNormally) {
final boolean isDebugEnabled = logger.isDebugEnabled();
for (Iterator i = deadProxies.iterator(); i.hasNext(); ) {
CacheClientProxy proxy = (CacheClientProxy) i.next();
if (isDebugEnabled)
logger.debug("CacheClientNotifier: Closing dead client: {}", proxy);
// Close the proxy
boolean keepProxy = false;
try {
keepProxy = proxy.close(false, stoppedNormally);
} catch (CancelException e) {
throw e;
} catch (Exception e) {
}
// proxy if it is durable.
if (keepProxy) {
logger.info(LocalizedMessage.create(LocalizedStrings.CacheClientNotifier_CACHECLIENTNOTIFIER_KEEPING_PROXY_FOR_DURABLE_CLIENT_NAMED_0_FOR_1_SECONDS_2, new Object[] { proxy.getDurableId(), Integer.valueOf(proxy.getDurableTimeout()), proxy }));
} else {
closeAllClientCqs(proxy);
if (isDebugEnabled) {
logger.debug("CacheClientNotifier: Not keeping proxy for non-durable client: {}", proxy);
}
removeClientProxy(proxy);
}
proxy.notifyRemoval();
}
// for
}
Aggregations