All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Alachisoft.NCache.Common.Monitoring.ServerMonitor Maven / Gradle / Ivy

There is a newer version: 5.3.3
Show newest version
package Alachisoft.NCache.Common.Monitoring;

import java.util.Iterator;
import java.util.Map;

public class ServerMonitor {

    private static boolean _monitor;
    private static java.util.HashMap _clientActivity = new java.util.HashMap();
    private static java.util.HashMap _threadClientMap = new java.util.HashMap();
    private static java.util.HashMap _dataStructures = new java.util.HashMap();
    private static java.util.HashMap _dedicatedThreadsActivity = new java.util.HashMap();
    private static java.util.Date _startTime = new java.util.Date(0);
    private static java.util.Date _endTime = new java.util.Date(0);
    private static Object _sync = new Object();

    public static java.util.Date getStartTime() {
        return _startTime;
    }

    public static java.util.Date getEndTime() {
        return _endTime;
    }

    public static boolean getMonitorActivity() {
        return _monitor;
    }

    public static void StartMonitoring() {
        synchronized (_sync) {
            if (_monitor) { //already started.
                return;
            }
            _monitor = true;
            _startTime = new java.util.Date();
        }
    }

    public static void StopMonitoring() {
        synchronized (_sync) {
            if (_monitor) {
                _monitor = false;
                _endTime = new java.util.Date();
            }
        }
    }

    public static void RegisterClient(String clientID, String address) {
        if (clientID == null) {
            return;
        }
        synchronized (_clientActivity) {
            if (!_clientActivity.containsKey(clientID)) {
                ClientMonitor clientActivity = new ClientMonitor(clientID, address);
                _clientActivity.put(clientID, clientActivity);
            }
        }
    }

    public static void UnregisterClient(String clientId) {
        if (clientId == null) {
            return;
        }
        synchronized (_clientActivity) {
            if (_clientActivity.containsKey(clientId)) {
                _clientActivity.remove(clientId);
            }
        }
    }

    public static void StartClientActivity(String clientId) {
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
//#if VS2005
        if (clientId == null) {
            return;
        }
        if (_monitor) {
            ClientMonitor cMonitor = (ClientMonitor) ((_clientActivity.get(clientId) instanceof ClientMonitor) ? _clientActivity.get(clientId) : null);
            if (cMonitor != null) {
                cMonitor.StartActivity();
            }
            long tId = Thread.currentThread().getId();

            synchronized (_threadClientMap) {
                _threadClientMap.put(tId, cMonitor);
            }
        }
//#endif
    }

    public static void StopClientActivity(String clientId) {
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
//#if VS2005

        if (_monitor) {
            ClientMonitor cMonitor = (ClientMonitor) ((_clientActivity.get(clientId) instanceof ClientMonitor) ? _clientActivity.get(clientId) : null);
            if (cMonitor != null) {
                cMonitor.StopActivity();
            }
            long tId = Thread.currentThread().getId();

            synchronized (_threadClientMap) {
                _threadClientMap.remove(tId);
            }
        }
//#endif
    }

    public static void LogClientActivity(String method, String activity) {
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
//#if VS2005

        if (_monitor) {
            ClientMonitor cMonitor = (ClientMonitor) ((_threadClientMap.get(Thread.currentThread().getId()) instanceof ClientMonitor) ? _threadClientMap.get(Thread.currentThread().getId()) : null);
            if (cMonitor != null) {
                cMonitor.LogActivity(method, activity);
            }
        }
//#endif
    }

    public static java.util.HashMap GetCompletedClientActivity() {
        java.util.HashMap activityTable = new java.util.HashMap();
        synchronized (_clientActivity) {
            Iterator ide = _clientActivity.entrySet().iterator();

            while (ide.hasNext()) {
                Map.Entry pair = (Map.Entry) ide.next();
                ClientMonitor cMonitor = (ClientMonitor) ((pair.getValue() instanceof ClientMonitor) ? pair.getValue() : null);
                activityTable.put(cMonitor.getInfo(), cMonitor.GetCompletedClientActivities());
            }
        }
        return activityTable;
    }

    public static java.util.HashMap GetCurrentClientActivity() throws CloneNotSupportedException {
        java.util.HashMap activityTable = new java.util.HashMap();
        synchronized (_clientActivity) {
            Iterator ide = _clientActivity.entrySet().iterator();

            while (ide.hasNext()) {
                Map.Entry pair = (Map.Entry) ide.next();
                ClientMonitor cMonitor = (ClientMonitor) ((pair.getValue() instanceof ClientMonitor) ? pair.getValue() : null);
                activityTable.put(cMonitor.getInfo(), cMonitor.GetCurrentClientActivities());
            }
        }
        return activityTable;
    }

    public static void Reset() {
        if (_clientActivity != null) {
            synchronized (_clientActivity) {
                _clientActivity.clear();
            }
        }
        if (_dedicatedThreadsActivity != null) {
            synchronized (_dedicatedThreadsActivity) {
                _dedicatedThreadsActivity.clear();
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy