Search in sources :

Example 21 with CacheClientProxy

use of org.apache.geode.internal.cache.tier.sockets.CacheClientProxy in project geode by apache.

the class CqServiceImpl method closeCq.

@Override
public void closeCq(String cqName, ClientProxyMembershipID clientProxyId) throws CqException {
    String serverCqName = cqName;
    if (clientProxyId != null) {
        serverCqName = this.constructServerCqName(cqName, clientProxyId);
        removeFromCacheForServerToConstructedCQName(cqName, clientProxyId);
    }
    ServerCQImpl cQuery = null;
    StringId errMsg = null;
    Exception ex = null;
    try {
        HashMap<String, CqQueryImpl> cqMap = cqQueryMap;
        if (!cqMap.containsKey(serverCqName)) {
            /*
         * gregp 052808: We should silently fail here instead of throwing error. This is to deal
         * with races in recovery
         */
            return;
        }
        cQuery = (ServerCQImpl) cqMap.get(serverCqName);
    } catch (CacheLoaderException e1) {
        errMsg = LocalizedStrings.CqService_CQ_NOT_FOUND_IN_THE_CQ_META_REGION_CQNAME_0;
        ex = e1;
    } catch (TimeoutException e2) {
        errMsg = LocalizedStrings.CqService_TIMEOUT_WHILE_TRYING_TO_GET_CQ_FROM_META_REGION_CQNAME_0;
        ex = e2;
    } finally {
        if (ex != null) {
            String s = errMsg.toLocalizedString(cqName);
            if (logger.isDebugEnabled()) {
                logger.debug(s);
            }
            throw new CqException(s, ex);
        }
    }
    try {
        cQuery.close(false);
        // CqBaseRegion
        try {
            LocalRegion baseRegion = cQuery.getCqBaseRegion();
            if (baseRegion != null && !baseRegion.isDestroyed()) {
                // Server specific clean up.
                if (isServer()) {
                    FilterProfile fp = baseRegion.getFilterProfile();
                    if (fp != null) {
                        fp.closeCq(cQuery);
                    }
                    CacheClientProxy clientProxy = cQuery.getCacheClientNotifier().getClientProxy(clientProxyId);
                    clientProxy.decCqCount();
                    if (clientProxy.hasNoCq()) {
                        this.stats.decClientsWithCqs();
                    }
                }
            }
        } catch (Exception e) {
            // May be cache is being shutdown
            if (logger.isDebugEnabled()) {
                logger.debug("Failed to remove CQ from the base region. CqName : {}", cqName);
            }
        }
        if (isServer()) {
            removeFromBaseRegionToCqNameMap(cQuery.getRegionName(), serverCqName);
        }
        LocalRegion baseRegion = cQuery.getCqBaseRegion();
        if (baseRegion.getFilterProfile().getCqCount() <= 0) {
            if (logger.isDebugEnabled()) {
                logger.debug("Should update the profile for this partitioned region {} for not requiring old value", baseRegion);
            }
        }
    } catch (CqClosedException cce) {
        throw new CqException(cce.getMessage());
    } finally {
        this.removeFromMatchingCqMap(cQuery);
    }
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) CqException(org.apache.geode.cache.query.CqException) CqClosedException(org.apache.geode.cache.query.CqClosedException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) TimeoutException(org.apache.geode.cache.TimeoutException) CqExistsException(org.apache.geode.cache.query.CqExistsException) CqException(org.apache.geode.cache.query.CqException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) InvalidDeltaException(org.apache.geode.InvalidDeltaException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) CqClosedException(org.apache.geode.cache.query.CqClosedException) QueryException(org.apache.geode.cache.query.QueryException) FilterProfile(org.apache.geode.internal.cache.FilterProfile) StringId(org.apache.geode.i18n.StringId) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) TimeoutException(org.apache.geode.cache.TimeoutException)

Example 22 with CacheClientProxy

use of org.apache.geode.internal.cache.tier.sockets.CacheClientProxy in project geode by apache.

