Search in sources :

Example 16 with ClientProxyMembershipID

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

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

the class CqServiceImpl method getAllClientCqs.

@Override
public List<ServerCQ> getAllClientCqs(ClientProxyMembershipID clientProxyId) {
    Collection<? extends InternalCqQuery> cqs = getAllCqs();
    ArrayList<ServerCQ> clientCqs = new ArrayList<>();
    for (InternalCqQuery cq : cqs) {
        ServerCQImpl cQuery = (ServerCQImpl) cq;
        ClientProxyMembershipID id = cQuery.getClientProxyId();
        if (id != null && id.equals(clientProxyId)) {
            clientCqs.add(cQuery);
        }
    }
    return clientCqs;
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) ArrayList(java.util.ArrayList)

Example 18 with ClientProxyMembershipID

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

the class CqServiceUnitTest method constructCqServerNameShouldReturnSameResultRegardlessOfOptimizedCacheNames.

@Test
public void constructCqServerNameShouldReturnSameResultRegardlessOfOptimizedCacheNames() {
    CqServiceImpl cqService = new CqServiceImpl(Fakes.cache());
    ClientProxyMembershipID proxyMembershipID = new ClientProxyMembershipID(Fakes.cache().getDistributedSystem().getDistributedMember());
    String name1 = cqService.constructServerCqName("myCq", proxyMembershipID);
    String name2 = cqService.constructServerCqName("myCq", proxyMembershipID);
    assertEquals(name1, name2);
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 19 with ClientProxyMembershipID

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

the class HARegionQueue method addClientCQsAndInterestList.

public static void addClientCQsAndInterestList(ClientUpdateMessageImpl msg, HAEventWrapper haEventWrapper, Map haContainer, String regionName) {
    ClientProxyMembershipID proxyID = ((HAContainerWrapper) haContainer).getProxyID(regionName);
    if (haEventWrapper.getClientCqs() != null) {
        CqNameToOp clientCQ = haEventWrapper.getClientCqs().get(proxyID);
        if (clientCQ != null) {
            msg.addClientCqs(proxyID, clientCQ);
        }
    }
    // if (haEventWrapper.getPutInProgress()) {
    // ((HAEventWrapper)entry.getKey()).setPutInProgress(true);
    // }
    // This is a remote HAEventWrapper.
    // Add new Interested client lists.
    ClientUpdateMessageImpl clientMsg = (ClientUpdateMessageImpl) haEventWrapper.getClientUpdateMessage();
    if (clientMsg.isClientInterestedInUpdates(proxyID)) {
        msg.addClientInterestList(proxyID, true);
    } else if (clientMsg.isClientInterestedInInvalidates(proxyID)) {
        msg.addClientInterestList(proxyID, false);
    }
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) ClientUpdateMessageImpl(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl) CqNameToOp(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.CqNameToOp)

Example 20 with ClientProxyMembershipID

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

the class DistributedAckRegionCCEDUnitTest method testEntryVersionRollover.

@Test
public void testEntryVersionRollover() throws Exception {
    assumeTrue(getClass() == DistributedAckRegionCCEDUnitTest.class);
    final String name = this.getUniqueName() + "-CC";
    final int numEntries = 1;
    SerializableRunnable createRegion = new SerializableRunnable("Create Region") {

        public void run() {
            try {
                RegionFactory f = getCache().createRegionFactory(getRegionAttributes());
                CCRegion = (LocalRegion) f.create(name);
                for (int i = 0; i < numEntries; i++) {
                    CCRegion.put("cckey" + i, "ccvalue");
                }
                assertEquals("expected no conflated events", 0, CCRegion.getCachePerfStats().getConflatedEventsCount());
            } catch (CacheException ex) {
                org.apache.geode.test.dunit.Assert.fail("While creating region", ex);
            }
        }
    };
    VM vm0 = Host.getHost(0).getVM(0);
    vm0.invoke(createRegion);
    try {
        createRegion.run();
        VersionTag tag = new VMVersionTag();
        // set the version to the max - it should make the system think there's a rollover and reject
        // the change. Then apply it to the cache as if it is a replayed client operation. That should
        // cause the cache to apply the op locally
        tag.setEntryVersion(0xFFFFFF);
        tag.setDistributedSystemId(1);
        tag.setRegionVersion(CCRegion.getVersionVector().getNextVersion());
        VersionTagHolder holder = new VersionTagHolder(tag);
        ClientProxyMembershipID id = ClientProxyMembershipID.getNewProxyMembership(CCRegion.getDistributionManager().getSystem());
        CCRegion.basicBridgePut("cckey0", "newvalue", null, true, null, id, true, holder);
        vm0.invoke(new SerializableRunnable("check conflation count") {

            public void run() {
                assertEquals("expected one conflated event", 1, CCRegion.getCachePerfStats().getConflatedEventsCount());
            }
        });
    } finally {
        disconnectAllFromDS();
    }
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) RegionFactory(org.apache.geode.cache.RegionFactory) VersionTagHolder(org.apache.geode.internal.cache.VersionTagHolder) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

ClientProxyMembershipID (org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID)30 Test (org.junit.Test)10 IOException (java.io.IOException)7 CacheClientProxy (org.apache.geode.internal.cache.tier.sockets.CacheClientProxy)7 CqException (org.apache.geode.cache.query.CqException)6 ArrayList (java.util.ArrayList)5 Set (java.util.Set)5 CqService (org.apache.geode.cache.query.internal.cq.CqService)5 EventID (org.apache.geode.internal.cache.EventID)5 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)5 AcceptorImpl (org.apache.geode.internal.cache.tier.sockets.AcceptorImpl)5 CacheServerStats (org.apache.geode.internal.cache.tier.sockets.CacheServerStats)5 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)5 UnitTest (org.apache.geode.test.junit.categories.UnitTest)5 Iterator (java.util.Iterator)4 DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)4 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)4 HashSet (java.util.HashSet)3 CacheException (org.apache.geode.cache.CacheException)3 ServerCQ (org.apache.geode.cache.query.internal.cq.ServerCQ)3