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

com.alachisoft.ncache.client.internal.statistics.PerfStatsCollector Maven / Gradle / Ivy

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.alachisoft.ncache.client.internal.statistics;

import Alachisoft.NCache.Caching.Statistics.StatsMetricsUtil;
import Alachisoft.NCache.Common.Enum.Time;
import Alachisoft.NCache.Common.IDisposable;
import Alachisoft.NCache.Common.Monitoring.Category;
import Alachisoft.NCache.Common.Monitoring.Counter;
import Alachisoft.NCache.Common.Monitoring.MetricsPublisher;
import Alachisoft.NCache.Common.ServiceConfiguration;
import Alachisoft.NCache.Common.Stats.UsageStats;
import Alachisoft.NCache.Management.CacheConfigManager;
import Alachisoft.NCache.Management.ICacheServer;
import Alachisoft.NCache.Management.NCacheRPCService;
import Alachisoft.NCache.Management.Statistics.StatisticsCounter;
import Util.CounterNames;
import com.alachisoft.ncache.common.caching.statistics.ClientCounters;
import com.alachisoft.ncache.common.caching.statistics.customcounters.*;
import com.alachisoft.ncache.common.caching.statistics.customcounters.systemcounters.VMCpuUsage;
import com.alachisoft.ncache.common.caching.statistics.customcounters.systemcounters.VMMemoryUsage;
import com.alachisoft.ncache.common.caching.statistics.customcounters.systemcounters.VMNetworkUsage;
import com.alachisoft.ncache.common.caching.statistics.monitoring.ClientMonitor;
import com.alachisoft.ncache.common.caching.statistics.monitoring.CounterIDMap;
import com.alachisoft.ncache.common.caching.statistics.monitoring.Monitor;
import com.alachisoft.ncache.common.caching.statistics.operations.ClientOperations;
import com.alachisoft.ncache.common.monitoring.*;
import com.alachisoft.ncache.runtime.util.NCDateTime;
import com.alachisoft.ncache.runtime.util.TimeSpan;

import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * @author Muneeb Shahid
 */
public class PerfStatsCollector implements StatisticsCounter, IDisposable, CounterMonitorableEntity {

    private String _cacheID;
    private String _port;
    Monitor monitor;
    private MetricsPublisher statsPublisher;
    ArrayList _availableCounters = new ArrayList();
    HashMap _ncacheClientCounters=new HashMap();
    private CounterIDMap _counterIDMap;
    private Thread _publishingThread;
    private boolean _publish;
    private java.util.Date _lastPublish = new java.util.Date();
    private static final int _publishingInterval = 1; // publishing counters interval is in seconds; i.e. 1 seconds
    private final Object _lockObj = new Object();
    private long _version;
    private NCacheRPCService NCache;
    private ICacheServer _cacheServer = null;
    private String PC_CATEGORY = "NCache Client";

    private ArrayList _pubsubCountersList = new ArrayList();

    private PerformanceCounter _pcClientRequestsPerSec;
    private PerformanceCounterBase _pcClientResponsesPerSec;
    private PerformanceCounterBase _pcTotalClientRequestsPerSec;
    private PerformanceCounterBase _pcTotalClientResponsesPerSec;

    private PerformanceCounter _pcAddPerSec;
    private PerformanceCounter _pcGetPerSec;
    private PerformanceCounter _pcUpdPerSec;
    private PerformanceCounter _pcDelPerSec;

    private PerformanceCounter _pcReadOperationsPerSec;
    private PerformanceCounter _pcWriteOperationsPerSec;

    private PerformanceCounter _pcEventProcesedPerSec;
    private PerformanceCounter _pcEventTriggeredPerSec;
    //Bulk Counters
    private AverageCounter _pcMsecPerAddBulkAvg;
    private PerformanceCounter _pcMsecPerAddBulkBase;
    private AverageCounter _pcMsecPerUpdBulkAvg;
    private PerformanceCounter _pcMsecPerUpdBulkBase;
    private AverageCounter _pcMsecPerGetBulkAvg;
    private PerformanceCounter _pcMsecPerGetBulkBase;
    private AverageCounter _pcMsecPerDelBulkAvg;
    private PerformanceCounter _pcMsecPerDelBulkBase;

    private AverageCounter _pcMsecPerGetAvg;
    private PerformanceCounter _pcMsecPerGetBase;
    private AverageCounter _pcMsecPerAddAvg;
    private PerformanceCounter _pcMsecPerAddBase;
    private AverageCounter _pcMsecPerUpdAvg;
    private PerformanceCounter _pcMsecPerUpdBase;
    private AverageCounter _pcMsecPerDelAvg;
    private PerformanceCounter _pcMsecPerDelBase;

    private UsageStats _usMsecPerGet = new UsageStats();
    private UsageStats _usMsecPerDel = new UsageStats();
    private UsageStats _usMsecPerUpd = new UsageStats();
    private UsageStats _usMsecPerAdd = new UsageStats();
    private UsageStats _usMsecPerEvent = new UsageStats();

    private AverageCounter _pcMsecPerEventAvg;
    private PerformanceCounter _pcMsecPerEventBase;


    private AverageCounter _pcMsecPerCompressionAvg;
    private PerformanceCounter _pcMsecPerCompressionAvgBase;
    private AverageCounter _pcMsecPerDecompressionAvg = null;
    private PerformanceCounter _pcMsecPerDecompressionAvgBase = null;

    private PerformanceCounter _pcCompressionPerSec;
    private PerformanceCounter _pcAvgCompressedItemSize;
    private PerformanceCounterBase _pcAvgCompressedItemSizeBase;

    private AverageCounter _pcMsecPerSerializationAvg;
    private AverageCounter _pcMsecPerDeserializationAvg;
    private PerformanceCounter _pcMsecPerSerializationAvgBase ;
    private PerformanceCounter _pcMsecPerDeserializationAvgBase;

    private AverageCounter _pcMsecPerDecryptionAvg;
    private PerformanceCounter _pcMsecPerDecryptionBase;
    private AverageCounter _pcMsecPerEncryptionAvg;
    private PerformanceCounter _pcMsecPerEncryptionBase;

    private AverageCounter _pcAvgItemSize;
    private PerformanceCounter _pcAvgItemSizeBase;

    private AverageCounter _pcMsecPerMessagePublishAvg;
    private PerformanceCounterBase _pcMsecPerMessagePublishBase;


    private PerformanceCounterBase _pcMessagePublishPerSec = null;
    private PerformanceCounterBase _pcMessageDeliverPerSec = null;

    private PerformanceCounter _pcReqrQueueSize;


    private PerformanceCounter _pcCpuUsage;
    private PerformanceCounter _pcMemoryUsage;
    private PerformanceCounter _pcNetworkUsage;
    private PerformanceCounter _pcRequestsPerSec;
    private PerformanceCounter _pollRequestsSent = null;
    /**
     * Resultant Updates from last poll request
     */
    private PerformanceCounter _pollLastUpdates = null;
    /**
     * Resultant Removes from last poll request
     */
    private PerformanceCounter _pollLastRemoves = null;
    private AverageCounter _pcMsecPerDecryptionAvgBase = null;

    private UsageStats _usMsecPerDecryption;
    private UsageStats _usMsecPerEncryption;
    private String _instanceName;
    private int GettingCacheServerIntervalDelay;
    private Category _privateCategory;

    public Category getCategory() {
        return _privateCategory;
    }

    public void setCategory(Category category) {
        _privateCategory = category;
    }

    public PerfStatsCollector(String instance, boolean inproc) {
        _instanceName = GetInstanceName(instance, 0, inproc);
        _cacheID=instance;
    }

    public PerfStatsCollector(String instanceName, int port, String cacheId)
    {
        _port = ":" + Integer.toString(port);
        _instanceName = GetInstanceName(instanceName, port, false);
        _cacheID = cacheId;
    }

    public PerfStatsCollector(String instance, int port, boolean inproc) {
        _instanceName = GetInstanceName(instance, port, inproc);
    }

    public final String GetInstanceName(String instanceName, int port, boolean inProc) {
        return !inProc ? instanceName : instanceName + " - " + ManagementFactory.getRuntimeMXBean().getName() + " - " + port;
    }