the class ServerCQImpl method cleanup.

/**
   * Clears the resource used by CQ.
   */
@Override
protected void cleanup() throws CqException {
    // CqBaseRegion
    try {
        if (this.cqBaseRegion != null && !this.cqBaseRegion.isDestroyed()) {
            this.cqBaseRegion.getFilterProfile().closeCq(this);
            CacheClientProxy clientProxy = ccn.getClientProxy(clientProxyId);
            clientProxy.decCqCount();
            if (clientProxy.hasNoCq()) {
                cqService.stats().decClientsWithCqs();
            }
        }
    } catch (Exception ex) {
        // May be cache is being shutdown
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to remove CQ from the base region. CqName :{}", cqName);
        }
    }
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqExistsException(org.apache.geode.cache.query.CqExistsException) CqException(org.apache.geode.cache.query.CqException) CqClosedException(org.apache.geode.cache.query.CqClosedException) IOException(java.io.IOException) QueryException(org.apache.geode.cache.query.QueryException)

Example 23 with CacheClientProxy

use of org.apache.geode.internal.cache.tier.sockets.CacheClientProxy in project geode by apache.

the class Bug51400DUnitTest method verifyQueueSize.

public static void verifyQueueSize(Boolean isPrimary, Integer numOfEvents) throws Exception {
    CacheClientProxyStats stats = ((CacheClientProxy) CacheClientNotifier.getInstance().getClientProxies().toArray()[0]).getStatistics();
    if (isPrimary) {
        // marker
        numOfEvents = numOfEvents + 1;
    }
    long qSize = stats.getMessageQueueSize();
    assertEquals("Expected queue size: " + numOfEvents + " but actual size: " + qSize + " at " + (isPrimary ? "primary." : "secondary."), numOfEvents.intValue(), qSize);
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) CacheClientProxyStats(org.apache.geode.internal.cache.tier.sockets.CacheClientProxyStats)

Example 24 with CacheClientProxy

use of org.apache.geode.internal.cache.tier.sockets.CacheClientProxy in project geode by apache.

the class Simple2CacheServerDUnitTest method checkProxyIsPrimary.

private boolean checkProxyIsPrimary(VM vm) {
    SerializableCallable checkProxyIsPrimary = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            final CacheClientNotifier ccn = CacheClientNotifier.getInstance();
            Awaitility.waitAtMost(20, TimeUnit.SECONDS).until(() -> {
                return (ccn.getClientProxies().size() == 1);
            });
            Iterator iter_prox = ccn.getClientProxies().iterator();
            CacheClientProxy proxy = (CacheClientProxy) iter_prox.next();
            return proxy.isPrimary();
        }
    };
    return (Boolean) vm.invoke(checkProxyIsPrimary);
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) CacheClientNotifier(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Iterator(java.util.Iterator)

Aggregations

CacheClientProxy (org.apache.geode.internal.cache.tier.sockets.CacheClientProxy)24 CacheClientNotifier (org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier)11 ClientProxyMembershipID (org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID)7 IOException (java.io.IOException)6 CqException (org.apache.geode.cache.query.CqException)5 LocalRegion (org.apache.geode.internal.cache.LocalRegion)5 Cache (org.apache.geode.cache.Cache)4 CqClosedException (org.apache.geode.cache.query.CqClosedException)4 CqExistsException (org.apache.geode.cache.query.CqExistsException)4 StringId (org.apache.geode.i18n.StringId)4 QueryException (org.apache.geode.cache.query.QueryException)3 RegionNotFoundException (org.apache.geode.cache.query.RegionNotFoundException)3 CqService (org.apache.geode.cache.query.internal.cq.CqService)3 CacheServerImpl (org.apache.geode.internal.cache.CacheServerImpl)3 AcceptorImpl (org.apache.geode.internal.cache.tier.sockets.AcceptorImpl)3 Part (org.apache.geode.internal.cache.tier.sockets.Part)3 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)3 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 AttributesFactory (org.apache.geode.cache.AttributesFactory)2