Search in sources :

Example 6 with CacheClientNotifier

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

the class ContunuousQueryFunction method execute.

@Override
public void execute(FunctionContext context) {
    try {
        String clientID = (String) context.getArguments();
        InternalCache cache = getCache();
        if (cache.getCacheServers().size() > 0) {
            CacheServerImpl server = (CacheServerImpl) cache.getCacheServers().iterator().next();
            if (server != null) {
                AcceptorImpl acceptorImpl = server.getAcceptor();
                if (acceptorImpl != null) {
                    CacheClientNotifier cacheClientNotifier = acceptorImpl.getCacheClientNotifier();
                    if (cacheClientNotifier != null) {
                        Collection<CacheClientProxy> cacheClientProxySet = cacheClientNotifier.getClientProxies();
                        ClientInfo clientInfo = null;
                        boolean foundClientinCCP = false;
                        Iterator<CacheClientProxy> it = cacheClientProxySet.iterator();
                        while (it.hasNext()) {
                            CacheClientProxy ccp = it.next();
                            if (ccp != null) {
                                String clientIdFromProxy = ccp.getProxyID().getDSMembership();
                                if (clientIdFromProxy != null && clientIdFromProxy.equals(clientID)) {
                                    foundClientinCCP = true;
                                    String durableId = ccp.getProxyID().getDurableId();
                                    boolean isPrimary = ccp.isPrimary();
                                    clientInfo = new ClientInfo((durableId != null && durableId.length() > 0 ? "Yes" : "No"), (isPrimary == true ? cache.getDistributedSystem().getDistributedMember().getId() : ""), (isPrimary == false ? cache.getDistributedSystem().getDistributedMember().getId() : ""));
                                    break;
                                }
                            }
                        }
                        // try getting from server connections
                        if (foundClientinCCP == false) {
                            ServerConnection[] serverConnections = acceptorImpl.getAllServerConnectionList();
                            for (ServerConnection conn : serverConnections) {
                                ClientProxyMembershipID cliIdFrmProxy = conn.getProxyID();
                                if (clientID.equals(cliIdFrmProxy.getDSMembership())) {
                                    String durableId = cliIdFrmProxy.getDurableId();
                                    clientInfo = new ClientInfo((durableId != null && durableId.length() > 0 ? "Yes" : "No"), "N.A.", "N.A.");
                                }
                            }
                        }
                        context.getResultSender().lastResult(clientInfo);
                    }
                }
            }
        }
    } catch (Exception e) {
        context.getResultSender().lastResult("Exception in ContunuousQueryFunction =" + e.getMessage());
    }
    context.getResultSender().lastResult(null);
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) CacheClientNotifier(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier) InternalCache(org.apache.geode.internal.cache.InternalCache) ServerConnection(org.apache.geode.internal.cache.tier.sockets.ServerConnection) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) AcceptorImpl(org.apache.geode.internal.cache.tier.sockets.AcceptorImpl) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl)

Example 7 with CacheClientNotifier

use of org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier 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 8 with CacheClientNotifier

use of org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier 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)

Example 9 with CacheClientNotifier

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

the class UnregisterInterestTest method setUp.

@Before
public void setUp() throws Exception {
    this.unregisterInterest = new UnregisterInterest();
    MockitoAnnotations.initMocks(this);
    when(this.authzRequest.unregisterInterestAuthorize(eq(REGION_NAME), eq(KEY), eq(0))).thenReturn(this.unregisterInterestOperationContext);
    when(this.cache.getRegion(isA(String.class))).thenReturn(this.region);
    when(this.cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class));
    when(this.interestTypePart.getInt()).thenReturn(0);
    when(this.isClosingPart.getObject()).thenReturn(BYTE_ARRAY);
    when(this.keyPart.getStringOrObject()).thenReturn(KEY);
    when(this.keepAlivePart.getObject()).thenReturn(BYTE_ARRAY);
    when(this.message.getNumberOfParts()).thenReturn(5);
    when(this.message.getPart(eq(0))).thenReturn(this.regionNamePart);
    when(this.message.getPart(eq(1))).thenReturn(this.interestTypePart);
    when(this.message.getPart(eq(2))).thenReturn(this.keyPart);
    when(this.message.getPart(eq(3))).thenReturn(this.isClosingPart);
    when(this.message.getPart(eq(4))).thenReturn(this.keepAlivePart);
    when(this.regionNamePart.getString()).thenReturn(REGION_NAME);
    when(this.serverConnection.getCache()).thenReturn(this.cache);
    when(this.serverConnection.getCacheServerStats()).thenReturn(this.cacheServerStats);
    when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest);
    when(this.serverConnection.getReplyMessage()).thenReturn(this.replyMessage);
    when(this.serverConnection.getCachedRegionHelper()).thenReturn(mock(CachedRegionHelper.class));
    when(this.serverConnection.getErrorResponseMessage()).thenReturn(this.errorResponseMessage);
    when(this.serverConnection.getAcceptor()).thenReturn(this.acceptor);
    when(this.serverConnection.getClientVersion()).thenReturn(Version.CURRENT);
    when(this.valuePart.getObject()).thenReturn(CALLBACK_ARG);
    when(this.unregisterInterestOperationContext.getKey()).thenReturn(KEY);
    CacheClientNotifier ccn = mock(CacheClientNotifier.class);
    PowerMockito.mockStatic(CacheClientNotifier.class, Mockito.CALLS_REAL_METHODS);
    PowerMockito.when(CacheClientNotifier.getInstance()).thenReturn(ccn);
    when(this.acceptor.getCacheClientNotifier()).thenReturn(ccn);
}
Also used : CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) CacheClientNotifier(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier) CancelCriterion(org.apache.geode.CancelCriterion) Before(org.junit.Before)

Example 10 with CacheClientNotifier

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

the class PRDeltaPropagationDUnitTest method verifyDeltaSent.

public static void verifyDeltaSent(Integer deltas) {
    CacheClientNotifier ccn = ((CacheServerImpl) cache.getCacheServers().toArray()[0]).getAcceptor().getCacheClientNotifier();
    int numOfDeltasSent = ((CacheClientProxy) ccn.getClientProxies().toArray()[0]).getStatistics().getDeltaMessagesSent();
    assertTrue("Expected " + deltas + " deltas to be sent but " + numOfDeltasSent + " were sent.", numOfDeltasSent == deltas);
}
Also used : CacheClientNotifier(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier)

Aggregations

CacheClientNotifier (org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier)17 CacheClientProxy (org.apache.geode.internal.cache.tier.sockets.CacheClientProxy)11 Cache (org.apache.geode.cache.Cache)4 IOException (java.io.IOException)3 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)3 Set (java.util.Set)2 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)2 CqService (org.apache.geode.cache.query.internal.cq.CqService)2 CacheServerImpl (org.apache.geode.internal.cache.CacheServerImpl)2 AcceptorImpl (org.apache.geode.internal.cache.tier.sockets.AcceptorImpl)2 ClientProxyMembershipID (org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID)2 Part (org.apache.geode.internal.cache.tier.sockets.Part)2 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)2 MemberResult (org.apache.geode.management.internal.cli.domain.MemberResult)2 Iterator (java.util.Iterator)1 CancelCriterion (org.apache.geode.CancelCriterion)1 EvictionAttributes (org.apache.geode.cache.EvictionAttributes)1 Region (org.apache.geode.cache.Region)1 RegionAttributes (org.apache.geode.cache.RegionAttributes)1 Pool (org.apache.geode.cache.client.Pool)1