    /**
     * @param inProc
     * @throws Exception
     */
    public void initializePerfCounters(boolean inproc) throws Exception {
        FlipManager.Start();
        monitor = new ClientMonitor(_instanceName);

        monitor.startJMX();
        monitor.registerNode();

        _pcClientRequestsPerSec = new RateOfCounter(PC_CATEGORY, "Client Requests/sec", _instanceName);
        _pcClientResponsesPerSec = new RateOfCounter(PC_CATEGORY, "Client Responses/sec", _instanceName);
        _pcTotalClientRequestsPerSec = new RateOfCounter(PC_CATEGORY, "Total Client Requests/sec", "_Total_ client stats");
        _pcTotalClientResponsesPerSec = new RateOfCounter(PC_CATEGORY, "Total Client Responses/sec", "_Total_ client stats");

        _pcAddPerSec = new RateOfCounter(PC_CATEGORY,"Additions/sec", _instanceName);
        monitor.registerCounter(ClientOperations.AddsPerSec, _pcAddPerSec);
        _pcGetPerSec = new RateOfCounter(PC_CATEGORY,"Fetches/sec", _instanceName);
        monitor.registerCounter(ClientOperations.GetPerSec, _pcGetPerSec);
        _pcUpdPerSec = new RateOfCounter(PC_CATEGORY,"Updates/sec", _instanceName);
        monitor.registerCounter(ClientOperations.UpdPerSec, _pcUpdPerSec);
        _pcDelPerSec = new RateOfCounter(PC_CATEGORY,"Deletes/sec", _instanceName);
        monitor.registerCounter(ClientOperations.DelPerSec, _pcDelPerSec);

        _pcEventProcesedPerSec = new RateOfCounter(PC_CATEGORY,"Events Processed/sec", _instanceName);
        monitor.registerCounter(ClientOperations.EventProcessedPerSec, _pcEventProcesedPerSec);
        _pcEventTriggeredPerSec = new RateOfCounter(PC_CATEGORY,"Events Triggered/sec", _instanceName);
        monitor.registerCounter(ClientOperations.EventTriggeredPerSec, _pcEventTriggeredPerSec);

        _pcReadOperationsPerSec = new RateOfCounter(PC_CATEGORY,"Read Operations/sec", _instanceName);
        monitor.registerCounter(ClientOperations.ReadOperationsPerSec, _pcReadOperationsPerSec);
        _pcWriteOperationsPerSec = new RateOfCounter(PC_CATEGORY,"Write Operations/sec", _instanceName);
        monitor.registerCounter(ClientOperations.WriteOperationsPerSec, _pcWriteOperationsPerSec);

            _pcMsecPerAddBulkAvg = new AverageCounter(PC_CATEGORY, "Average us/addbulk", _instanceName);
            _pcMsecPerAddBulkBase = new RateOfCounter(PC_CATEGORY, "Average us/addbulk base", _instanceName);
            _pcMsecPerGetBulkAvg = new AverageCounter(PC_CATEGORY, "Average us/fetchbulk", _instanceName);
            _pcMsecPerGetBulkBase = new RateOfCounter(PC_CATEGORY, "Average us/fetchbulk base", _instanceName);
            _pcMsecPerUpdBulkAvg = new AverageCounter(PC_CATEGORY, "Average us/insertbulk", _instanceName);
            _pcMsecPerUpdBulkBase = new RateOfCounter(PC_CATEGORY, "Average us/insertbulk base", _instanceName);
            _pcMsecPerDelBulkAvg = new AverageCounter(PC_CATEGORY, "Average us/removebulk", _instanceName);
            _pcMsecPerDelBulkBase = new RateOfCounter(PC_CATEGORY, "Average us/removebulk base", _instanceName);

        _pcMsecPerUpdAvg = new AverageCounter(PC_CATEGORY,"Average us/insert", _instanceName);
        monitor.registerCounter(ClientOperations.MSecPerUpdateAvg, _pcMsecPerUpdAvg);
        _usMsecPerUpd = new UsageStats();
         _pcMsecPerUpdBase = new RateOfCounter("Average ms/insert base", _instanceName);
        monitor.registerCounter(ClientOperations.MSecPerUpdateBase, _pcMsecPerUpdBase);

        _pcMsecPerDelAvg = new AverageCounter(PC_CATEGORY,"Average us/remove", _instanceName);
        monitor.registerCounter(ClientOperations.MSecPerDelAvg, _pcMsecPerDelAvg);
        _usMsecPerDel = new UsageStats();
        _pcMsecPerDelBase = new RateOfCounter("Average ms/remove base", _instanceName);
        monitor.registerCounter(ClientOperations.MSecPerDelBase, _pcMsecPerDelBase);

        _pcMsecPerAddAvg = new AverageCounter(PC_CATEGORY,"Average us/add", _instanceName);
        monitor.registerCounter(ClientOperations.MSecPerAddAvg, _pcMsecPerAddAvg);
        _usMsecPerAdd = new UsageStats();
        _pcMsecPerAddBase = new RateOfCounter(PC_CATEGORY,"Average us/add base", _instanceName);
        monitor.registerCounter(ClientOperations.MSecPerAddBase, _pcMsecPerAddBase);

        _pcMsecPerGetAvg = new AverageCounter(PC_CATEGORY,"Average us/fetch", _instanceName);
        monitor.registerCounter(ClientOperations.MSecPerGetAvg, _pcMsecPerGetAvg);
        _pcMsecPerGetBase=new AverageCounter(PC_CATEGORY,"Average us/fetch base",_instanceName);

        _usMsecPerGet = new UsageStats();
        _pcMsecPerDelBase = new RateOfCounter(PC_CATEGORY,"Average us/remove base", _instanceName);


        _pcMsecPerEventAvg = new AverageCounter(PC_CATEGORY, "Average us/event", _instanceName);
        monitor.registerCounter(ClientOperations.AvgEventPerSec, _pcMsecPerEventAvg);
        _pcMsecPerEventBase = new RateOfCounter(PC_CATEGORY, "Average us/event base", _instanceName);
        _usMsecPerEvent = new UsageStats();


        _pcMsecPerCompressionAvg = new AverageCounter(PC_CATEGORY,"Average us/compression", _instanceName);
        monitor.registerCounter(ClientOperations.MsecPerCompressionAvg, _pcMsecPerCompressionAvg);
        _pcMsecPerCompressionAvgBase = new RateOfCounter(PC_CATEGORY, "Average us/compression base", _instanceName);
        _pcMsecPerDecompressionAvg = new AverageCounter(PC_CATEGORY,"Average us/decompression", _instanceName);
        monitor.registerCounter(ClientOperations.MSecPerDecompressionAvg, _pcMsecPerDecompressionAvg);
        _pcMsecPerDecompressionAvgBase = new RateOfCounter(PC_CATEGORY,"Average us/decompression base", _instanceName);
        monitor.registerCounter(ClientOperations.MSecPerDecompressionAvgBase, _pcMsecPerDecompressionAvgBase);

        _pcCompressionPerSec = new RateOfCounter(PC_CATEGORY,"Compression/sec", _instanceName);
        monitor.registerCounter(ClientOperations.CompressionPerSec, _pcCompressionPerSec);
        _pcAvgCompressedItemSize = new AverageCounter(PC_CATEGORY,"Average Compressed Item Size", _instanceName);
        monitor.registerCounter(ClientOperations.AvgCompressedItemSize, _pcAvgCompressedItemSize);
        _pcAvgCompressedItemSizeBase = new RateOfCounter(PC_CATEGORY, "Average Compressed Item Size base", _instanceName);

        _pcMsecPerDecryptionAvg = new AverageCounter(PC_CATEGORY,"Average us/decryption", _instanceName);
        monitor.registerCounter(ClientOperations.MSecPerDecryptionAvg, _pcMsecPerDecryptionAvg);
        _pcMsecPerDecryptionAvgBase = new AverageCounter(PC_CATEGORY,"Average us/decryption base", _instanceName);
        _usMsecPerDecryption = new UsageStats();
        _pcMsecPerDecryptionBase = new RateOfCounter(PC_CATEGORY,"Average ms/decryption base", _instanceName);
        monitor.registerCounter(ClientOperations.MSecPerDecryptionBase, _pcMsecPerDecryptionBase);

        _pcMsecPerEncryptionAvg = new AverageCounter(PC_CATEGORY,"Average us/encryption", _instanceName);
        monitor.registerCounter(ClientOperations.MSecPerEncryptionAvg, _pcMsecPerEncryptionAvg);
        _usMsecPerEncryption = new UsageStats();
        _pcMsecPerEncryptionBase = new AverageCounter(PC_CATEGORY,"Average ms/encryption base", _instanceName);
        monitor.registerCounter(ClientOperations.MSecPerEncryptionBase, _pcMsecPerEncryptionBase);

        _pcAvgItemSize = new AverageCounter(PC_CATEGORY,"Average Item Size", _instanceName);
        monitor.registerCounter(ClientOperations.AvgItemSize, _pcAvgItemSize);
        _pcAvgItemSizeBase = new RateOfCounter(PC_CATEGORY,"Average Item Size base", _instanceName);
        monitor.registerCounter(ClientOperations.AvgItemSizeBase, _pcAvgItemSizeBase);

            _pcMsecPerMessagePublishAvg = new AverageCounter(PC_CATEGORY, CounterNames.AvgPublishMessage, _instanceName);
            _pcMsecPerMessagePublishBase = new RateOfCounter(PC_CATEGORY, CounterNames.AvgPublishMessageBase, _instanceName);
            _pcMessagePublishPerSec = new RateOfCounter(PC_CATEGORY, CounterNames.MessagePublishPerSec, _instanceName);
            _pcMessageDeliverPerSec = new RateOfCounter(PC_CATEGORY, CounterNames.MessageDeliveryPerSec, _instanceName);

        _pcReqrQueueSize = new NumberOfItemCounter(PC_CATEGORY,"Request queue size", _instanceName);
        monitor.registerCounter(ClientOperations.RequestQueueSize, _pcReqrQueueSize);

        _pcRequestsPerSec = new RateOfCounter(PC_CATEGORY,"Requests Per Sec", _instanceName);
        monitor.registerCounter(ClientOperations.RequestsPerSec, _pcRequestsPerSec);
        // Poll Counters
        _pollRequestsSent = new NumberOfItemCounter(PC_CATEGORY, "# of Sync Poll Requests", _instanceName);
        _pollLastUpdates = new NumberOfItemCounter(PC_CATEGORY, "# of Last Sync Poll Updates", _instanceName);
        _pollLastRemoves = new NumberOfItemCounter(PC_CATEGORY, "# of Last Sync Poll Removes", _instanceName);

        _pcMsecPerSerializationAvg = new AverageCounter(PC_CATEGORY, "Average us/serialization", _instanceName);
        monitor.registerCounter(ClientOperations.MsecPerSerializationAvg, _pcMsecPerSerializationAvg);
        _pcMsecPerDeserializationAvg = new AverageCounter(PC_CATEGORY, "Average us/deserialization", _instanceName);
        _pcMsecPerSerializationAvgBase = new RateOfCounter(PC_CATEGORY, "Average us/serialization base", _instanceName );
        _pcMsecPerDeserializationAvgBase = new RateOfCounter(PC_CATEGORY, "Average us/deserialization base", _instanceName );
//        try {
//            _pcCpuUsage = new VMCpuUsage("Client Cpu Usage", _instanceName);
//            if(_pcCpuUsage != null)
//                monitor.registerCounter(ClientOperations.CpuUsage, _pcCpuUsage);
//        } catch (Throwable e) {
//        }
//
//        try {
//            _pcMemoryUsage = new VMMemoryUsage("Client Memory Usage", _instanceName);
//            if(_pcMemoryUsage != null)
//            monitor.registerCounter(ClientOperations.MemoryUsage, _pcMemoryUsage);
//        } catch (Throwable e) {
//        }
        _pubsubCountersList.add(_pcMsecPerMessagePublishAvg.getName());
        _pubsubCountersList.add(_pcMessagePublishPerSec.getName());
        //     _pubsubCountersList.Add(_pcMsecPerMessagePublishAvg.Name);
        _pubsubCountersList.add(_pcMessageDeliverPerSec.getName());
//        try {
//            _pcNetworkUsage =new VMNetworkUsage("Client Network Usage", _instanceName);
//            if(_pcNetworkUsage != null)
//                monitor.registerCounter(ClientOperations.NetworkUsage,_pcNetworkUsage);
//        } catch (Throwable e) {
//        }
        StoreCounters();
    }

    private void StoreCounters() {
        _ncacheClientCounters.put( _pcTotalClientRequestsPerSec.getName(), _pcTotalClientRequestsPerSec);
        _ncacheClientCounters.put(_pcTotalClientResponsesPerSec.getName(), _pcTotalClientResponsesPerSec);
        _ncacheClientCounters.put(_pcAddPerSec.getName(), _pcAddPerSec);
        _ncacheClientCounters.put(_pcGetPerSec.getName(), _pcGetPerSec);
        _ncacheClientCounters.put(_pcUpdPerSec.getName(), _pcUpdPerSec);
        _ncacheClientCounters.put(_pcDelPerSec.getName(), _pcDelPerSec);
        _ncacheClientCounters.put(_pcEventTriggeredPerSec.getName(), _pcEventTriggeredPerSec);
        _ncacheClientCounters.put(_pcEventProcesedPerSec.getName(), _pcEventProcesedPerSec);
        _ncacheClientCounters.put(_pcReadOperationsPerSec.getName(), _pcReadOperationsPerSec);
        _ncacheClientCounters.put(_pcWriteOperationsPerSec.getName(), _pcWriteOperationsPerSec);
        _ncacheClientCounters.put(_pcMsecPerAddBulkAvg.getName(), _pcMsecPerAddBulkAvg);
        _ncacheClientCounters.put(_pcMsecPerAddBulkBase.getName(), _pcMsecPerAddBulkBase);
        _ncacheClientCounters.put(_pcMsecPerGetBulkAvg.getName(), _pcMsecPerGetBulkAvg);
        _ncacheClientCounters.put(_pcMsecPerGetBulkBase.getName(), _pcMsecPerGetBulkBase);
        _ncacheClientCounters.put(_pcMsecPerUpdBulkAvg.getName(), _pcMsecPerUpdBulkAvg);
        _ncacheClientCounters.put(_pcMsecPerUpdBulkBase.getName(), _pcMsecPerUpdBulkBase);
        _ncacheClientCounters.put(_pcMsecPerDelBulkAvg.getName(), _pcMsecPerDelBulkAvg);
        _ncacheClientCounters.put(_pcMsecPerDelBulkBase.getName(), _pcMsecPerDelBulkBase);
        _ncacheClientCounters.put(_pcMsecPerGetAvg.getName(), _pcMsecPerGetAvg);
        _ncacheClientCounters.put(_pcMsecPerGetBase.getName(), _pcMsecPerGetBase);
        _ncacheClientCounters.put(_pcMsecPerAddAvg.getName(), _pcMsecPerAddAvg);
        _ncacheClientCounters.put(_pcMsecPerAddBase.getName(), _pcMsecPerAddBase);
        _ncacheClientCounters.put(_pcMsecPerUpdAvg.getName(), _pcMsecPerUpdAvg);
        _ncacheClientCounters.put(_pcMsecPerUpdBase.getName(), _pcMsecPerUpdBase);
        _ncacheClientCounters.put(_pcMsecPerDelAvg.getName(), _pcMsecPerDelAvg);
        _ncacheClientCounters.put(_pcMsecPerDelBase.getName(), _pcMsecPerDelBase);
        _ncacheClientCounters.put(_pcReqrQueueSize.getName(), _pcReqrQueueSize);
        _ncacheClientCounters.put(_pcCompressionPerSec.getName(), _pcCompressionPerSec);
        _ncacheClientCounters.put(_pcAvgItemSize.getName(), _pcAvgItemSize);
        _ncacheClientCounters.put(_pcMsecPerEventAvg.getName(), _pcMsecPerEventAvg);
        _ncacheClientCounters.put(_pcMsecPerEventBase.getName(), _pcMsecPerEventBase);
        _ncacheClientCounters.put(_pcMsecPerCompressionAvg.getName(), _pcMsecPerCompressionAvg);
        _ncacheClientCounters.put(_pcMsecPerCompressionAvgBase.getName(), _pcMsecPerCompressionAvgBase);
        _ncacheClientCounters.put(_pcMsecPerDecompressionAvg.getName(), _pcMsecPerDecompressionAvg);
        _ncacheClientCounters.put(_pcMsecPerDecompressionAvgBase.getName(), _pcMsecPerDecompressionAvgBase);
        _ncacheClientCounters.put(_pcAvgCompressedItemSize.getName(), _pcAvgCompressedItemSize);
        _ncacheClientCounters.put(_pcAvgCompressedItemSizeBase.getName(), _pcAvgCompressedItemSizeBase);
        _ncacheClientCounters.put(_pcMsecPerSerializationAvg.getName(), _pcMsecPerSerializationAvg);
        _ncacheClientCounters.put(_pcMsecPerSerializationAvgBase.getName(), _pcMsecPerSerializationAvgBase);
        _ncacheClientCounters.put(_pcMsecPerDeserializationAvg.getName(), _pcMsecPerDeserializationAvg);
        _ncacheClientCounters.put(_pcMsecPerDeserializationAvgBase.getName(), _pcMsecPerDeserializationAvgBase);
        _ncacheClientCounters.put(_pcMsecPerEncryptionAvg.getName(), _pcMsecPerEncryptionAvg);
        _ncacheClientCounters.put(_pcMsecPerEncryptionBase.getName(), _pcMsecPerEncryptionBase);
        _ncacheClientCounters.put(_pcMsecPerDecryptionAvg.getName(), _pcMsecPerDecryptionAvg);
        _ncacheClientCounters.put(_pcMsecPerDecryptionAvgBase.getName(), _pcMsecPerDecryptionAvgBase);

        _ncacheClientCounters.put(_pollRequestsSent.getName(), _pollRequestsSent);
        _ncacheClientCounters.put(_pollLastUpdates.getName(), _pollLastUpdates);
        _ncacheClientCounters.put(_pollLastRemoves.getName(), _pollLastRemoves);
        _ncacheClientCounters.put(_pcMsecPerMessagePublishAvg.getName(), _pcMsecPerMessagePublishAvg);
        _ncacheClientCounters.put(_pcMsecPerMessagePublishBase.getName(), _pcMsecPerMessagePublishBase);
        _ncacheClientCounters.put(_pcMessagePublishPerSec.getName(), _pcMessagePublishPerSec);
        _ncacheClientCounters.put(_pcMessageDeliverPerSec.getName(), _pcMessageDeliverPerSec);
    }

    public void incrementClientRequestsPerSecStatsBy(long requests) {
        if (_pcRequestsPerSec != null) {
            synchronized (_pcRequestsPerSec) {
                _pcRequestsPerSec.incrementBy(requests);
            }
        }
    }

    /**
     * Increment the performance counter for Cache update operations per second.
     */
    public void incrementAddPerSecStats() {
        if (_pcAddPerSec != null) {
            synchronized (_pcAddPerSec) {
                _pcAddPerSec.increment();
            }
        }

        if (_pcWriteOperationsPerSec != null) {
            synchronized (_pcWriteOperationsPerSec) {
                _pcWriteOperationsPerSec.increment();
            }
        }
    }

    /**
     * Increment the performance counter for Cache get operations per second.
     */
    public void incrementGetPerSecStats() {
        if (_pcGetPerSec != null) {
            synchronized (_pcGetPerSec) {
                _pcGetPerSec.increment();
            }
        }

        if (_pcReadOperationsPerSec != null) {
            synchronized (_pcReadOperationsPerSec) {
                _pcReadOperationsPerSec.increment();
            }
        }
    }

    /**
     * Increment the performance counter for Cache update operations per second.
     */
    public void incrementUpdPerSecStats() {
        if (_pcUpdPerSec != null) {
            synchronized (_pcUpdPerSec) {
                _pcUpdPerSec.increment();
            }
        }
        if (_pcWriteOperationsPerSec != null) {
            synchronized (_pcWriteOperationsPerSec) {
                _pcWriteOperationsPerSec.increment();
            }
        }
    }

    /**
     * Increment the performance counter for Cache remove operations per second.
     */
    public void incrementDelPerSecStats() {
        if (_pcDelPerSec != null) {
            synchronized (_pcDelPerSec) {
                _pcDelPerSec.increment();
            }
        }
        if (_pcWriteOperationsPerSec != null) {
            synchronized (_pcWriteOperationsPerSec) {
                _pcWriteOperationsPerSec.increment();
            }
        }
    }

    /**
     * Increments the performance counter for compression/sec.
     */
    public void incrementCompressionPerSec() {
        if (_pcCompressionPerSec != null) {
            synchronized (_pcCompressionPerSec) {
                _pcCompressionPerSec.increment();
            }
        }
    }

    //

    /**
     * Timestamps the start of sampling interval for Cache avg. and max. per mill-second time of fetch operations.
     */
    public void mSecPerGetBeginSample() {
        if (_pcMsecPerGetAvg != null) {
            synchronized (_usMsecPerGet) {
                _usMsecPerGet.BeginSample();
            }
        }
    }

    /**
     * Timestamps and updates the counter for Cache avg. and max. per mill-second time of fetch operations.
     */
    public void mSecPerGetEndSample() {
        if (_pcMsecPerGetAvg != null) {
            synchronized (_pcMsecPerGetAvg) {
                _usMsecPerGet.EndSample();
                _pcMsecPerGetAvg.incrementBy(Time.toMicroSeconds(_usMsecPerGet.getCurrent(), Time.nSEC));
                _pcMsecPerGetBase.increment();
            }
        }
    }
    //

    //

    /**
     * Timestamps the start of sampling interval for Cache avg. and max. per mill-second time of add operations.
     */
    public void mSecPerAddBeginSample() {
        if (_pcMsecPerAddAvg != null) {
            synchronized (_pcMsecPerAddAvg) {
                _usMsecPerAdd.BeginSample();
            }
        }
    }

    /**
     * Timestamps and updates the counter for Cache avg. and max. per mill-second time of add operations.
     */
    public void mSecPerAddEndSample() {
        if (_pcMsecPerAddAvg != null) {
            synchronized (_pcMsecPerAddAvg) {
                _usMsecPerAdd.EndSample();
                _pcMsecPerAddAvg.incrementBy(Time.toMicroSeconds(_usMsecPerAdd.getCurrent(), Time.nSEC));
                _pcMsecPerAddBase.increment();
            }
        }
    }
    //

    //

    /**
     * Timestamps the start of sampling interval for Cache avg. and max. per mill-second time of decryption operations.
     */
    public void mSecPerDecryptionBeginSample() {
        if (_pcMsecPerDecryptionAvg != null) {
            synchronized (_pcMsecPerDecryptionAvg) {
                _usMsecPerDecryption.BeginSample();
            }
        }
    }

    /**
     * Timestamps and updates the counter for Cache avg. and max. per mill-second time of decryption operations.
     */
    public void mSecPerDecryptionEndSample() {
        if (_pcMsecPerDecryptionAvg != null) {
            synchronized (_pcMsecPerDecryptionAvg) {
                _usMsecPerDecryption.EndSample();
                _pcMsecPerDecryptionAvg.incrementBy(Time.toMicroSeconds(_usMsecPerDecryption.getCurrent(), Time.nSEC));
                _pcMsecPerDecryptionBase.increment();
            }
        }
    }
    //

    //

    /**
     * Timestamps the start of sampling interval for Cache avg. and max. per mill-second time of encryption operations.
     */
    public void mSecPerEncryptionBeginSample() {
        if (_pcMsecPerEncryptionAvg != null) {
            synchronized (_pcMsecPerEncryptionAvg) {
                _usMsecPerEncryption.BeginSample();
            }
        }
    }

