@Override protected boolean doHandShake(byte endpointType, int queueSize) { ClientHealthMonitor clientHealthMonitor = getAcceptor().getClientHealthMonitor(); clientHealthMonitor.registerClient(clientProxyMembershipID); clientHealthMonitor.addConnection(clientProxyMembershipID, this); return true; }
/** * This method returns the CacheClientStatus for all the clients that are connected to this * server. This method returns all clients irrespective of whether subscription is enabled or not. * * @return Map of ClientProxyMembershipID against CacheClientStatus objects. */ public static Map getStatusForAllClientsIgnoreSubscriptionStatus() { Map result = new HashMap(); if (ClientHealthMonitor.getInstance() != null) result = ClientHealthMonitor.getInstance().getStatusForAllClients(); return result; }
/** * Creates the singleton <code>CacheClientNotifier</code> instance. * * @param cache The GemFire <code>Cache</code> * @param maximumTimeBetweenPings The maximum time allowed between pings before determining the */ protected static synchronized void createInstance(InternalCache cache, int maximumTimeBetweenPings, CacheClientNotifierStats stats) { refCount++; if (_instance != null) { return; } _instance = new ClientHealthMonitor(cache, maximumTimeBetweenPings, stats); }
public void removeAllConnectionsAndUnregisterClient(ClientProxyMembershipID proxyID, Throwable t) { // Remove all connections cleanupClientThreads(proxyID, false); unregisterClient(proxyID, false, t); }
public static Map getConnectedIncomingGateways() { Map connectedIncomingGateways = null; ClientHealthMonitor chMon = ClientHealthMonitor.getInstance(); if (chMon == null) { connectedIncomingGateways = new HashMap(); } else { connectedIncomingGateways = chMon.getConnectedIncomingGateways(); } return connectedIncomingGateways; }
@Test public void idleServerConnectionTerminatedByHealthMonitor() throws Exception { ClientProxyMembershipID mockId = mock(ClientProxyMembershipID.class); ServerConnection mockConnection = mock(ServerConnection.class); clientHealthMonitor.addConnection(mockId, mockConnection); clientHealthMonitor.receivedPing(mockId); clientHealthMonitor.testUseCustomHeartbeatCheck((a, b, c) -> true); // Fail all heartbeats await() .untilAsserted(() -> verify(mockConnection).handleTermination(true)); }
@Override public void cmdExecute(final Message clientMessage, final ServerConnection serverConnection, final SecurityService securityService, long start) throws IOException { final boolean isDebugEnabled = logger.isDebugEnabled(); if (isDebugEnabled) { logger.debug("{}: rcv tx: {} from {} rcvTime: {}", serverConnection.getName(), clientMessage.getTransactionId(), serverConnection.getSocketString(), (DistributionStats.getStatTime() - start)); } ClientHealthMonitor chm = ClientHealthMonitor.getInstance(); if (chm != null) chm.receivedPing(serverConnection.getProxyID()); CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper(); writeReply(clientMessage, serverConnection); serverConnection.setAsTrue(RESPONDED); if (isDebugEnabled) { logger.debug("{}: Sent ping reply to {}", serverConnection.getName(), serverConnection.getSocketString()); } }
@Test public void testDoOneMessageNotifiesClientHealthMonitor() throws IOException { AcceptorImpl acceptorStub = mock(AcceptorImpl.class); ClientProtocolProcessor clientProtocolProcessor = mock(ClientProtocolProcessor.class); ServerConnection serverConnection = getServerConnection(clientProtocolProcessor, acceptorStub); serverConnection.doOneMessage(); ArgumentCaptor<ClientProxyMembershipID> clientProxyMembershipIDArgumentCaptor = ArgumentCaptor.forClass(ClientProxyMembershipID.class); verify(clientHealthMonitorMock).receivedPing(clientProxyMembershipIDArgumentCaptor.capture()); assertEquals("identity(localhost<ec>:0,connection=1", clientProxyMembershipIDArgumentCaptor.getValue().toString()); }
Thread.sleep(monitorInterval); if (logger.isTraceEnabled()) { logger.trace("Monitoring {} client(s)", getClientHeartbeats().size()); for (Iterator i = getClientHeartbeats().entrySet().iterator(); i.hasNext();) { Map.Entry entry = (Map.Entry) i.next(); ClientProxyMembershipID proxyID = (ClientProxyMembershipID) entry.getKey(); validateThreads(proxyID); if (cleanupClientThreads(proxyID, true)) { logger.warn( "Monitoring client with member id {}. It had been {} ms since the latest heartbeat. Max interval is {}. Terminated client.", logger.fatal(ClientHealthMonitor.this.toString() + ": An unexpected Exception occurred", e);
@Before public void setUp() { System.setProperty(ClientHealthMonitor.CLIENT_HEALTH_MONITOR_INTERVAL_PROPERTY, Integer.toString(monitorIntervalMillis)); InternalCache mockCache = mock(InternalCache.class); CacheClientNotifierStats mockStats = mock(CacheClientNotifierStats.class); clientHealthMonitor = ClientHealthMonitor.getInstance(mockCache, pingIntervalMillis, mockStats); }
/** * Caller must synchronize on cache.allClientServersLock * * @return all the clients */ public static Map getConnectedClients(InternalCache cache) { // Get all clients Map allClients = new HashMap(); for (Iterator bsii = cache.getCacheServers().iterator(); bsii.hasNext();) { CacheServerImpl bsi = (CacheServerImpl) bsii.next(); AcceptorImpl ai = bsi.getAcceptor(); if (ai != null && ai.getCacheClientNotifier() != null) { allClients.putAll(ai.getCacheClientNotifier().getAllClients()); } } // Fill in the missing info, if HealthMonitor started if (ClientHealthMonitor.getInstance() != null) ClientHealthMonitor.getInstance().fillInClientInfo(allClients); return allClients; }
ClientHealthMonitor chMon = ClientHealthMonitor.getInstance(); Set filterProxyIDs = null; if (onlyClientsNotifiedByThisServer) { Map map = chMon.getConnectedClients(filterProxyIDs);
ClientHealthMonitor chm = ClientHealthMonitor.getInstance(); chm.removeAllConnectionsAndUnregisterClient(proxyID, t); if (!getProxy().isDurable()) { getProxy().getCacheClientNotifier().unregisterClient(proxyID, false);
extractDelta = true; if (!extractDelta && ClientHealthMonitor.getInstance() != null) { extractDelta = ClientHealthMonitor.getInstance().hasDeltaClients();
/** * Processes a received ping for a client. * * @param proxyID The id of the client from which the ping was received */ public void receivedPing(ClientProxyMembershipID proxyID) { if (this._clientMonitor == null) { return; } if (logger.isTraceEnabled()) { logger.trace("ClientHealthMonitor: Received ping from client with member id {}", proxyID); } synchronized (_clientHeartbeatsLock) { if (!this._clientHeartbeats.containsKey(proxyID)) { registerClient(proxyID); } else { this._clientHeartbeats.put(proxyID, Long.valueOf(System.currentTimeMillis())); } } }
/** * Factory method to construct or return the singleton <code>ClientHealthMonitor</code> instance. * * @param cache The GemFire <code>Cache</code> * @param maximumTimeBetweenPings The maximum time allowed between pings before determining the * client has died and interrupting its sockets. * @return The singleton <code>ClientHealthMonitor</code> instance */ public static ClientHealthMonitor getInstance(InternalCache cache, int maximumTimeBetweenPings, CacheClientNotifierStats stats) { createInstance(cache, maximumTimeBetweenPings, stats); return _instance; }
this.stats.incClientUnRegisterRequests(); expireTXStates(proxyID);
@Test public void activeServerConnectionNotTerminatedByHealthMonitor() throws Exception { ClientProxyMembershipID mockId = mock(ClientProxyMembershipID.class); ServerConnection mockConnection = mock(ServerConnection.class); clientHealthMonitor.addConnection(mockId, mockConnection); clientHealthMonitor.receivedPing(mockId); HeartbeatOverride heartbeater = new HeartbeatOverride(); clientHealthMonitor.testUseCustomHeartbeatCheck(heartbeater); await().until(() -> heartbeater.numHeartbeats >= 5); // Check that we never tried to terminate the connection verify(mockConnection, times(0)).handleTermination(true); }
setClientDisconnectedException(e); } finally { acceptor.getClientHealthMonitor().receivedPing(this.clientProxyMembershipID);
/** * Removes an existing <code>CacheClientProxy</code> from the list of known client proxies * * @param proxy The <code>CacheClientProxy</code> to remove */ protected void removeClientProxy(CacheClientProxy proxy) { // this._logger.info(String.format("%s", "removing client proxy " + proxy, new // Exception("stack trace"))); ClientProxyMembershipID client = proxy.getProxyID(); this._clientProxies.remove(client); this._connectionListener.queueRemoved(); this.getCache().cleanupForClient(this, client); if (!(proxy.clientConflation == Handshake.CONFLATION_ON)) { ClientHealthMonitor chm = ClientHealthMonitor.getInstance(); if (chm != null) { chm.numOfClientsPerVersion.decrementAndGet(proxy.getVersion().ordinal()); } } }