Search in sources :

Example 61 with CancelException

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);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) TimeoutException(org.apache.geode.cache.TimeoutException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) CancelException(org.apache.geode.CancelException) InternalGemFireException(org.apache.geode.InternalGemFireException) CacheWriterException(org.apache.geode.cache.CacheWriterException) ConcurrentModificationException(java.util.ConcurrentModificationException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) Iterator(java.util.Iterator) CancelException(org.apache.geode.CancelException) Conflatable(org.apache.geode.internal.cache.Conflatable) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) HAEventWrapper(org.apache.geode.internal.cache.tier.sockets.HAEventWrapper)

Example 62 with CancelException

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));
            }
        }
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) ServerSocket(java.net.ServerSocket) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) CancelException(org.apache.geode.CancelException) SSLException(javax.net.ssl.SSLException) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CancelException(org.apache.geode.CancelException) EOFException(java.io.EOFException) SSLException(javax.net.ssl.SSLException) CancelledKeyException(java.nio.channels.CancelledKeyException) BindException(java.net.BindException) InterruptedIOException(java.io.InterruptedIOException) SocketException(java.net.SocketException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) SocketTimeoutException(java.net.SocketTimeoutException) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ClosedSelectorException(java.nio.channels.ClosedSelectorException) ToDataException(org.apache.geode.ToDataException)

Example 63 with CancelException

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;
    }
}
Also used : Iterator(java.util.Iterator) CancelException(org.apache.geode.CancelException)

Example 64 with CancelException

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;
}
Also used : Iterator(java.util.Iterator) CancelException(org.apache.geode.CancelException)

Example 65 with CancelException

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
}
Also used : Iterator(java.util.Iterator) CancelException(org.apache.geode.CancelException) CqException(org.apache.geode.cache.query.CqException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) UnsupportedVersionException(org.apache.geode.cache.UnsupportedVersionException) RegionExistsException(org.apache.geode.cache.RegionExistsException) CancelException(org.apache.geode.CancelException) AuthenticationRequiredException(org.apache.geode.security.AuthenticationRequiredException)

Aggregations

CancelException (org.apache.geode.CancelException)135 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)46 IOException (java.io.IOException)40 ReplyException (org.apache.geode.distributed.internal.ReplyException)30 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)25 CacheClosedException (org.apache.geode.cache.CacheClosedException)23 Region (org.apache.geode.cache.Region)22 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)21 LocalRegion (org.apache.geode.internal.cache.LocalRegion)18 Set (java.util.Set)16 Cache (org.apache.geode.cache.Cache)16 CacheException (org.apache.geode.cache.CacheException)16 HashSet (java.util.HashSet)15 Iterator (java.util.Iterator)15 QueryException (org.apache.geode.cache.query.QueryException)15 ArrayList (java.util.ArrayList)13 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)13 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)13 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)13 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)13