    /**
     * Timestamps and updates the counter for Cache avg. and max. per mill-second time of encryption operations.
     */
    public void mSecPerEncryptionEndSample() {
        if (_pcMsecPerEncryptionAvg != null) {
            synchronized (_pcMsecPerEncryptionAvg) {
                _usMsecPerEncryption.EndSample();
                _pcMsecPerEncryptionAvg.incrementBy(Time.toMicroSeconds(_usMsecPerEncryption.getCurrent(), Time.nSEC));
//                _pcMsecPerEncryptionBase.increment();
            }
        }
    }
    //

    //

    /**
     * Timestamps the start of sampling interval for Cache avg. and max. per mill-second time of Update operations.
     */
    public void mSecPerUpdateBeginSample() {
        if (_pcMsecPerUpdAvg != null) {
            synchronized (_pcMsecPerUpdAvg) {
                _usMsecPerUpd.BeginSample();
            }
        }
    }

    /**
     * Timestamps and updates the counter for Cache avg. and max. per mill-second time of Update operations.
     */
    public void mSecPerUpdateEndSample() {
        if (_pcMsecPerUpdAvg != null) {
            synchronized (_pcMsecPerUpdAvg) {
                _usMsecPerUpd.EndSample();
                _pcMsecPerUpdAvg.incrementBy(Time.toMicroSeconds(_usMsecPerUpd.getCurrent(), Time.nSEC));
                _pcMsecPerUpdBase.increment();
            }
        }
    }
    //

    //

    /**
     * Timestamps the start of sampling interval for Cache avg. and max. per mill-second time of Update operations.
     */
    public void mSecPerDelBeginSample() {
        if (_pcMsecPerDelAvg != null) {
            synchronized (_pcMsecPerDelAvg) {
                _usMsecPerDel.BeginSample();
            }
        }
    }

    /**
     * Timestamps and updates the counter for Cache avg. and max. per mill-second time of Update operations.
     */
    public void mSecPerDelEndSample() {
        if (_pcMsecPerDelAvg != null) {
            synchronized (_pcMsecPerDelAvg) {
                _usMsecPerDel.EndSample();
                _pcMsecPerDelAvg.incrementBy(Time.toMicroSeconds(_usMsecPerDel.getCurrent(), Time.nSEC));
                _pcMsecPerDelBase.increment();
            }
        }
    }
    //

    //

    //

    //
    public void incrementMsecPerCompression(long value) {
        if (_pcMsecPerCompressionAvg != null) {
            synchronized (_pcMsecPerCompressionAvg) {
                _pcMsecPerCompressionAvg.incrementBy(Time.toMicroSeconds(value * 1000000, Time.nSEC));
                _pcMsecPerCompressionAvgBase.increment();
            }
        }
    }
    //

    //
    public void incrementAvgCompressedItemSize(long value) {
        if (_pcAvgCompressedItemSize != null) {
            synchronized (_pcAvgCompressedItemSize) {
                _pcAvgCompressedItemSize.incrementBy(value);
                _pcAvgCompressedItemSizeBase.increment();
            }
        }
    }
    //


    //
    public void incrementMSecPerEvent(long value) {
        if (_pcMsecPerEventAvg != null) {
            synchronized (_pcMsecPerEventAvg) {
                _pcMsecPerEventAvg.incrementBy(value);
            }
        }
    }

    public void incrementMSecPerEvent() {
        if (_pcMsecPerEventAvg != null) {
            synchronized (_pcMsecPerEventAvg) {
                _pcMsecPerEventAvg.increment();
            }
        }
    }


    //

    //
    public void incrementEventProcessedPerSec(long value) {
        if (_pcEventProcesedPerSec != null) {
            synchronized (_pcEventProcesedPerSec) {
                _pcEventProcesedPerSec.incrementBy(value);
            }
        }
    }

    public void incrementEventProcessedPerSec() {
        if (_pcEventProcesedPerSec != null) {
            synchronized (_pcEventProcesedPerSec) {
                _pcEventProcesedPerSec.increment();
            }
        }
    }


    //

    //
    public void incrementEventTriggeredPerSec(long value) {
        if (_pcEventTriggeredPerSec != null) {
            synchronized (_pcEventTriggeredPerSec) {
                _pcEventTriggeredPerSec.incrementBy(value);
            }
        }
    }

    public void incrementEventTriggeredPerSec() {
        if (_pcEventTriggeredPerSec != null) {
            synchronized (_pcEventTriggeredPerSec) {
                _pcEventTriggeredPerSec.increment();
            }
        }
    }


    //


    /**
     * Increments the performance counter for Average Item Size.
     *
     * @param itemSize
     */
    public void incrementAvgItemSize(long itemSize) {
        if (_pcAvgItemSize != null) {
            synchronized (_pcAvgItemSize) {
                _pcAvgItemSize.incrementBy(itemSize);
                _pcAvgItemSizeBase.incrementBy(itemSize);
            }
        }
    }

    @Override
    public void msecPerGetBeginSample() {
        if (_pcMsecPerGetAvg != null)
        {
            synchronized (_usMsecPerGet)
            {
                _usMsecPerGet.BeginSample();
            }
        }
    }

    /**
     * Increment the performance counter for Mirror Queue size by one.
     */
    public void incrementRequestQueueSize() {
        if (_pcReqrQueueSize != null) {
            synchronized (_pcReqrQueueSize) {
                _pcReqrQueueSize.increment();
            }
        }
    }

    /**
     * Decrement the performance counter for Mirror Queue size by one.
     */
    public void decrementRequestQueueSize() {
        if (_pcReqrQueueSize != null) {
            synchronized (_pcReqrQueueSize) {
                if (_pcReqrQueueSize.getValue() > 0) {
                    _pcReqrQueueSize.decrement();
                }
            }
        }
    }

    public void incrementMsecPerSerialization(long value) {
        if (_pcMsecPerSerializationAvg != null) {
            synchronized (_pcMsecPerSerializationAvg) {
                _pcMsecPerSerializationAvg.incrementBy(Time.toMicroSeconds(value * 1000000, Time.nSEC));
                _pcMsecPerSerializationAvgBase.increment();
            }
        }
    }

    public final void incrementMsecPerEncryptionSample(long value) {
        if (_pcMsecPerEncryptionAvg != null) {
            synchronized (_pcMsecPerEncryptionAvg) {
                _pcMsecPerEncryptionAvg.incrementBy(value * 1000);
                _pcMsecPerEncryptionBase.increment();
            }
        }
    }

    @Override
    public void msecPerUpdBeginSample() {

    }

    public final void incrementMsecPerAddBulkSample(long value) {
        if (_pcMsecPerAddBulkAvg != null) {
            synchronized (_pcMsecPerAddBulkAvg) {
                _pcMsecPerAddBulkAvg.incrementBy(Time.toMicroSeconds(value,Time.nSEC));
                _pcMsecPerAddBulkBase.increment();
            }
        }
    }

    public final void incrementByAddPerSecStats(long value) {
        if (_pcAddPerSec != null) {
            synchronized (_pcAddPerSec) {
                _pcAddPerSec.incrementBy(value);
            }
        }

        if (_pcWriteOperationsPerSec != null) {
            synchronized (_pcWriteOperationsPerSec) {
                _pcWriteOperationsPerSec.incrementBy(value);
            }
        }
    }

    public final void incrementMsecPerUpdBulkSample(long value) {
        if (_pcMsecPerUpdBulkAvg != null) {
            synchronized (_pcMsecPerUpdBulkAvg) {
                _pcMsecPerUpdBulkAvg.incrementBy(Time.toMicroSeconds(value,Time.nSEC));
                _pcMsecPerUpdBulkBase.increment();
            }
        }
    }

    public final void incrementMsecPerUpdBulkSample(long value, long baseValue) {
        if (_pcMsecPerUpdBulkAvg != null) {
            synchronized (_pcMsecPerUpdBulkAvg) {
                _pcMsecPerUpdBulkAvg.incrementBy(value * 1000000);
                _pcMsecPerUpdBulkAvg.incrementBy(baseValue);
            }
        }
    }

    public final void incrementMsecPerDelBulkSample(long value) {
        if (_pcMsecPerDelBulkAvg != null) {
            synchronized (_pcMsecPerDelBulkAvg) {
                _pcMsecPerDelBulkAvg.incrementBy(Time.toMicroSeconds(value,Time.nSEC));
                _pcMsecPerDelBulkBase.increment();
            }
        }
    }

    @Override
    public void incrementRequestQueueSizeStats() {
        if (_pcReqrQueueSize != null)
        {
            synchronized (_pcReqrQueueSize)
            {
                _pcReqrQueueSize.increment();
            }
        }
    }

    @Override
    public void decrementRequestQueueSizeStats() {
        if (_pcReqrQueueSize != null)
        {
            synchronized (_pcReqrQueueSize)
            {
                if (_pcReqrQueueSize.getValue() > 0)
                {
                    _pcReqrQueueSize.decrement();
                }
            }
        }
    }

    @Override
    public void setPollRequestsCount(long value) {
        {
            synchronized (_pollRequestsSent)
            {
                _pollRequestsSent.setValue(value);
            }
        }
    }

    /**
     * Increment the performance counter for Cache update operations per second.
     */
    public final void incrementByUpdPerSecStats(long value) {
        if (_pcUpdPerSec != null) {
            synchronized (_pcUpdPerSec) {
                _pcUpdPerSec.incrementBy(value);
            }
        }

        if (_pcWriteOperationsPerSec != null) {
            synchronized (_pcWriteOperationsPerSec) {
                _pcWriteOperationsPerSec.incrementBy(value);
            }
        }
    }

    /**
     * Increment the performance counter for Cache remove operations per second.
     */
    public final void incrementByDelPerSecStats(long value) {
        if (_pcDelPerSec != null) {
            synchronized (_pcDelPerSec) {
                _pcDelPerSec.incrementBy(value);
            }
        }

        if (_pcWriteOperationsPerSec != null) {
            synchronized (_pcWriteOperationsPerSec) {
                _pcWriteOperationsPerSec.incrementBy(value);
            }
        }
    }

    @Override
    public void incrementAvgEventProcessingSample(long value) {
        if (_pcMsecPerEventAvg != null)
        {
            synchronized (_pcMsecPerEventAvg)
            {
                _pcMsecPerEventAvg.incrementBy(Time.toMicroSeconds(value * 1000000, Time.nSEC));
                _pcMsecPerEventBase.increment();
            }
        }
    }

    @Override
    public void incrementEventsProcessedPerSec() {
        if (_pcEventProcesedPerSec != null)
        {
            synchronized (_pcEventProcesedPerSec)
            {
                _pcEventProcesedPerSec.increment();
            }
        }
    }

    @Override
    public void incrementEventsTriggeredPerSeconds() {
        if (_pcEventTriggeredPerSec != null)
        {
            synchronized (_pcEventTriggeredPerSec)
            {
                _pcEventTriggeredPerSec.increment();
            }
        }
    }


    @Override
    public String getInstanceName() {
        return null;
    }

    @Override
    public void setInstanceName(String value) {

    }

    @Override
    public String getInstanceName(String instanceName, int port, boolean inProc) {
        return null;
    }

    @Override
    public boolean getUserHasAccessRights() {
        return false;
    }

    @Override
    public boolean getIsEnabled() {
        return false;
    }

    @Override
    public void setIsEnabled(boolean value) {

    }

    public void dispose() {
        try {
            synchronized (this) {
                if (monitor != null) {
                    if (_pcAddPerSec != null) {
                        monitor.unRegisterCounter(ClientOperations.AddsPerSec);
                    }
                    if (_pcMsecPerUpdBase != null) {
                        monitor.unRegisterCounter(ClientOperations.MSecPerUpdateBase);
                    }
                    if (_pcAvgItemSize != null) {
                        monitor.unRegisterCounter(ClientOperations.AvgItemSize);
                    }

                    if (_pcMsecPerCompressionAvg != null) {
                        monitor.unRegisterCounter(ClientOperations.MsecPerCompressionAvg);
                    }

                    if (_pcCompressionPerSec != null) {
                        monitor.unRegisterCounter(ClientOperations.CompressionPerSec);
                    }

                    if (_pcAvgCompressedItemSize != null) {
                        monitor.unRegisterCounter(ClientOperations.AvgCompressedItemSize);
                    }

                    if (_pcMsecPerSerializationAvg != null) {
                        monitor.unRegisterCounter(ClientOperations.MsecPerSerialization);
                    }

                    if (_pcMsecPerEventAvg != null) {
                        monitor.unRegisterCounter(ClientOperations.AvgEventPerSec);
                    }

                    if (_pcEventProcesedPerSec != null) {
                        monitor.unRegisterCounter(ClientOperations.EventProcessedPerSec);
                    }
                    if (_pcEventTriggeredPerSec != null) {
                        monitor.unRegisterCounter(ClientOperations.EventTriggeredPerSec);
                    }
                    if (_pcMsecPerUpdBase != null) {
                        monitor.unRegisterCounter(ClientOperations.MSecPerUpdateBase);
                    }
                    if (_pcMsecPerAddBase != null) {
                        monitor.unRegisterCounter(ClientOperations.MSecPerAddBase);
                    }
                    if (_pcMsecPerDecompressionAvg != null) {
                        monitor.unRegisterCounter(ClientOperations.MSecPerDecompressionAvg);
                    }
                    if (_pcMsecPerDecompressionAvgBase != null) {
                        monitor.unRegisterCounter(ClientOperations.MSecPerDecompressionAvgBase);
                    }
                    if (_pcMsecPerEventAvg != null) {
                        monitor.unRegisterCounter(ClientOperations.AvgEventPerSec);
                    }
                    if (_pcMsecPerGetAvg != null) {
                        monitor.unRegisterCounter(ClientOperations.MSecPerGet);
                    }
                    if (_pcMsecPerGetAvg != null) {
                        monitor.unRegisterCounter(ClientOperations.MSecPerGetAvg);
                    }
                    if (_pcMsecPerAddAvg != null) {
                        monitor.unRegisterCounter(ClientOperations.MSecPerAddAvg);
                    }
                    if (_pcMsecPerEncryptionAvg != null) {
                        monitor.unRegisterCounter(ClientOperations.MSecPerEncryptionAvg);
                    }
                    if (_pcMsecPerCompressionAvg != null) {
                        monitor.unRegisterCounter(ClientOperations.MsecPerCompressionAvg);
                    }
                    if (_pcMsecPerSerializationAvg != null) {
                        monitor.unRegisterCounter(ClientOperations.MsecPerSerializationAvg);
                    }
                    if (_pcAvgItemSizeBase != null)
                    {
                        monitor.unRegisterCounter(ClientOperations.AvgItemSizeBase);
                    }

                    monitor.unRegisterNode();
                    monitor.stopJMX();
                    monitor = null;
                }
                FlipManager.Stop();
            }

            statsPublisher.dispose();
            _pcClientRequestsPerSec.reset();
            _pcClientResponsesPerSec.reset();
            _pcTotalClientRequestsPerSec.reset();
            _pcTotalClientResponsesPerSec.reset();
            _pcAddPerSec.reset();
            _pcGetPerSec.reset();
            _pcUpdPerSec.reset();
            _pcDelPerSec.reset();

            _pcEventTriggeredPerSec.reset();
            _pcEventProcesedPerSec.reset();

            _pcReadOperationsPerSec.reset();
            _pcWriteOperationsPerSec.reset();


            //Bulk Counters
            _pcMsecPerAddBulkAvg.reset();
            _pcMsecPerGetBulkAvg.reset();
            _pcMsecPerUpdBulkAvg.reset();
            _pcMsecPerDelBulkAvg.reset();
            _pcMsecPerGetAvg.reset();
            _usMsecPerGet = new UsageStats();
            _pcMsecPerAddAvg.reset();
            _usMsecPerAdd.reset();
            _pcMsecPerUpdAvg.reset();
            _usMsecPerUpd.reset();
            _pcMsecPerDelAvg.reset();
            _usMsecPerDel.reset();
            _pcReqrQueueSize.reset();
            _pcCompressionPerSec.reset();
            _pcAvgItemSize.reset();

            _pcMsecPerEventAvg.reset();
            _usMsecPerEvent.reset();

            _usMsecPerDel.reset();

            _pcMsecPerCompressionAvg.reset();
            _pcMsecPerDecompressionAvg.reset();
            _pcAvgCompressedItemSize.reset();
            _pcMsecPerSerializationAvg.reset();
            _pcMsecPerDeserializationAvg.reset();
            _pcMsecPerEncryptionAvg.reset();
            _pcMsecPerDecryptionAvg.reset();
            // Poll Counters
            _pollRequestsSent.reset();
            _pollLastUpdates.reset();
            _pollLastRemoves.reset();

            _pcMsecPerMessagePublishAvg.reset();
            _pcMessagePublishPerSec.reset();
            _pcMessageDeliverPerSec.reset();

            _pcMsecPerAddBase.reset();
            _pcMsecPerDelBase.reset();
            _pcMsecPerGetBase.reset();
            _pcMsecPerUpdBase.reset();
            _pcMsecPerAddBulkBase.reset();
            _pcMsecPerGetBulkBase.reset();
            _pcMsecPerUpdBulkBase.reset();
            _pcMsecPerDelBulkBase.reset();
            _pcAvgItemSizeBase.reset();
            _pcMsecPerEventBase.reset();
            _pcMsecPerCompressionAvgBase.reset();
            _pcMsecPerDecompressionAvgBase.reset();
            _pcAvgCompressedItemSizeBase.reset();
            _pcMsecPerSerializationAvgBase.reset();
            _pcMsecPerDeserializationAvgBase.reset();
            _pcMsecPerDecryptionAvgBase.reset();
            _pcMsecPerEncryptionBase.reset();

            if(_publishingThread !=null && _publishingThread.isAlive())
            {

                _publishingThread.interrupt();
            }

            if(_cacheServer !=null )_cacheServer.dispose();
        } catch (Throwable e) {
        }

    }

    public void incrementMsecPerDelSample(long current) {
        if (_pcMsecPerDelAvg != null) {
            synchronized (_pcMsecPerDelAvg) {
                _pcMsecPerDelAvg .incrementBy(Time.toMicroSeconds(current , Time.nSEC));
                _pcMsecPerDelBase.increment();
            }
        }
    }

    @Override
    public void incrementMsecPerDelSample(long value, long baseValue) {
        if (_pcMsecPerDelAvg != null) {
            synchronized (_pcMsecPerDelAvg) {
                _pcMsecPerDelAvg .incrementBy(Time.toMicroSeconds(value , Time.nSEC));
                _pcMsecPerDelBase.incrementBy(baseValue);
            }
        }
    }

    @Override
    public void msecPerDelEndSample() {

    }

    public final void incrementMsecPerGetSample(long value) {
        if (_pcMsecPerDelAvg != null)
        {
            synchronized (_pcMsecPerGetAvg)
            {
                _pcMsecPerGetAvg.incrementBy(Time.toMicroSeconds(value , Time.nSEC)); //ts.Milliseconds);
                _pcMsecPerGetBase.increment();
            }
        }
    }

    @Override
    public void incrementMsecPerGetSample(long value, long baseValue) {
        if (_pcMsecPerDelAvg != null)
        {
            synchronized (_pcMsecPerGetAvg)
            {
                _pcMsecPerGetAvg.incrementBy(Time.toMicroSeconds(value, Time.nSEC)); //ts.Milliseconds);
                _pcMsecPerGetBase.incrementBy(baseValue);
            }
        }
    }

    @Override
    public void msecPerGetEndSample() {

    }

    @Override
    public void msecPerAddBeginSample() {

    }

    public void incrementMsecPerDecryptionSample(long value) {
        if (_pcMsecPerDecryptionAvg != null) {
            synchronized (_pcMsecPerDecryptionAvg) {
                _pcMsecPerDecryptionAvg.incrementBy(value * 1000);
                _pcMsecPerDecryptionAvgBase.increment();
            }
        }

    }

    public final void incrementMsecPerDeserialization(long value) {
        if (_pcMsecPerDeserializationAvg != null) {
            synchronized (_pcMsecPerDeserializationAvg) {
                _pcMsecPerDeserializationAvg.incrementBy(value * 1000000);
                _pcMsecPerDeserializationAvgBase.increment();
            }
        }
    }

    public final void incrementMsecPerGetBulkSample(long value) {
        if (_pcMsecPerGetBulkAvg != null) {
            synchronized (_pcMsecPerGetBulkAvg) {
                _pcMsecPerGetBulkAvg.incrementBy(Time.toMicroSeconds(value,Time.nSEC));
                _pcMsecPerGetBulkBase.increment();
            }
        }
    }

    public final void incrementByGetPerSecStats(long value) {
        if (_pcGetPerSec != null) {
            synchronized (_pcGetPerSec) {
                _pcGetPerSec.incrementBy(value);
            }
        }

        if (_pcReadOperationsPerSec != null) {
            synchronized (_pcReadOperationsPerSec) {
                _pcReadOperationsPerSec.incrementBy(value);
            }
        }
    }

    public void incrementMessageDeliverPerSec(long value) {
        if (_pubsubCountersList != null && _pubsubCountersList.size() > 0 && _pubsubCountersList.contains(CounterNames.MessageDeliveryPerSec)) {
            PerformanceCounter performanceCounter = _ncacheClientCounters.get(CounterNames.MessageDeliveryPerSec);
            if (performanceCounter != null) {
                synchronized (performanceCounter) {
                    performanceCounter.incrementBy(value);
                }
            }
        }
    }

    @Override
    public void startPublishingCounters(String bindIp) {
        if (!_publish) {
            if (bindIp == null)
                bindIp = ServiceConfiguration.getBindToClusterIP();
            if (NCache == null) {
                try {
                    NCache = new NCacheRPCService(null);
                } catch (Exception e) {

                }
            }
            NCache.setServerName(bindIp); //ServiceConfiguration.BindToClusterIP.ToString();
            if (NCache.getServerName() == null)
                return;
            if (NCache.getUseTcp())
                NCache.setPort(CacheConfigManager.getTcpPort());
            else
                NCache.setPort(CacheConfigManager.getHttpPort());
        }
        _publish = true;

        _publishingThread = new Thread(new Runnable() {
            @Override
            public void run() {
                PublishCounters();
            }
        });
        _publishingThread.setDaemon(true);
        _publishingThread.setName("CountersPublishingThread");
        _publishingThread.start();

    }

    @Override
    public void DecrementRequestQueueSizeStats() {
        if (_pcReqrQueueSize != null) {
            synchronized (_pcReqrQueueSize) {
                if (_pcReqrQueueSize.getValue() > 0) {
                    _pcReqrQueueSize.decrement();
                }
            }
        }
    }

    @Override
    public void IncrementEventsTriggeredPerSeconds(long pcEventTriggeredPerSec) {

    }

    @Override
    public void IncrementClientRequestsPerSecStats(long requests) {
        if (_pcClientRequestsPerSec != null)
        {
            synchronized (_pcClientRequestsPerSec)
            {
                _pcClientRequestsPerSec.incrementBy(requests);
                incrementTotalClientRequestsPerSecStats(requests);
            }
        }
    }

    @Override
    public void IncrementClientResponsesPerSecStats(long value) {
        if (_pcClientResponsesPerSec != null)
        {
            synchronized (_pcClientResponsesPerSec)
            {
                _pcClientResponsesPerSec.incrementBy(value);
                incrementTotalClientResponsesPerSecStats(value);
            }
        }
    }

    @Override
    public void IncrementTotalClientRequestsPerSecStats(long value) {

        if (_pcTotalClientRequestsPerSec != null)
        {
            synchronized (_pcTotalClientRequestsPerSec)
            {
                _pcTotalClientRequestsPerSec.incrementBy(value);
                incrementTotalClientRequestsPerSecStats(value);
            }
        }
    }

    @Override
    public void IncrementTotalClientResponsesPerSecStats(long value) {
        if (_pcTotalClientResponsesPerSec != null)
        {
            synchronized (_pcTotalClientResponsesPerSec)
            {
                _pcTotalClientResponsesPerSec.incrementBy(value);
                incrementTotalClientResponsesPerSecStats(value);
            }
        }
    }

    @Override
    public void IncrementByGetPerSecStats(long value) {
        if (_pcGetPerSec != null)
        {
            synchronized (_pcGetPerSec)
            {
                _pcGetPerSec.incrementBy(value);
            }
        }

        if (_pcReadOperationsPerSec != null)
        {
            synchronized (_pcReadOperationsPerSec)
            {
                _pcReadOperationsPerSec.incrementBy(value);
            }
        }

    }

    @Override
    public void IncrementByAddPerSecStats(long value) {
        if (_pcAddPerSec != null)
        {
            synchronized (_pcAddPerSec)
            {
                _pcAddPerSec.incrementBy(value);
            }
        }

        if (_pcWriteOperationsPerSec != null)
        {
            synchronized (_pcWriteOperationsPerSec)
            {
                _pcWriteOperationsPerSec.incrementBy(value);
            }
        }
    }

    @Override
    public void IncrementByUpdPerSecStats(long value) {
        if (_pcUpdPerSec != null) synchronized (_pcUpdPerSec) { _pcUpdPerSec.incrementBy(value); }

        if (_pcWriteOperationsPerSec != null)
        {
            synchronized (_pcWriteOperationsPerSec)
            {
                _pcWriteOperationsPerSec.incrementBy(value);
            }
        }

    }

    @Override
    public void IncrementByDelPerSecStats(long value) {
        if (_pcDelPerSec != null) synchronized (_pcDelPerSec) { _pcDelPerSec.incrementBy(value); }

        if (_pcWriteOperationsPerSec != null)
        {
            synchronized (_pcWriteOperationsPerSec)
            {
                _pcWriteOperationsPerSec.incrementBy(value);
            }
        }
    }

    @Override
    public void IncrementEventsProcessedPerSec(long value) {
        if (_pcEventProcesedPerSec != null)
        {
            synchronized (_pcEventProcesedPerSec)
            {
                _pcEventProcesedPerSec.increment();
            }
        }
    }

    @Override
    public void IncrementCompressionPerSec(long value) {
        if (_pcCompressionPerSec != null) synchronized (_pcCompressionPerSec) { _pcCompressionPerSec.increment(); }
    }

    @Override
    public void IncrementMsecPerMessagePublish(long value , long messageCount) {
        if (_pubsubCountersList != null && _pubsubCountersList.contains(CounterNames.AvgPublishMessage))
        {
            PerformanceCounter performanceCounter = _ncacheClientCounters.get(CounterNames.AvgPublishMessage);
            if (performanceCounter != null)
            {
                synchronized (performanceCounter)
                {
                    performanceCounter.incrementBy(value * 1000000 / TimeSpan.TicksPerMinute);
                    IncrementMessageCounter(CounterNames.AvgPublishMessageBase, messageCount);
                }
            }
        }

    }

    @Override
    public void IncrementMessageDeliverPerSec(long value) {
        if (_pubsubCountersList != null && _pubsubCountersList.size() > 0 && _pubsubCountersList.contains(CounterNames.MessageDeliveryPerSec))
        {
            PerformanceCounter performanceCounter = _ncacheClientCounters.get(CounterNames.MessageDeliveryPerSec);
            if (performanceCounter != null)
            {
                synchronized (performanceCounter)
                {
                    performanceCounter.incrementBy(value);
                }
            }
        }
    }

    @Override
    public void IncrementMessageCounter(String counterName, long value) {
        if (_pubsubCountersList != null && _pubsubCountersList.contains(counterName))
        {
            PerformanceCounter performanceCounter = _ncacheClientCounters.get(counterName);
            if (performanceCounter != null)
            {
                performanceCounter.incrementBy(value);
            }
        }
    }

    public void incrementMsecPerMessagePublish(long value) {
        if (_pubsubCountersList != null && _pubsubCountersList.contains(CounterNames.AvgPublishMessage)) {
            PerformanceCounter performanceCounter = _ncacheClientCounters.get(CounterNames.AvgPublishMessage);
            if (performanceCounter != null) {
                synchronized (performanceCounter) {
                    performanceCounter.incrementBy(value * 1000000);
                    incrementMessageCounter(CounterNames.AvgPublishMessageBase,1);
                }
            }
        }

    }

    public void incrementMessageCounter(String counterName,int incrementedValue) {
        if (_pubsubCountersList != null && _pubsubCountersList.contains(counterName)) {
            PerformanceCounter performanceCounter = _ncacheClientCounters.get(counterName);
            if (performanceCounter != null) {
                performanceCounter.incrementBy(incrementedValue);
            }
        }

    }

    public void incrementMessagePublishedPerSec(int value) {
        incrementMessageCounter(CounterNames.MessagePublishPerSec,value);
    }

    public void incrementMsecPerUpdSample(long current) {
        if (_pcMsecPerUpdAvg != null) {
            synchronized (_pcMsecPerUpdAvg) {
                _pcMsecPerUpdAvg.incrementBy(Time.toMicroSeconds(current,Time.nSEC));
                _pcMsecPerUpdBase.increment();
            }
        }
    }

    @Override
    public void incrementMsecPerUpdSample(long value, long baseValue) {
        if (_pcMsecPerUpdAvg != null) {
            synchronized (_pcMsecPerUpdAvg) {
                _pcMsecPerUpdAvg.incrementBy(Time.toMicroSeconds(value,Time.nSEC));
                _pcMsecPerUpdBase.incrementBy(baseValue);
            }
        }
    }

    @Override
    public void msecPerUpdEndSample() {

    }

    @Override
    public void msecPerDelBeginSample() {

    }

    public void incrementMsecPerAddSample(long current) {
        if (_pcMsecPerAddAvg != null) {
            synchronized (_pcMsecPerAddAvg) {
                _pcMsecPerAddAvg.incrementBy(Time.toMicroSeconds(current,Time.nSEC));
                _pcMsecPerAddBase.increment();
            }
        }
    }

    @Override
    public void incrementMsecPerAddSample(long value, long baseValue) {
        if (_pcMsecPerAddAvg != null) {
            synchronized (_pcMsecPerAddAvg) {
                _pcMsecPerAddAvg.incrementBy(Time.toMicroSeconds(value,Time.nSEC)); //ts.Milliseconds);
                _pcMsecPerAddBase.incrementBy(baseValue);
            }
        }
    }

    @Override
    public void msecPerAddEndSample() {

    }

    /// 
    /// Increments the performance counter for Average �s/compression.
    /// 
    /// Value to increment by
    public void incrementMsecPerDecompression(long value) {
        if (_pcMsecPerDecompressionAvg != null) {
            synchronized (_pcMsecPerDecompressionAvg) {
                _pcMsecPerDecompressionAvg.incrementBy(Time.toMicroSeconds(value * 1000000, Time.nSEC));
                _pcMsecPerDecompressionAvgBase.increment();
            }
        }
    }

    @Override
    public void incrementClientRequestsPerSecStats(long requests) {

    }

    @Override
    public void incrementClientResponsesPerSecStats(long responses) {
        if (_pcClientResponsesPerSec != null)
        {
            synchronized (_pcClientResponsesPerSec)
            {
                _pcClientResponsesPerSec.incrementBy(responses);
                incrementTotalClientResponsesPerSecStats(responses);
            }
        }
    }

    @Override
    public void incrementTotalClientRequestsPerSecStats(long requests) {
        if (_pcTotalClientRequestsPerSec != null)
        {
            synchronized (_pcTotalClientRequestsPerSec)
            {
                _pcTotalClientRequestsPerSec.incrementBy(requests);
            }
        }
    }

    @Override
    public void incrementTotalClientResponsesPerSecStats(long responses) {
        if (_pcTotalClientResponsesPerSec != null)
        {
            synchronized (_pcTotalClientResponsesPerSec)
            {
                _pcTotalClientResponsesPerSec.incrementBy(responses);
            }
        }
    }

    @Override
    public void incrementPollRequestCount() {
        if (_pollRequestsSent != null) {
            synchronized (_pollRequestsSent) {
                _pollRequestsSent.increment();
            }
        }
    }

    public void setPollLastUpdates(long value) {
        if (_pollLastUpdates != null) {
            synchronized (_pollLastUpdates) {
                _pollLastUpdates.setValue(value);
            }
        }
    }

    public void setPollLastRemoves(long value) {
        if (_pollLastRemoves != null) {
            synchronized (_pollLastRemoves) {
                _pollLastRemoves.setValue(value);
            }
        }
    }

    //region Monitoring

    public MetricsPublisher getStatsPublisher()
    {
        return statsPublisher;
    }

    public void setStatsPublisher(MetricsPublisher value)
    {
        statsPublisher = value;
    }

    public final void RegisterOnMetricsPublisher()
    {
        populateCounters();
        RegisterAsMonitorableEntity();
    }

    private void populateCounters()
    { try
        {
            if (getCategory()!= null && getCategory().getPublish())
            {
                for (Counter counter : getCategory().getCounters())
                {
                    PerformanceCounter performanceCounter;
                    if (counter.getPublish())
                    {
                        //if (counter.Name != _pcClientResponsesPerSec.CounterName || counter.Name != _pcClientRequestsPerSec.CounterName)
                        //{


                        if (_ncacheClientCounters.containsKey(counter.getName()))
                        {
                            performanceCounter=_ncacheClientCounters.get(counter.getName());
                            if (!_availableCounters.contains(performanceCounter))
                                _availableCounters.add(performanceCounter);
                        }
                        //}
                        //else
                        //{
                        //    if (_ncacheClientCounters.TryGetValue(counter.Name, out performanceCounter))
                        //    {
                        //        if (!_availableCounters.Contains(performanceCounter))
                        //            _availableCounters.Add(performanceCounter);
                        //    }
                        //    if (_ncacheClientCounters.TryGetValue($"Total{counter.Name}", out performanceCounter))
                        //    {
                        //        if (!_availableCounters.Contains(performanceCounter))
                        //            _availableCounters.Add(performanceCounter);
                        //    }
                        //}

                    }
                }
            }

        }
        catch (Exception ex)
        {
//            Logger.Error("Monitoring Module:", ex.getMessage());
        }
    }

    public final void RegisterAsMonitorableEntity()
    {
        if(_privateCategory != null && _privateCategory.getPublish())
            statsPublisher.RegisterMonitorableEntity(this);
    }

    private void GenerateIDMap(CounterMetadataCollection counterMetadataCollection)
    {
        _counterIDMap = new CounterIDMap();
        _counterIDMap.assignAndAddCounters(counterMetadataCollection.getCounters());
    }

    @Override
    public Publisher getPublisherType() {
        return Publisher.NCacheClient;
    }

    @Override
    public boolean getMergeCounters() {
        return false;
    }

    @Override
    public CounterMetadataCollection getMetadata() {
        CounterMetadataCollection counterMetadataCollection = StatsMetricsUtil.Metadata(ClientCounters.GetCounterCreationData(),Publisher.NCacheClient,getCategory());
        GenerateIDMap(counterMetadataCollection);
        counterMetadataCollection.setCategory(Publisher.NCacheClient);
        counterMetadataCollection.setInstanceName(ServiceConfiguration.getBindToClientServerIP().toString());
        counterMetadataCollection.setVersion("5.1");//Common.Monitoring.Version.GetVersion()
        return counterMetadataCollection;
    }

    @Override
    public IntervalCounterDataCollection getData() {
        java.util.HashMap counterData = new java.util.HashMap();
        synchronized (_availableCounters)
        {
            try
            {
                for (PerformanceCounter data : _availableCounters)
                {
                    if(data!=null){
                        if (data.getName().equals("Request Queue Size") || data.getName().equals("Average µs/Published Messages"))
                        {

                        }

                        if (_counterIDMap.getCounterID(data.getName()) != -10)
                        {
                            counterData.put(_counterIDMap.getCounterID(data.getName()), data.getValue());
                        }
                    }
                }
                IntervalCounterDataCollection tempVar = new IntervalCounterDataCollection();
                tempVar.setValues(counterData);
                tempVar.setTimestamp(NCDateTime.getUTCNow());//java.util.Date.UTCNow
                tempVar.setPublisherType(Publisher.NCacheClient);
                return tempVar;
            }
            catch (RuntimeException ex)
            {
                throw ex;
            }
        }
    }



    @Override
    public MonitoringEntityType getGetEntityType() {
        return MonitoringEntityType.Stats;
    }

    @Override
    public boolean getIsPrimary() {
        return true;
    }


    private void PublishCounters() {
        try {
            long currentVersion = -1;
            boolean error = false;
            TimeSpan normalPublishingInterval = TimeSpan.FromSeconds(_publishingInterval);
            TimeSpan errorRecoveryInterval = TimeSpan.FromSeconds(5);
            TimeSpan sleepInterval;
            while (_publish) {
                try {
                    if (_cacheServer == null)
                        _cacheServer = NCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                    if (!error)
                        sleepInterval = normalPublishingInterval;
                    else
                        sleepInterval = errorRecoveryInterval;

                    Thread.sleep(sleepInterval.getTotalMiliSeconds());

                    PublishCountersToNCacheService();
                    error = false;
                } catch (InterruptedException interruptedException) {
                    _publish = false;
                    error = true;
                } catch (Exception e) {
                    if (_cacheServer == null) {
                        Thread.sleep(GettingCacheServerIntervalDelay);
                        continue;
                    }
                    error = true;
                }
            }
        }
        catch (Exception e)
        {
        }
    }

