Search in sources :

Example 16 with CqService

use of org.apache.geode.cache.query.internal.cq.CqService in project geode by apache.

the class HARegionQueue method maintainCqStats.

private void maintainCqStats(Object event, long incrementAmount) {
    CqService cqService = region.getGemFireCache().getCqService();
    if (cqService != null) {
        try {
            if (event instanceof HAEventWrapper) {
                HAEventWrapper hw = (HAEventWrapper) event;
                if (hw.getClientUpdateMessage() != null) {
                    event = hw.getClientUpdateMessage();
                } else {
                    event = (Conflatable) this.haContainer.get(event);
                }
                if (event instanceof ClientUpdateMessage) {
                    if (((ClientUpdateMessage) event).hasCqs() && ((ClientUpdateMessage) event).hasCqs(clientProxyID)) {
                        CqNameToOp cqNames = ((ClientUpdateMessage) event).getClientCq(clientProxyID);
                        if (cqNames != null) {
                            for (String cqName : cqNames.getNames()) {
                                InternalCqQuery cq = ((InternalCqQuery) cqService.getClientCqFromServer(clientProxyID, cqName));
                                CqQueryVsdStats cqStats = cq.getVsdStats();
                                if (cq != null && cqStats != null) {
                                    cqStats.incNumHAQueuedEvents(incrementAmount);
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            // as maintaining cq stats should not affect the system.
            if (logger.isTraceEnabled()) {
                logger.trace("Exception while maintaining cq events stats.", e);
            }
        }
    }
}
Also used : ClientUpdateMessage(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessage) CqNameToOp(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.CqNameToOp) InternalCqQuery(org.apache.geode.cache.query.internal.cq.InternalCqQuery) CqService(org.apache.geode.cache.query.internal.cq.CqService) 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) HAEventWrapper(org.apache.geode.internal.cache.tier.sockets.HAEventWrapper) CqQueryVsdStats(org.apache.geode.cache.query.internal.CqQueryVsdStats)

Example 17 with CqService

use of org.apache.geode.cache.query.internal.cq.CqService in project geode by apache.

the class CacheClientProxy method closeClientCq.

// Only close the client cq if it is paused and no one is attempting to restart the proxy
public boolean closeClientCq(String clientCQName) throws CqException {
    if (testHook != null) {
        testHook.doTestHook("PRE_DRAIN_IN_PROGRESS");
    }
    synchronized (drainsInProgressLock) {
        numDrainsInProgress++;
    }
    if (testHook != null) {
        testHook.doTestHook("DRAIN_IN_PROGRESS_BEFORE_DRAIN_LOCK_CHECK");
    }
    try {
        // the numDrainsInProgress. That means we need to stop.
        if (drainLocked) {
            // someone is trying to restart a paused proxy
            String msg = LocalizedStrings.CacheClientProxy_COULD_NOT_DRAIN_CQ_DUE_TO_RESTARTING_DURABLE_CLIENT.toLocalizedString(clientCQName, proxyID.getDurableId());
            logger.info(msg);
            throw new CqException(msg);
        }
        // we can probably remove the isPaused check
        if (isPaused() && !isConnected()) {
            CqService cqService = getCache().getCqService();
            if (cqService != null) {
                InternalCqQuery cqToClose = cqService.getCq(cqService.constructServerCqName(clientCQName, this.proxyID));
                // close and drain
                if (cqToClose != null) {
                    cqService.closeCq(clientCQName, this.proxyID);
                    this._messageDispatcher.drainClientCqEvents(this.proxyID, cqToClose);
                } else {
                    String msg = LocalizedStrings.CqService_CQ_NOT_FOUND_FAILED_TO_CLOSE_THE_SPECIFIED_CQ_0.toLocalizedString(clientCQName);
                    logger.info(msg);
                    throw new CqException(msg);
                }
            }
        } else {
            String msg = LocalizedStrings.CacheClientProxy_COULD_NOT_DRAIN_CQ_DUE_TO_ACTIVE_DURABLE_CLIENT.toLocalizedString(clientCQName, proxyID.getDurableId());
            logger.info(msg);
            throw new CqException(msg);
        }
    } finally {
        synchronized (drainsInProgressLock) {
            numDrainsInProgress--;
        }
        if (testHook != null) {
            testHook.doTestHook("DRAIN_COMPLETE");
        }
    }
    return true;
}
Also used : CqException(org.apache.geode.cache.query.CqException) InternalCqQuery(org.apache.geode.cache.query.internal.cq.InternalCqQuery) CqService(org.apache.geode.cache.query.internal.cq.CqService)

Example 18 with CqService

use of org.apache.geode.cache.query.internal.cq.CqService in project geode by apache.

the class CacheServerBridge method getClientHealthStatus.

private ClientHealthStatus getClientHealthStatus(ClientConnInfo connInfo) {
    ClientProxyMembershipID proxyId = connInfo.getClientId();
    CacheClientProxy proxy = CacheClientNotifier.getInstance().getClientProxy(proxyId);
    if (proxy != null && !proxy.isConnected() && !proxyId.isDurable()) {
        return null;
    }
    CacheServerBridge.clientVersion.set(getClientVersion(connInfo));
    int clientCQCount = 0;
    CqService cqService = cache.getCqService();
    if (cqService != null) {
        List<ServerCQ> cqs = cqService.getAllClientCqs(proxyId);
        clientCQCount = cqs.size();
    }
    ClientHealthStatus status = new ClientHealthStatus();
    Region clientHealthMonitoringRegion = ClientHealthMonitoringRegion.getInstance(this.cache);
    String clientName = proxyId.getDSMembership();
    status.setClientId(connInfo.toString());
    status.setName(clientName);
    status.setHostName(connInfo.getHostName());
    status.setClientCQCount(clientCQCount);
    // Only available for clients having subscription enabled true
    if (proxy != null) {
        status.setUpTime(proxy.getUpTime());
        status.setQueueSize(proxy.getQueueSizeStat());
        status.setConnected(proxy.isConnected());
        status.setSubscriptionEnabled(true);
    } else {
        status.setConnected(true);
        status.setSubscriptionEnabled(false);
    }
    ClientHealthStats stats = (ClientHealthStats) clientHealthMonitoringRegion.get(clientName);
    if (stats != null) {
        status.setCpus(stats.getCpus());
        status.setNumOfCacheListenerCalls(stats.getNumOfCacheListenerCalls());
        status.setNumOfGets(stats.getNumOfGets());
        status.setNumOfMisses(stats.getNumOfMisses());
        status.setNumOfPuts(stats.getNumOfPuts());
        status.setNumOfThreads(stats.getNumOfThreads());
        status.setProcessCpuTime(stats.getProcessCpuTime());
        status.setPoolStats(stats.getPoolStats());
    }
    return status;
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) ClientHealthStatus(org.apache.geode.management.ClientHealthStatus) Region(org.apache.geode.cache.Region) ClientHealthMonitoringRegion(org.apache.geode.internal.admin.ClientHealthMonitoringRegion) ServerCQ(org.apache.geode.cache.query.internal.cq.ServerCQ) CqService(org.apache.geode.cache.query.internal.cq.CqService) ClientHealthStats(org.apache.geode.internal.admin.remote.ClientHealthStats)

Example 19 with CqService

use of org.apache.geode.cache.query.internal.cq.CqService in project geode by apache.

the class GetSubscriptionQueueSizeFunction method execute.

@Override
public void execute(FunctionContext context) {
    final Cache cache = CliUtil.getCacheIfExists();
    final String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
    String[] args = (String[]) context.getArguments();
    String durableClientId = null, cqName = null;
    SubscriptionQueueSizeResult result = new SubscriptionQueueSizeResult(memberNameOrId);
    durableClientId = args[0];
    cqName = args[1];
    try {
        CacheClientNotifier cacheClientNotifier = CacheClientNotifier.getInstance();
        if (cacheClientNotifier != null) {
            CacheClientProxy cacheClientProxy = cacheClientNotifier.getClientProxy(durableClientId);
            // Check if the client is present or not
            if (cacheClientProxy != null) {
                if (cqName != null && !cqName.isEmpty()) {
                    CqService cqService = cacheClientProxy.getCache().getCqService();
                    if (cqService != null) {
                        CqQuery cqQuery = cqService.getClientCqFromServer(cacheClientProxy.getProxyID(), cqName);
                        if (cqQuery != null) {
                            CqQueryVsdStats cqVsdStats = ((InternalCqQuery) cqQuery).getVsdStats();
                            if (cqVsdStats != null) {
                                long queueSize = cqVsdStats.getNumHAQueuedEvents();
                                result.setSubscriptionQueueSize(queueSize);
                            } else {
                                result.setErrorMessage(CliStrings.format(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE_CQ_STATS_NOT_FOUND, durableClientId, cqName));
                            }
                        } else {
                            result.setErrorMessage(CliStrings.format(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE_CQ_NOT_FOUND, durableClientId, cqName));
                        }
                    } else {
                        result.setErrorMessage(CliStrings.COUNT_DURABLE_CQ_EVENTS__NO__CQS__REGISTERED);
                    }
                } else {
                    result.setSubscriptionQueueSize(cacheClientNotifier.getDurableClientHAQueueSize(durableClientId));
                }
            } else {
                result.setErrorMessage(CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, durableClientId));
            }
        } else {
            result.setErrorMessage(CliStrings.NO_CLIENT_FOUND);
        }
    } catch (Exception e) {
        result.setExceptionMessage(e.getMessage());
    } finally {
        context.getResultSender().lastResult(result);
    }
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) CacheClientNotifier(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier) InternalCqQuery(org.apache.geode.cache.query.internal.cq.InternalCqQuery) InternalCqQuery(org.apache.geode.cache.query.internal.cq.InternalCqQuery) CqQuery(org.apache.geode.cache.query.CqQuery) SubscriptionQueueSizeResult(org.apache.geode.management.internal.cli.domain.SubscriptionQueueSizeResult) CqService(org.apache.geode.cache.query.internal.cq.CqService) Cache(org.apache.geode.cache.Cache) CqQueryVsdStats(org.apache.geode.cache.query.internal.CqQueryVsdStats)

Example 20 with CqService

use of org.apache.geode.cache.query.internal.cq.CqService in project geode by apache.

the class ListDurableCqNamesFunction method execute.

public void execute(final FunctionContext context) {
    final Cache cache = getCache();
    final DistributedMember member = cache.getDistributedSystem().getDistributedMember();
    String memberNameOrId = CliUtil.getMemberNameOrId(member);
    DurableCqNamesResult result = new DurableCqNamesResult(memberNameOrId);
    String durableClientId = (String) context.getArguments();
    try {
        CacheClientNotifier ccn = CacheClientNotifier.getInstance();
        if (ccn != null) {
            CacheClientProxy ccp = ccn.getClientProxy(durableClientId);
            if (ccp != null) {
                CqService cqService = ccp.getCache().getCqService();
                if (cqService != null && cqService.isRunning()) {
                    List<String> durableCqNames = cqService.getAllDurableClientCqs(ccp.getProxyID());
                    if (durableCqNames != null && !durableCqNames.isEmpty()) {
                        result.setCqNamesList(new ArrayList<String>(durableCqNames));
                    } else {
                        result.setErrorMessage(CliStrings.format(CliStrings.LIST_DURABLE_CQS__NO__CQS__FOR__CLIENT, durableClientId));
                    }
                } else {
                    result.setErrorMessage(CliStrings.LIST_DURABLE_CQS__NO__CQS__REGISTERED);
                }
            } else {
                result.setErrorMessage(CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, durableClientId));
            }
        } else {
            result.setErrorMessage(CliStrings.NO_CLIENT_FOUND);
        }
    } catch (Exception e) {
        result.setExceptionMessage(e.getMessage());
    } finally {
        context.getResultSender().lastResult(result);
    }
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) DurableCqNamesResult(org.apache.geode.management.internal.cli.domain.DurableCqNamesResult) CacheClientNotifier(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier) DistributedMember(org.apache.geode.distributed.DistributedMember) CqService(org.apache.geode.cache.query.internal.cq.CqService) Cache(org.apache.geode.cache.Cache)

Aggregations

CqService (org.apache.geode.cache.query.internal.cq.CqService)36 InternalCqQuery (org.apache.geode.cache.query.internal.cq.InternalCqQuery)15 CacheException (org.apache.geode.cache.CacheException)11 DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)11 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)10 IOException (java.io.IOException)9 Collection (java.util.Collection)9 Set (java.util.Set)8 CqException (org.apache.geode.cache.query.CqException)8 HashSet (java.util.HashSet)7 Region (org.apache.geode.cache.Region)7 ServerCQImpl (org.apache.geode.cache.query.internal.cq.ServerCQImpl)7 Host (org.apache.geode.test.dunit.Host)7 VM (org.apache.geode.test.dunit.VM)7 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)7 Test (org.junit.Test)7 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)6 Portfolio (org.apache.geode.cache.query.data.Portfolio)5 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)5 CacheServerStats (org.apache.geode.internal.cache.tier.sockets.CacheServerStats)5