Search in sources :

Example 1 with CacheClientStatus

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);
            }
        }
    }
}
Also used : CacheClientStatus(org.apache.geode.internal.cache.CacheClientStatus) HashSet(java.util.HashSet) Set(java.util.Set) ConcurrentHashSet(org.apache.geode.internal.concurrent.ConcurrentHashSet) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with CacheClientStatus

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);
    }
}
Also used : CacheClientStatus(org.apache.geode.internal.cache.CacheClientStatus) CacheClosedException(org.apache.geode.cache.CacheClosedException) MemoryUsage(java.lang.management.MemoryUsage) CacheServerInfo(org.apache.geode.management.internal.cli.domain.CacheServerInfo) CacheClosedException(org.apache.geode.cache.CacheClosedException) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) MemoryMXBean(java.lang.management.MemoryMXBean) MemberInformation(org.apache.geode.management.internal.cli.domain.MemberInformation) CacheServer(org.apache.geode.cache.server.CacheServer) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) Cache(org.apache.geode.cache.Cache)

Example 3 with CacheClientStatus

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);
            }
        }
    }
}
Also used : CacheClientStatus(org.apache.geode.internal.cache.CacheClientStatus) Iterator(java.util.Iterator) Collection(java.util.Collection) CacheServer(org.apache.geode.cache.server.CacheServer) HARegion(org.apache.geode.internal.cache.HARegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) ClientHealthMonitoringRegion(org.apache.geode.internal.admin.ClientHealthMonitoringRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) HashMap(java.util.HashMap) Map(java.util.Map) ClientHealthStats(org.apache.geode.internal.admin.remote.ClientHealthStats)

Example 4 with CacheClientStatus

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;
}
Also used : CacheClientStatus(org.apache.geode.internal.cache.CacheClientStatus) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Iterator(java.util.Iterator) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HAContainerMap(org.apache.geode.internal.cache.ha.HAContainerMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 5 with CacheClientStatus

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;
}
Also used : CacheClientStatus(org.apache.geode.internal.cache.CacheClientStatus) HashSet(java.util.HashSet) Set(java.util.Set) ConcurrentHashSet(org.apache.geode.internal.concurrent.ConcurrentHashSet) HashMap(java.util.HashMap) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

CacheClientStatus (org.apache.geode.internal.cache.CacheClientStatus)5 HashMap (java.util.HashMap)4 Iterator (java.util.Iterator)4 Map (java.util.Map)4 HashSet (java.util.HashSet)2 Set (java.util.Set)2 CacheServer (org.apache.geode.cache.server.CacheServer)2 ConcurrentHashSet (org.apache.geode.internal.concurrent.ConcurrentHashSet)2 MemoryMXBean (java.lang.management.MemoryMXBean)1 MemoryUsage (java.lang.management.MemoryUsage)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Cache (org.apache.geode.cache.Cache)1 CacheClosedException (org.apache.geode.cache.CacheClosedException)1 Region (org.apache.geode.cache.Region)1 DistributionConfig (org.apache.geode.distributed.internal.DistributionConfig)1 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)1