use of org.apache.geode.internal.cache.CacheClientStatus in project geode by apache.
the class ClientHealthMonitor method fillInClientInfo.
public void fillInClientInfo(Map allClients) {
// so weed those out.
synchronized (_clientThreadsLock) {
Iterator allClientsIterator = allClients.entrySet().iterator();
while (allClientsIterator.hasNext()) {
Map.Entry entry = (Map.Entry) allClientsIterator.next();
// proxyID
ClientProxyMembershipID proxyID = (ClientProxyMembershipID) entry.getKey();
// includes FQDN
CacheClientStatus cci = (CacheClientStatus) entry.getValue();
Set connections = (Set) this._clientThreads.get(proxyID);
if (connections != null) {
String memberId = null;
cci.setNumberOfConnections(connections.size());
List socketPorts = new ArrayList();
List socketAddresses = new ArrayList();
Iterator connectionsIterator = connections.iterator();
while (connectionsIterator.hasNext()) {
ServerConnection sc = (ServerConnection) connectionsIterator.next();
socketPorts.add(Integer.valueOf(sc.getSocketPort()));
socketAddresses.add(sc.getSocketAddress());
// each ServerConnection has the
memberId = sc.getMembershipID();
// same member id
}
cci.setMemberId(memberId);
cci.setSocketPorts(socketPorts);
cci.setSocketAddresses(socketAddresses);
}
}
}
}
use of org.apache.geode.internal.cache.CacheClientStatus in project geode by apache.
the class GetMemberInformationFunction method execute.
@Override
public void execute(FunctionContext functionContext) {
try {
Cache cache = CacheFactory.getAnyInstance();
/*
* TODO: 1) Get the CPU usage%
*/
InternalDistributedSystem system = (InternalDistributedSystem) cache.getDistributedSystem();
DistributionConfig config = system.getConfig();
String serverBindAddress = config.getServerBindAddress();
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
MemberInformation memberInfo = new MemberInformation();
memberInfo.setGroups(config.getGroups());
memberInfo.setLogFilePath(config.getLogFile().getCanonicalPath());
memberInfo.setStatArchiveFilePath(config.getStatisticArchiveFile().getCanonicalPath());
memberInfo.setWorkingDirPath(System.getProperty("user.dir"));
memberInfo.setCacheXmlFilePath(config.getCacheXmlFile().getCanonicalPath());
memberInfo.setLocators(config.getLocators());
memberInfo.setServerBindAddress(serverBindAddress);
memberInfo.setOffHeapMemorySize(config.getOffHeapMemorySize());
MemoryUsage memUsage = memoryMXBean.getHeapMemoryUsage();
memberInfo.setHeapUsage(Long.toString(bytesToMeg(memUsage.getUsed())));
memberInfo.setMaxHeapSize(Long.toString(bytesToMeg(memUsage.getMax())));
memberInfo.setInitHeapSize(Long.toString(bytesToMeg(memUsage.getInit())));
memberInfo.setHostedRegions(CliUtil.getAllRegionNames());
List<CacheServer> csList = cache.getCacheServers();
// A member is a server only if it has a cacheserver
if (csList != null) {
memberInfo.setServer(true);
Iterator<CacheServer> iters = csList.iterator();
while (iters.hasNext()) {
CacheServer cs = iters.next();
String bindAddress = cs.getBindAddress();
int port = cs.getPort();
boolean isRunning = cs.isRunning();
CacheServerInfo cacheServerInfo = new CacheServerInfo(bindAddress, port, isRunning);
memberInfo.addCacheServerInfo(cacheServerInfo);
}
Map<ClientProxyMembershipID, CacheClientStatus> allConnectedClients = InternalClientMembership.getStatusForAllClientsIgnoreSubscriptionStatus();
Iterator<ClientProxyMembershipID> it = allConnectedClients.keySet().iterator();
int numConnections = 0;
while (it.hasNext()) {
CacheClientStatus status = allConnectedClients.get(it.next());
numConnections = numConnections + status.getNumberOfConnections();
}
memberInfo.setClientCount(numConnections);
} else {
memberInfo.setServer(false);
}
functionContext.getResultSender().lastResult(memberInfo);
} catch (CacheClosedException e) {
functionContext.getResultSender().sendException(e);
} catch (Exception e) {
functionContext.getResultSender().sendException(e);
}
}
use of org.apache.geode.internal.cache.CacheClientStatus in project geode by apache.
the class GemFireMemberStatus method initializeServer.
protected void initializeServer() {
Collection servers = cache.getCacheServers();
if (servers.size() == 0) {
setIsServer(false);
} else {
setIsServer(true);
// Get connected clients.
// The following method returns a map of client member id to a cache
// client info. For now, keep track of the member ids in the set of
// _connectedClients.
Map allConnectedClients = InternalClientMembership.getStatusForAllClientsIgnoreSubscriptionStatus();
Iterator allConnectedClientsIterator = allConnectedClients.values().iterator();
while (allConnectedClientsIterator.hasNext()) {
CacheClientStatus ccs = (CacheClientStatus) allConnectedClientsIterator.next();
addConnectedClient(ccs.getMemberId());
// host address is available directly by id, hence CacheClientStatus need not be populated
putClientHostName(ccs.getMemberId(), ccs.getHostAddress());
}
// Get client queue sizes
Map clientQueueSize = getClientIDMap(InternalClientMembership.getClientQueueSizes());
setClientQueueSizes(clientQueueSize);
// Set server acceptor port (set it based on the first CacheServer)
CacheServer server = (CacheServer) servers.toArray()[0];
setServerPort(server.getPort());
// Get Client Health Stats
// Assert.assertTrue(cache != null); (cannot be null)
Region clientHealthMonitoringRegion = ClientHealthMonitoringRegion.getInstance((InternalCache) cache);
if (clientHealthMonitoringRegion != null) {
String[] clients = (String[]) clientHealthMonitoringRegion.keySet().toArray(new String[0]);
for (int i = 0; i < clients.length; i++) {
String clientId = clients[i];
ClientHealthStats stats = (ClientHealthStats) clientHealthMonitoringRegion.get(clientId);
setClientHealthStats(clientId, stats);
}
}
}
}
use of org.apache.geode.internal.cache.CacheClientStatus in project geode by apache.
the class CacheClientNotifier method getAllClients.
/**
* Return (possibly stale) list of all clients and their status
*
* @return Map, with CacheClientProxy as a key and CacheClientStatus as a value
*/
public Map getAllClients() {
Map clients = new HashMap();
for (Iterator iter = this._clientProxies.values().iterator(); iter.hasNext(); ) {
CacheClientProxy proxy = (CacheClientProxy) iter.next();
ClientProxyMembershipID proxyID = proxy.getProxyID();
clients.put(proxyID, new CacheClientStatus(proxyID));
}
return clients;
}
use of org.apache.geode.internal.cache.CacheClientStatus in project geode by apache.
the class ClientHealthMonitor method getStatusForAllClients.
/**
* 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 Map getStatusForAllClients() {
Map result = new HashMap();
synchronized (_clientThreadsLock) {
Iterator connectedClients = this._clientThreads.entrySet().iterator();
while (connectedClients.hasNext()) {
Map.Entry entry = (Map.Entry) connectedClients.next();
ClientProxyMembershipID proxyID = (ClientProxyMembershipID) entry.getKey();
CacheClientStatus cci = new CacheClientStatus(proxyID);
Set connections = (Set) this._clientThreads.get(proxyID);
if (connections != null) {
String memberId = null;
Iterator connectionsIterator = connections.iterator();
while (connectionsIterator.hasNext()) {
ServerConnection sc = (ServerConnection) connectionsIterator.next();
byte communicationMode = sc.getCommunicationMode();
/* Check for all modes that could be used for Client-Server communication */
if (communicationMode == Acceptor.CLIENT_TO_SERVER || communicationMode == Acceptor.PRIMARY_SERVER_TO_CLIENT || communicationMode == Acceptor.SECONDARY_SERVER_TO_CLIENT || communicationMode == Acceptor.CLIENT_TO_SERVER_FOR_QUEUE) {
// each ServerConnection has the same member id
memberId = sc.getMembershipID();
cci.setMemberId(memberId);
cci.setNumberOfConnections(connections.size());
result.put(proxyID, cci);
break;
}
}
}
}
}
return result;
}
Aggregations