/** * Returns the <code>CacheClientProxy</code> associated to the durableClientId * * @return the <code>CacheClientProxy</code> associated to the durableClientId */ public CacheClientProxy getClientProxy(String durableClientId) { return getClientProxy(durableClientId, false); }
/** * Returns the CacheClientProxy associated to the membershipID. This looks at both proxies that * are initialized and those that are still in initialization mode. */ public CacheClientProxy getClientProxy(ClientProxyMembershipID membershipID, boolean proxyInInitMode) { CacheClientProxy proxy = getClientProxy(membershipID); if (proxyInInitMode && proxy == null) { proxy = (CacheClientProxy) this._initClientProxies.get(membershipID); } return proxy; }
public CacheClientProxy getCacheClientProxy(ClientProxyMembershipID clientProxyId, CacheClientNotifier ccn) throws CqException { CacheClientProxy proxy = ccn.getClientProxy(clientProxyId, true); if (proxy == null) { throw new CqException("No Cache Client Proxy found while executing CQ."); } return proxy; }
public int getDurableClientHAQueueSize(String durableClientId) { CacheClientProxy ccp = getClientProxy(durableClientId); if (ccp == null) { return -1; } return ccp.getQueueSizeStat(); }
/** * The client represented by the proxyId is ready to receive updates. */ public void readyForEvents(ClientProxyMembershipID proxyId) { CacheClientProxy proxy = getClientProxy(proxyId); if (proxy == null) { // TODO: log a message } else { // False signifies that a marker message has not already been processed. // Generate and send one. proxy.startOrResumeMessageDispatcher(false); } }
public boolean closeClientCq(String durableClientId, String clientCQName) throws CqException { CacheClientProxy proxy = getClientProxy(durableClientId); // close and drain if (proxy != null) { return proxy.closeClientCq(clientCQName); } return false; }
@Override public ClientSession getClientSession(String durableClientId) { return getCacheClientNotifier().getClientProxy(durableClientId); }
/** * Sets keepalive on the proxy of the given membershipID * * @param membershipID Uniquely identifies the client pool * @since GemFire 5.7 */ public void setKeepAlive(ClientProxyMembershipID membershipID, boolean keepAlive) { if (logger.isDebugEnabled()) { logger.debug("CacheClientNotifier: setKeepAlive client: {}", membershipID); } CacheClientProxy proxy = getClientProxy(membershipID); if (proxy != null) { // Close the port if the proxy represents the client and contains the // port) // // If so, remove the port from the client's remote ports // proxy.removePort(clientPort); // Set the keepalive flag proxy.setKeepAlive(keepAlive); } }
/** * Unregisters client interest in the input region and key. * * @param regionName The name of the region of interest * @param keyOfInterest The name of the key of interest * @param isClosing Whether the caller is closing * @param membershipID The <code>ClientProxyMembershipID</code> of the client no longer interested * in this <code>Region</code> and key */ public void unregisterClientInterest(String regionName, Object keyOfInterest, int interestType, boolean isClosing, ClientProxyMembershipID membershipID, boolean keepalive) { if (logger.isDebugEnabled()) { logger.debug( "CacheClientNotifier: Client {} unregistering interest in: {} -> {} (an instance of {})", membershipID, regionName, keyOfInterest, keyOfInterest.getClass().getName()); } CacheClientProxy proxy = getClientProxy(membershipID); if (proxy != null) { proxy.setKeepAlive(keepalive); proxy.unregisterClientInterest(regionName, keyOfInterest, interestType, isClosing); } }
@Override public ClientSession getClientSession(DistributedMember member) { return getCacheClientNotifier().getClientProxy(ClientProxyMembershipID.getClientId(member)); }
/** * Unregisters client interest in the input region and list of keys. * * @param regionName The name of the region of interest * @param keysOfInterest The list of keys of interest * @param isClosing Whether the caller is closing * @param membershipID The <code>ClientProxyMembershipID</code> of the client no longer interested * in this <code>Region</code> and key */ public void unregisterClientInterest(String regionName, List keysOfInterest, boolean isClosing, ClientProxyMembershipID membershipID, boolean keepalive) { if (logger.isDebugEnabled()) { logger.debug("CacheClientNotifier: Client {} unregistering interest in: {} -> {}", membershipID, regionName, keysOfInterest); } CacheClientProxy proxy = getClientProxy(membershipID); if (proxy != null) { proxy.setKeepAlive(keepalive); proxy.unregisterClientInterest(regionName, keysOfInterest, isClosing); } }
/** * Unregisters an existing client from this server. * * @param memberId Uniquely identifies the client */ public void unregisterClient(ClientProxyMembershipID memberId, boolean normalShutdown) { if (logger.isDebugEnabled()) { logger.debug("CacheClientNotifier: Unregistering all clients with member id: {}", memberId); } CacheClientProxy proxy = getClientProxy(memberId); if (proxy != null) { final boolean isTraceEnabled = logger.isTraceEnabled(); if (isTraceEnabled) { logger.trace("CacheClientNotifier: Potential client: {}", proxy); } // If the proxy's member id is the same as the input member id, add // it to the set of dead proxies. if (!proxy.startRemoval()) { if (isTraceEnabled) { logger.trace("CacheClientNotifier: Potential client: {} matches {}", proxy, memberId); } closeDeadProxies(Collections.singletonList(proxy), normalShutdown); } } }
/** * Shuts down durable client proxy */ public boolean closeDurableClientProxy(String durableClientId) throws CacheException { CacheClientProxy ccp = getClientProxy(durableClientId); if (ccp == null) { return false; } // we can probably remove the isPaused check if (ccp.isPaused() && !ccp.isConnected()) { ccp.setKeepAlive(false); closeDeadProxies(Collections.singletonList(ccp), true); return true; } else { if (logger.isDebugEnabled()) { logger.debug("Cannot close running durable client: {}", durableClientId); } // TODO: never throw an anonymous inner class throw new CacheException("Cannot close a running durable client : " + durableClientId) {}; } }
private static void findLocalDurableQueues(ClientProxyMembershipID proxyId, ArrayList<ServerLocation> matches) { InternalCache cache = GemFireCacheImpl.getInstance(); if (cache != null) { List l = cache.getCacheServers(); if (l != null) { Iterator i = l.iterator(); while (i.hasNext()) { CacheServerImpl bs = (CacheServerImpl) i.next(); if (bs.getAcceptor().getCacheClientNotifier().getClientProxy(proxyId) != null) { ServerLocation loc = new ServerLocation(bs.getExternalAddress(), bs.getPort()); matches.add(loc); } } } } }
/** * this method uses CacheClientNotifier to try to obtain an ID that is equal to this one. This is * used during deserialization to reduce storage overhead. */ private ClientProxyMembershipID canonicalReference() { CacheClientNotifier ccn = CacheClientNotifier.getInstance(); if (ccn != null) { CacheClientProxy cp = ccn.getClientProxy(this, true); if (cp != null) { if (this.isCanonicalEquals(cp.getProxyID())) { return cp.getProxyID(); } } } return this; }
/** * 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); } } }
@Test public void closedCacheClientProxyInExecuteCqShouldThrowCQException() { InternalCache cache = mock(InternalCache.class); CancelCriterion cancelCriterion = mock(CancelCriterion.class); DistributedSystem distributedSystem = mock(DistributedSystem.class); doNothing().when(cancelCriterion).checkCancelInProgress(null); when(cache.getCancelCriterion()).thenReturn(cancelCriterion); when(cache.getDistributedSystem()).thenReturn(distributedSystem); ClientProxyMembershipID clientProxyMembershipID = mock(ClientProxyMembershipID.class); CacheClientNotifier cacheClientNotifier = mock(CacheClientNotifier.class); when(cacheClientNotifier.getClientProxy(clientProxyMembershipID, true)).thenReturn(null); CqServiceImpl cqService = new CqServiceImpl(cache); try { cqService.getCacheClientProxy(clientProxyMembershipID, cacheClientNotifier); fail(); } catch (Exception ex) { if (!(ex instanceof CqException && ex.getMessage() .contains("No Cache Client Proxy found while executing CQ."))) { fail(); } } } }
/** * Adds or updates entry in the dispatched message map when client sends an ack. * */ public boolean processDispatchedMessage(ClientProxyMembershipID proxyId, EventID eid) { boolean success = false; CacheClientProxy proxy = getClientProxy(proxyId); if (proxy != null) { HARegionQueue harq = proxy.getHARegionQueue(); harq.addDispatchedMessage(new ThreadIdentifier(eid.getMembershipID(), eid.getThreadID()), eid.getSequenceID()); success = true; } return success; }
private CliFunctionResult createFunctionResult(String memberNameOrId, String durableClientId) { try { CacheClientNotifier cacheClientNotifier = CacheClientNotifier.getInstance(); if (cacheClientNotifier == null) { return new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.ERROR, CliStrings.NO_CLIENT_FOUND); } CacheClientProxy ccp = cacheClientNotifier.getClientProxy(durableClientId); if (ccp == null) { return new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.ERROR, CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, durableClientId)); } boolean isClosed = cacheClientNotifier.closeDurableClientProxy(durableClientId); if (isClosed) { return new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.OK, CliStrings.format(CliStrings.CLOSE_DURABLE_CLIENTS__SUCCESS, durableClientId)); } else { return new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.ERROR, CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, durableClientId)); } } catch (Exception e) { return new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.ERROR, e.getMessage()); } }
@Override protected void process(ClusterDistributionManager dm) { // Get the proxy for the proxy id try { CacheClientNotifier clientNotifier = CacheClientNotifier.getInstance(); if (clientNotifier != null) { CacheClientProxy proxy = clientNotifier.getClientProxy(this.clientId); // If this VM contains a proxy for the requested proxy id, forward the // message on to the proxy for processing if (proxy != null) { proxy.processInterestMessage(this.clientMessage); } } } finally { ReplyMessage reply = new ReplyMessage(); reply.setProcessorId(this.processorId); reply.setRecipient(getSender()); try { dm.putOutgoing(reply); } catch (CancelException ignore) { // can't send a reply, so ignore the exception } } }