    private void PublishCountersToNCacheService() {
        ClientCustomCounters counters = new ClientCustomCounters();
        if (_pcClientRequestsPerSec != null)
            counters._pcClientRequestsPerSec = _pcClientRequestsPerSec.getValue();
        if (_pcClientResponsesPerSec != null)
            counters._pcClientResponsesPerSec = _pcClientResponsesPerSec.getValue();
        if (_pcTotalClientRequestsPerSec != null)
            counters._pcTotalClientRequestsPerSec = _pcTotalClientRequestsPerSec.getValue();
        if (_pcTotalClientResponsesPerSec != null)
            counters._pcTotalClientResponsesPerSec = _pcTotalClientResponsesPerSec.getValue();
        if (_pcAddPerSec != null)
            counters._pcAddPerSec = _pcAddPerSec.getValue();
        if (_pcGetPerSec != null)
            counters._pcGetPerSec = _pcGetPerSec.getValue();
        if (_pcGetPerSec != null)
            counters._pcUpdPerSec = _pcUpdPerSec.getValue();
        if (_pcDelPerSec != null)
            counters._pcDelPerSec = _pcDelPerSec.getValue();
        if (_pcEventTriggeredPerSec != null)
            counters._pcEventTriggeredPerSec = _pcEventTriggeredPerSec.getValue();
        if (_pcEventProcesedPerSec != null)
            counters._pcEventProcesedPerSec = _pcEventProcesedPerSec.getValue();
        if (_pcReadOperationsPerSec != null)
            counters._pcReadOperationsPerSec = _pcReadOperationsPerSec.getValue();
        if (_pcWriteOperationsPerSec != null)
            counters._pcWriteOperationsPerSec = _pcWriteOperationsPerSec.getValue();
        if(_pcMemoryUsage!=null)
        {
            counters._pcMemoryUsage=_pcMemoryUsage.getValue()*1000000;
        }
        if(_pcCpuUsage!=null)
        {
            counters._pcCpuUsage=_pcCpuUsage.getValue();
        }
        if (_pcMsecPerAddBulkAvg != null)
        {
            counters._pcMsecPerAddBulkAvg = _pcMsecPerAddBulkAvg.getSum();
            counters._pcMsecPerAddBulkBase = _pcMsecPerAddBulkAvg.getTotalCount();
        }
        if (_pcMsecPerGetBulkAvg != null)
        {
            counters._pcMsecPerGetBulkAvg = _pcMsecPerGetBulkAvg.getSum();
            counters._pcMsecPerGetBulkBase = _pcMsecPerGetBulkAvg.getTotalCount();
        }
        if (_pcMsecPerUpdBulkAvg != null)
        {
            counters._pcMsecPerUpdBulkAvg = _pcMsecPerUpdBulkAvg.getSum();
            counters._pcMsecPerUpdBulkBase = _pcMsecPerUpdBulkAvg.getTotalCount();
        }
        if (_pcMsecPerDelBulkAvg != null)
        {
            counters._pcMsecPerDelBulkAvg = _pcMsecPerDelBulkAvg.getSum();
            counters._pcMsecPerDelBulkBase = _pcMsecPerDelBulkAvg.getTotalCount();
        }
        if (_pcMsecPerGetAvg != null)
        {
            counters._pcMsecPerGetAvg = _pcMsecPerGetAvg.getSum();
            counters._pcMsecPerGetBase = _pcMsecPerGetAvg.getTotalCount();
        }
        if (_pcMsecPerAddAvg != null)
        {
            counters._pcMsecPerAddAvg = _pcMsecPerAddAvg.getSum();
            counters._pcMsecPerAddBase = _pcMsecPerAddAvg.getTotalCount();
        }
        if (_pcMsecPerUpdAvg != null)
        {
            counters._pcMsecPerUpdAvg = _pcMsecPerUpdAvg.getSum();
            counters._pcMsecPerUpdBase = _pcMsecPerUpdAvg.getTotalCount();
        }
        if (_pcMsecPerDelAvg != null)
        {
            counters._pcMsecPerDelAvg = _pcMsecPerDelAvg.getSum();
            counters._pcMsecPerDelBase = _pcMsecPerDelAvg.getTotalCount();
        }

        if (_pcReqrQueueSize != null)
            counters._pcReqrQueueSize = _pcReqrQueueSize.getValue();
        if (_pcCompressionPerSec != null)
            counters._pcCompressionPerSec = _pcCompressionPerSec.getValue();
        if (_pcAvgItemSize != null)
        {
            counters._pcAvgItemSize = _pcAvgItemSize.getSum();
            counters._pcAvgItemSizeBase = _pcAvgItemSize.getTotalCount();
        }
        if (_pcMsecPerEventAvg != null)
        {
            counters._pcMsecPerEventAvg = _pcMsecPerEventAvg.getTotalCount();
            counters._pcMsecPerEventBase = _pcMsecPerEventAvg.getTotalCount();
        }
        if (_pcMsecPerCompressionAvg != null)
        {
            counters._pcMsecPerCompressionAvg = _pcMsecPerCompressionAvg.getSum();
            counters._pcMsecPerCompressionAvgBase = _pcMsecPerCompressionAvg.getTotalCount();
        }
        if (_pcMsecPerDecompressionAvg != null)
        {
            counters._pcMsecPerDecompressionAvg = _pcMsecPerDecompressionAvg.getSum();
            counters._pcMsecPerDecompressionAvgBase = _pcMsecPerDecompressionAvg.getTotalCount();
        }
        if (_pcAvgCompressedItemSize != null)
            counters._pcAvgCompressedItemSize = _pcAvgCompressedItemSize.getValue();
        if (_pcMsecPerSerializationAvg != null)
        {
            counters._pcMsecPerSerializationAvg = _pcMsecPerSerializationAvg.getSum();
            counters._pcMsecPerSerializationAvgBase = _pcMsecPerSerializationAvg.getTotalCount();
        }
        if (_pcMsecPerDeserializationAvg != null)
        {
            counters._pcMsecPerDeserializationAvg = _pcMsecPerDeserializationAvg.getSum();
            counters._pcMsecPerDeserializationAvgBase = _pcMsecPerDeserializationAvg.getTotalCount();
        }
        if (_pcMsecPerEncryptionAvg != null)
        {
            counters._pcMsecPerEncryptionAvg = _pcMsecPerEncryptionAvg.getSum();
            counters._pcMsecPerEncryptionAvgBase = _pcMsecPerEncryptionAvg.getTotalCount();
        }
        if (_pcMsecPerDecryptionAvg != null)
        {
            counters._pcMsecPerDecryptionAvg = _pcMsecPerDecryptionAvg.getSum();
            counters._pcMsecPerDecryptionAvgBase = _pcMsecPerDecryptionAvg.getTotalCount();
        }

        if (_pollRequestsSent != null)
            counters._pollRequestsSent = _pollRequestsSent.getValue();
        if (_pollLastUpdates != null)
            counters._pollLastUpdates = _pollLastUpdates.getValue();
        if (_pollLastRemoves != null)
            counters._pollLastRemoves = _pollLastRemoves.getValue();
        if (_pcMsecPerMessagePublishAvg != null)
        {
            counters._pcMsecPerMessagePublishAvg = _pcMsecPerMessagePublishAvg.getSum();
            counters._pcMsecPerMessagePublishBase = _pcMsecPerMessagePublishAvg.getTotalCount();
        }
        if (_pcMessagePublishPerSec != null)
            counters._pcMessagePublishPerSec = _pcMessagePublishPerSec.getValue();
        if (_pcMessageDeliverPerSec != null)
            counters._pcMessageDeliverPerSec = _pcMessageDeliverPerSec.getValue();
        if (_cacheServer != null)
            _cacheServer.PublishCustomClientCounters(_cacheID, counters);
    }
    public void UpdateCounters(ClientCustomCounters counters)
    {
        IncrementClientRequestsPerSecStats((long)counters._pcClientRequestsPerSec);
        IncrementClientResponsesPerSecStats((long)counters._pcClientResponsesPerSec);
        IncrementTotalClientRequestsPerSecStats((long)counters._pcTotalClientRequestsPerSec);
        IncrementTotalClientResponsesPerSecStats((long)counters._pcTotalClientResponsesPerSec);
        IncrementByGetPerSecStats((long)counters._pcGetPerSec);
        IncrementByAddPerSecStats((long)counters._pcAddPerSec);
        IncrementByUpdPerSecStats((long)counters._pcUpdPerSec);
        IncrementByDelPerSecStats((long)counters._pcDelPerSec);
        //IncrementAvgEventProcessingSample((long)counters._pcMsecPerEventAvg, (long)counters._pcMsecPerEventBase);
        IncrementEventsProcessedPerSec((long)counters._pcEventProcesedPerSec);
        IncrementEventsTriggeredPerSeconds((long)counters._pcEventTriggeredPerSec);
        IncrementCompressionPerSec((long)counters._pcCompressionPerSec);
        //IncrementMsecPerCompression((long)counters._pcMsecPerCompressionAvg);
        //IncrementMsecPerDecompression((long)counters._pcMsecPerDecompressionAvg, (long)counters._pcMsecPerDecompressionAvgBase);
        //IncrementAvgCompressedItemSize((long)counters._pcAvgCompressedItemSize, (long)counters._pcAvgCompressedItemSizeBase);
        //IncrementMsecPerSerialization((long)counters._pcMsecPerSerializationAvg, (long)counters._pcMsecPerSerializationAvgBase);
        //IncrementMsecPerDeserialization((long)counters._pcMsecPerDeserializationAvg, (long)counters._pcMsecPerDeserializationAvgBase);
        //IncrementAvgItemSize((long)counters._pcAvgItemSize, (long)counters._pcAvgItemSizeBase);
        //IncrementMsecPerGetSample((long)counters._pcMsecPerGetAvg, (long)counters._pcMsecPerGetBase);
        //IncrementMsecPerAddSample((long)counters._pcMsecPerAddAvg, (long)counters._pcMsecPerAddBase);
        //IncrementMsecPerDecryptionSample((long)counters._pcMsecPerDecryptionAvg, (long)counters._pcMsecPerDecryptionAvgBase);
        //IncrementMsecPerEncryptionSample((long)counters._pcMsecPerEncryptionAvg, (long)counters._pcMsecPerEncryptionAvgBase);
        //IncrementMsecPerUpdSample((long)counters._pcMsecPerUpdAvg, (long)counters._pcMsecPerUpdBase);
        //IncrementMsecPerDelSample((long)counters._pcMsecPerDelAvg, (long)counters._pcMsecPerDelBase);
        //IncrementMsecPerGetBulkSample((long)counters._pcMsecPerGetBulkAvg, (long)counters._pcMsecPerGetBulkBase);
        //IncrementMsecPerUpdBulkSample((long)counters._pcMsecPerUpdBulkAvg, (long)counters._pcMsecPerUpdBulkBase);
        //IncrementMsecPerDelBulkSample((long)counters._pcMsecPerDelBulkAvg, (long)counters._pcMsecPerDelBulkBase);
        //IncrementMsecPerAddBulkSample((long)counters._pcMsecPerAddBulkAvg, (long)counters._pcMsecPerAddBulkBase);
        _pcReqrQueueSize.setValue(counters._pcReqrQueueSize);
        _pollRequestsSent.setValue(counters._pollRequestsSent);
        _pollLastUpdates.setValue( counters._pollLastUpdates);
        _pollLastRemoves.setValue(counters._pollLastRemoves);
        IncrementMsecPerMessagePublish((long)counters._pcMessagePublishPerSec,1);
        IncrementMessageDeliverPerSec((long)counters._pcMessageDeliverPerSec);
         if(_pcMsecPerAddAvg!=null)
             _pcMsecPerAddAvg.incrementBy(counters._pcMsecPerAddAvg, counters._pcMsecPerAddBase);
         if(_pcMsecPerAddBulkAvg!=null)
             _pcMsecPerAddBulkAvg.incrementBy(counters._pcMsecPerAddBulkAvg, counters._pcMsecPerAddBulkBase);
        if(_pcMsecPerGetBulkAvg!=null)
            _pcMsecPerGetBulkAvg.incrementBy(counters._pcMsecPerGetBulkAvg, counters._pcMsecPerGetBulkBase);
        if(_pcMsecPerUpdBulkAvg!=null)
            _pcMsecPerUpdBulkAvg.incrementBy(counters._pcMsecPerUpdBulkAvg, counters._pcMsecPerUpdBulkBase);
        if(_pcMsecPerUpdBulkAvg!=null)
            _pcMsecPerUpdBulkAvg.incrementBy(counters._pcMsecPerUpdBulkAvg, counters._pcMsecPerUpdBulkBase);
        if(_pcMsecPerDelBulkAvg!=null)
            _pcMsecPerDelBulkAvg.incrementBy(counters._pcMsecPerDelBulkAvg, counters._pcMsecPerDelBulkBase);
        if(_pcMsecPerGetAvg!=null)
            _pcMsecPerGetAvg.incrementBy(counters._pcMsecPerGetAvg, counters._pcMsecPerGetBase);
        if(_pcMsecPerUpdAvg!=null)
            _pcMsecPerUpdAvg.incrementBy(counters._pcMsecPerUpdAvg, counters._pcMsecPerUpdBase);
        if(_pcMsecPerDelAvg!=null)
            _pcMsecPerDelAvg.incrementBy(counters._pcMsecPerDelAvg, counters._pcMsecPerDelBase);
        if(_pcAvgItemSize!=null)
            _pcAvgItemSize.incrementBy(counters._pcAvgItemSize, counters._pcAvgItemSizeBase);
        if(_pcMsecPerEventAvg!=null)
            _pcMsecPerEventAvg.incrementBy(counters._pcMsecPerEventAvg, counters._pcMsecPerEventBase);
        if(_pcMsecPerCompressionAvg!=null)
            _pcMsecPerCompressionAvg.incrementBy(counters._pcMsecPerCompressionAvg, counters._pcMsecPerCompressionAvgBase);
        if(_pcMsecPerCompressionAvg!=null)
            _pcMsecPerCompressionAvg.incrementBy(counters._pcMsecPerCompressionAvg, counters._pcMsecPerCompressionAvgBase);
        if(_pcMsecPerDecompressionAvg!=null)
            _pcMsecPerDecompressionAvg.incrementBy(counters._pcMsecPerDecompressionAvg, counters._pcMsecPerDecompressionAvgBase);
        if(_pcMsecPerSerializationAvg!=null)
            _pcMsecPerSerializationAvg.incrementBy(counters._pcMsecPerSerializationAvg, counters._pcMsecPerSerializationAvgBase);
        if(_pcMsecPerDeserializationAvg!=null)
            _pcMsecPerDeserializationAvg.incrementBy(counters._pcMsecPerDeserializationAvg, counters._pcMsecPerDeserializationAvgBase);
        if(_pcMsecPerEncryptionAvg!=null)
            _pcMsecPerEncryptionAvg.incrementBy(counters._pcMsecPerEncryptionAvg, counters._pcMsecPerEncryptionAvgBase);
        if(_pcMsecPerDecryptionAvg!=null)
            _pcMsecPerDecryptionAvg.incrementBy(counters._pcMsecPerDecryptionAvg, counters._pcMsecPerDecryptionAvgBase);
        if(_pcMsecPerMessagePublishAvg!=null)
            _pcMsecPerMessagePublishAvg.incrementBy(counters._pcMsecPerMessagePublishAvg, counters._pcMsecPerMessagePublishBase);
    }

    //endregion
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy