geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [14/21] incubator-geode git commit: GEODE-1781: repackage internal statistics classes and refactor statistics tests
Date Tue, 16 Aug 2016 01:14:27 GMT
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7334c131/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/CacheClientNotifierStats.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/CacheClientNotifierStats.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/CacheClientNotifierStats.java
index afc4235..36c22b6 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/CacheClientNotifierStats.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/CacheClientNotifierStats.java
@@ -21,8 +21,7 @@ import com.gemstone.gemfire.Statistics;
 import com.gemstone.gemfire.StatisticsFactory;
 import com.gemstone.gemfire.StatisticsType;
 import com.gemstone.gemfire.StatisticsTypeFactory;
-import com.gemstone.gemfire.internal.NanoTimer;
-import com.gemstone.gemfire.internal.StatisticsTypeFactoryImpl;
+import com.gemstone.gemfire.internal.statistics.StatisticsTypeFactoryImpl;
 import com.gemstone.gemfire.distributed.internal.DistributionStats;
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7334c131/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/CacheClientProxyStats.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/CacheClientProxyStats.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/CacheClientProxyStats.java
index cf69d90..7812a3a 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/CacheClientProxyStats.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/CacheClientProxyStats.java
@@ -22,7 +22,7 @@ import com.gemstone.gemfire.Statistics;
 import com.gemstone.gemfire.StatisticsFactory;
 import com.gemstone.gemfire.StatisticsType;
 import com.gemstone.gemfire.StatisticsTypeFactory;
-import com.gemstone.gemfire.internal.StatisticsTypeFactoryImpl;
+import com.gemstone.gemfire.internal.statistics.StatisticsTypeFactoryImpl;
 import com.gemstone.gemfire.distributed.internal.DistributionStats;
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7334c131/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/CacheClientUpdater.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/CacheClientUpdater.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/CacheClientUpdater.java
index 391c3e6..26efd4d 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/CacheClientUpdater.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/CacheClientUpdater.java
@@ -45,6 +45,7 @@ import com.gemstone.gemfire.internal.logging.log4j.LocalizedMessage;
 import com.gemstone.gemfire.internal.logging.log4j.LogMarker;
 import com.gemstone.gemfire.internal.offheap.annotations.Released;
 import com.gemstone.gemfire.internal.sequencelog.EntryLogger;
+import com.gemstone.gemfire.internal.statistics.StatisticsTypeFactoryImpl;
 import com.gemstone.gemfire.security.AuthenticationFailedException;
 import com.gemstone.gemfire.security.AuthenticationRequiredException;
 import com.gemstone.gemfire.security.GemFireSecurityException;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7334c131/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/CacheServerStats.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/CacheServerStats.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/CacheServerStats.java
index 626e075..360a87c 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/CacheServerStats.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/CacheServerStats.java
@@ -14,14 +14,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-/**
- * Bridge Server statistic definitions
- */
 package com.gemstone.gemfire.internal.cache.tier.sockets;
 
-import java.net.InetAddress;
-
 import com.gemstone.gemfire.StatisticDescriptor;
 import com.gemstone.gemfire.Statistics;
 import com.gemstone.gemfire.StatisticsFactory;
@@ -29,10 +23,11 @@ import com.gemstone.gemfire.StatisticsType;
 import com.gemstone.gemfire.cache.server.ServerLoad;
 import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
 import com.gemstone.gemfire.distributed.internal.PoolStatHelper;
-import com.gemstone.gemfire.internal.DummyStatisticsFactory;
 import com.gemstone.gemfire.internal.SocketCreator;
-import com.gemstone.gemfire.internal.util.ArrayUtils;
 
+/**
+ * Bridge Server statistic definitions
+ */
 public class CacheServerStats implements MessageStats {
   
   private static final String typeName = "CacheServerStats";

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7334c131/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/wan/GatewaySenderStats.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/wan/GatewaySenderStats.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/wan/GatewaySenderStats.java
index 15a6dee..1044456 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/wan/GatewaySenderStats.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/wan/GatewaySenderStats.java
@@ -22,7 +22,7 @@ import com.gemstone.gemfire.StatisticsFactory;
 import com.gemstone.gemfire.StatisticsType;
 import com.gemstone.gemfire.StatisticsTypeFactory;
 import com.gemstone.gemfire.distributed.internal.DistributionStats;
-import com.gemstone.gemfire.internal.StatisticsTypeFactoryImpl;
+import com.gemstone.gemfire.internal.statistics.StatisticsTypeFactoryImpl;
 import com.gemstone.gemfire.internal.cache.CachePerfStats;
 
 public class GatewaySenderStats {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7334c131/geode-core/src/main/java/com/gemstone/gemfire/internal/concurrent/Atomics.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/concurrent/Atomics.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/concurrent/Atomics.java
index 8940a69..9475059 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/concurrent/Atomics.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/concurrent/Atomics.java
@@ -20,9 +20,9 @@ package com.gemstone.gemfire.internal.concurrent;
 import com.gemstone.gemfire.Statistics;
 import com.gemstone.gemfire.StatisticsType;
 import com.gemstone.gemfire.distributed.internal.DistributionConfig;
-import com.gemstone.gemfire.internal.LocalStatisticsImpl;
-import com.gemstone.gemfire.internal.StatisticsManager;
-import com.gemstone.gemfire.internal.StatisticsTypeImpl;
+import com.gemstone.gemfire.internal.statistics.LocalStatisticsImpl;
+import com.gemstone.gemfire.internal.statistics.StatisticsManager;
+import com.gemstone.gemfire.internal.statistics.StatisticsTypeImpl;
 import com.gemstone.gemfire.internal.stats50.Atomic50StatisticsImpl;
 
 import java.util.concurrent.atomic.AtomicLong;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7334c131/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapStorage.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapStorage.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapStorage.java
index bc7fb6a..449e05a 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapStorage.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapStorage.java
@@ -24,7 +24,7 @@ import com.gemstone.gemfire.distributed.internal.DistributionStats;
 import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
 import com.gemstone.gemfire.distributed.internal.InternalLocator;
 import com.gemstone.gemfire.internal.ClassPathLoader;
-import com.gemstone.gemfire.internal.StatisticsTypeFactoryImpl;
+import com.gemstone.gemfire.internal.statistics.StatisticsTypeFactoryImpl;
 import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
 
 import java.lang.reflect.Method;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7334c131/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/AbstractStatisticsFactory.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/AbstractStatisticsFactory.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/AbstractStatisticsFactory.java
new file mode 100755
index 0000000..fb07d45
--- /dev/null
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/AbstractStatisticsFactory.java
@@ -0,0 +1,327 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.statistics;
+
+import com.gemstone.gemfire.StatisticDescriptor;
+import com.gemstone.gemfire.Statistics;
+import com.gemstone.gemfire.StatisticsFactory;
+import com.gemstone.gemfire.StatisticsType;
+import com.gemstone.gemfire.StatisticsTypeFactory;
+import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+/**
+ * An abstract standalone implementation of {@link StatisticsFactory}.
+ * It can be used in contexts that do not have the GemFire product
+ * or in vm's that do not have a distributed system nor a gemfire connection.
+ *
+ * @since GemFire 7.0
+ */
+public abstract class AbstractStatisticsFactory 
+    implements StatisticsFactory, StatisticsManager {
+
+  private final long id;
+  private final String name;
+  private final CopyOnWriteArrayList<Statistics> statsList;
+  private int statsListModCount = 0;
+  private long statsListUniqueId = 1;
+  private final Object statsListUniqueIdLock;
+  private final StatisticsTypeFactory tf;
+  private final long startTime;
+
+  public AbstractStatisticsFactory(long id, String name, long startTime) {
+    this.id = id;
+    this.name = name;
+    this.startTime = startTime;
+    
+    this.statsList = new CopyOnWriteArrayList<Statistics>();
+    this.statsListUniqueIdLock = new Object();
+    this.tf = StatisticsTypeFactoryImpl.singleton();
+  }
+
+  public void close() {
+  }
+  
+  @Override
+  public final String getName() {
+    return this.name;
+  }
+  
+  @Override
+  public final long getId() {
+    return this.id;
+  }
+  
+  @Override
+  public final long getStartTime() {
+    return this.startTime;
+  }
+  
+  @Override
+  public final int getStatListModCount() {
+    return this.statsListModCount;
+  }
+  
+  @Override
+  public final List<Statistics> getStatsList() {
+    return this.statsList;
+  }
+
+  @Override
+  public final int getStatisticsCount() {
+    int result = 0;
+    List<Statistics> statsList = this.statsList;
+    if (statsList != null) {
+      result = statsList.size();
+    }
+    return result;
+  }
+  
+  @Override
+  public final Statistics findStatistics(long id) {
+    List<Statistics> statsList = this.statsList;
+    synchronized (statsList) {
+      for (Statistics s : statsList) {
+        if (s.getUniqueId() == id) {
+          return s;
+        }
+      }
+    }
+    throw new RuntimeException(LocalizedStrings.PureStatSampler_COULD_NOT_FIND_STATISTICS_INSTANCE.toLocalizedString());
+  }
+  
+  @Override
+  public final boolean statisticsExists(long id) {
+    List<Statistics> statsList = this.statsList;
+    for (Statistics s : statsList) {
+      if (s.getUniqueId() == id) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  @Override
+  public final Statistics[] getStatistics() {
+    List<Statistics> statsList = this.statsList;
+    return (Statistics[])statsList.toArray(new Statistics[statsList.size()]);
+  }
+  
+  // StatisticsFactory methods
+  
+  @Override
+  public final Statistics createStatistics(StatisticsType type) {
+    return createOsStatistics(type, null, 0, 0);
+  }
+  
+  @Override
+  public final Statistics createStatistics(StatisticsType type, String textId) {
+    return createOsStatistics(type, textId, 0, 0);
+  }
+  
+  @Override
+  public final Statistics createStatistics(StatisticsType type, String textId, long numericId) {
+    return createOsStatistics(type, textId, 0, 0);
+  }
+  
+  protected Statistics createOsStatistics(StatisticsType type, String textId, long numericId, int osStatFlags) {
+    long myUniqueId;
+    synchronized (statsListUniqueIdLock) {
+      myUniqueId = statsListUniqueId++; // fix for bug 30597
+    }
+    Statistics result = new LocalStatisticsImpl(type, textId, numericId, myUniqueId, false, osStatFlags, this);
+    synchronized (statsList) {
+      statsList.add(result);
+      statsListModCount++;
+    }
+    return result;
+  }
+
+  @Override
+  public final Statistics[] findStatisticsByType(StatisticsType type) {
+    List<Statistics> hits = new ArrayList<Statistics>();
+    Iterator<Statistics> it = statsList.iterator();
+    while (it.hasNext()) {
+      Statistics s = (Statistics)it.next();
+      if (type == s.getType()) {
+        hits.add(s);
+      }
+    }
+    Statistics[] result = new Statistics[hits.size()];
+    return (Statistics[])hits.toArray(result);
+  }
+  
+  @Override
+  public final Statistics[] findStatisticsByTextId(String textId) {
+    List<Statistics> hits = new ArrayList<Statistics>();
+    Iterator<Statistics> it = statsList.iterator();
+    while (it.hasNext()) {
+      Statistics s = (Statistics)it.next();
+      if (s.getTextId().equals(textId)) {
+        hits.add(s);
+      }
+    }
+    Statistics[] result = new Statistics[hits.size()];
+    return (Statistics[])hits.toArray(result);
+  }
+  
+  @Override
+  public final Statistics[] findStatisticsByNumericId(long numericId) {
+    List<Statistics> hits = new ArrayList<Statistics>();
+    Iterator<Statistics> it = statsList.iterator();
+    while (it.hasNext()) {
+      Statistics s = (Statistics)it.next();
+      if (numericId == s.getNumericId()) {
+        hits.add(s);
+      }
+    }
+    Statistics[] result = new Statistics[hits.size()];
+    return (Statistics[])hits.toArray(result);
+  }
+  
+  public final Statistics findStatisticsByUniqueId(long uniqueId) {
+    Iterator<Statistics> it = statsList.iterator();
+    while (it.hasNext()) {
+      Statistics s = (Statistics)it.next();
+      if (uniqueId == s.getUniqueId()) {
+        return s;
+      }
+    }
+    return null;
+  }
+
+  /** for internal use only. Its called by {@link LocalStatisticsImpl#close}. */
+  @Override
+  public final void destroyStatistics(Statistics stats) {
+    synchronized (statsList) {
+      if (statsList.remove(stats)) {
+        statsListModCount++;
+      }
+    }
+  }
+
+  @Override
+  public final Statistics createAtomicStatistics(StatisticsType type) {
+    return createAtomicStatistics(type, null, 0);
+  }
+  
+  @Override
+  public final Statistics createAtomicStatistics(StatisticsType type, String textId) {
+    return createAtomicStatistics(type, textId, 0);
+  }
+  
+  @Override
+  public Statistics createAtomicStatistics(StatisticsType type, String textId, long numericId) {
+    long myUniqueId;
+    synchronized (statsListUniqueIdLock) {
+      myUniqueId = statsListUniqueId++; // fix for bug 30597
+    }
+    Statistics result = StatisticsImpl.createAtomicNoOS(type, textId, numericId, myUniqueId, this);
+    synchronized (statsList) {
+      statsList.add(result);
+      statsListModCount++;
+    }
+    return result;
+  }
+
+  // StatisticsTypeFactory methods
+  
+  /**
+   * Creates or finds a StatisticType for the given shared class.
+   */
+  @Override
+  public final StatisticsType createType(String name, String description, StatisticDescriptor[] stats) {
+    return tf.createType(name, description, stats);
+  }
+  
+  @Override
+  public final StatisticsType findType(String name) {
+    return tf.findType(name);
+  }
+  
+  @Override
+  public final StatisticsType[] createTypesFromXml(Reader reader)
+    throws IOException {
+    return tf.createTypesFromXml(reader);
+  }
+
+  @Override
+  public final StatisticDescriptor createIntCounter(String name, String description, String units) {
+    return tf.createIntCounter(name, description, units);
+  }
+  
+  @Override
+  public final StatisticDescriptor createLongCounter(String name, String description, String units) {
+    return tf.createLongCounter(name, description, units);
+  }
+  
+  @Override
+  public final StatisticDescriptor createDoubleCounter(String name, String description, String units) {
+    return tf.createDoubleCounter(name, description, units);
+  }
+  
+  @Override
+  public final StatisticDescriptor createIntGauge(String name, String description, String units) {
+    return tf.createIntGauge(name, description, units);
+  }
+  
+  @Override
+  public final StatisticDescriptor createLongGauge(String name, String description, String units) {
+    return tf.createLongGauge(name, description, units);
+  }
+  
+  @Override
+  public final StatisticDescriptor createDoubleGauge(String name, String description, String units) {
+    return tf.createDoubleGauge(name, description, units);
+  }
+  
+  @Override
+  public final StatisticDescriptor createIntCounter(String name, String description, String units, boolean largerBetter) {
+    return tf.createIntCounter(name, description, units, largerBetter);
+  }
+  
+  @Override
+  public final StatisticDescriptor createLongCounter(String name, String description, String units, boolean largerBetter) {
+    return tf.createLongCounter(name, description, units, largerBetter);
+  }
+  
+  @Override
+  public final StatisticDescriptor createDoubleCounter(String name, String description, String units, boolean largerBetter) {
+    return tf.createDoubleCounter(name, description, units, largerBetter);
+  }
+  
+  @Override
+  public final StatisticDescriptor createIntGauge(String name, String description, String units, boolean largerBetter) {
+    return tf.createIntGauge(name, description, units, largerBetter);
+  }
+  
+  @Override
+  public final StatisticDescriptor createLongGauge(String name, String description, String units, boolean largerBetter) {
+    return tf.createLongGauge(name, description, units, largerBetter);
+  }
+  
+  @Override
+  public final StatisticDescriptor createDoubleGauge(String name, String description, String units, boolean largerBetter) {
+    return tf.createDoubleGauge(name, description, units, largerBetter);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7334c131/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/ArchiveSplitter.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/ArchiveSplitter.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/ArchiveSplitter.java
new file mode 100644
index 0000000..14aadf1
--- /dev/null
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/ArchiveSplitter.java
@@ -0,0 +1,522 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.statistics;
+
+import com.gemstone.gemfire.*;
+import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
+
+import java.io.*;
+//import java.text.*;
+//import java.util.*;
+import java.util.zip.*;
+
+/**
+ * ArchiveSplitter provides APIs to read statistic snapshots from an archive
+ * file.
+ */
+public class ArchiveSplitter implements StatArchiveFormat {
+  private final File archiveName;
+  private InputStream is;
+  private MyFilterInputStream myIs;
+  private DataInputStream dataIn;
+  private DataOutputStream dataOut;
+  private OutputStream output;
+  private final static int BUFFER_SIZE = 1024*1024;
+  private long splitDuration; // in millis
+  private byte[][] resourceTypes = new byte[256][];
+  private byte[][] resourceInstanceTypeCodes = new byte[256][];
+  private byte[][] resourceInstanceTokens = new byte[256][];
+  private long[][] resourceInstanceBits = new long[256][];
+  private static final long DEFAULT_SPLIT_DURATION = 24*60*60*1000; // one day
+  private long currentDuration = 0; // in millis
+  private int splitCount = 0;
+  private byte[][] globalTokens = new byte[256][];
+  private int globalTokenCount = 0;
+
+  // header info
+  private byte archiveVersion;
+  private long startTimeStamp;
+  private long systemId;
+  private long systemStartTimeStamp;
+  private int timeZoneOffset;
+  private String timeZoneName;
+  private String systemDirectory;
+  private String productVersion;
+  private String os;
+  private String machine;
+  
+
+  public ArchiveSplitter(File archiveName) throws IOException {
+    this(archiveName, DEFAULT_SPLIT_DURATION);
+  }
+  public ArchiveSplitter(File archiveName, long splitDuration) throws IOException {
+    this.archiveName = archiveName;
+    this.splitDuration = splitDuration;
+    this.is = new FileInputStream(archiveName);
+    boolean compressed = archiveName.getPath().endsWith(".gz");
+    if (compressed) {
+      this.myIs = new MyFilterInputStream(new BufferedInputStream(new GZIPInputStream(this.is, BUFFER_SIZE), BUFFER_SIZE));
+    } else {
+      this.myIs = new MyFilterInputStream(new BufferedInputStream(this.is, BUFFER_SIZE));
+    }
+    this.dataIn = new DataInputStream(this.myIs);
+  }
+  private void readHeaderToken() throws IOException {
+    byte archiveVersion = dataIn.readByte();
+    if (archiveVersion <= 1) {
+      throw new GemFireIOException(LocalizedStrings.ArchiveSplitter_ARCHIVE_VERSION_0_IS_NO_LONGER_SUPPORTED.toLocalizedString(new Byte(archiveVersion)), null);
+    }
+    if (archiveVersion > ARCHIVE_VERSION) {
+      throw new GemFireIOException(LocalizedStrings.ArchiveSplitter_UNSUPPORTED_ARCHIVE_VERSION_0_THE_SUPPORTED_VERSION_IS_1.toLocalizedString(new Object[] {new Byte(archiveVersion), new Byte(ARCHIVE_VERSION)}), null);
+    }
+
+    this.archiveVersion = archiveVersion;
+    this.startTimeStamp = dataIn.readLong();
+    this.systemId = dataIn.readLong();
+    this.systemStartTimeStamp = dataIn.readLong();
+    this.timeZoneOffset = dataIn.readInt();
+    this.timeZoneName = dataIn.readUTF();
+    this.systemDirectory = dataIn.readUTF();
+    this.productVersion = dataIn.readUTF();
+    this.os = dataIn.readUTF();
+    this.machine = dataIn.readUTF();
+  }
+  private void skipBytes(int count) throws IOException {
+    int skipped = dataIn.skipBytes(count);
+    while (skipped != count) {
+      count -= skipped;
+      skipped = dataIn.skipBytes(count);
+    }
+  }
+  private void skipBoolean() throws IOException {
+    //dataIn.readBoolean();
+    skipBytes(1);
+  }
+//  private void skipByte() throws IOException {
+//    //dataIn.readByte();
+//    skipBytes(1);
+//  }
+//  private void skipUByte() throws IOException {
+//    //dataIn.readUnsignedByte();
+//    skipBytes(1);
+//  }
+//  private void skipShort() throws IOException {
+//    //dataIn.readShort();
+//    skipBytes(2);
+//  }
+//  private void skipUShort() throws IOException {
+//    //dataIn.readUnsignedShort();
+//    skipBytes(2);
+//  }
+//  private void skipInt() throws IOException {
+//    //dataIn.readInt();
+//    skipBytes(4);
+//  }
+  private void skipLong() throws IOException {
+    //dataIn.readLong();
+    skipBytes(8);
+  }
+  private void skipUTF() throws IOException {
+    //dataIn.readUTF();
+    skipBytes(dataIn.readUnsignedShort());
+  }
+  private void addGlobalToken(byte[] token) {
+    if (globalTokenCount >= globalTokens.length) {
+      byte[][] tmp = new byte[globalTokenCount+128][];
+      System.arraycopy(globalTokens, 0, tmp, 0, globalTokens.length);
+      globalTokens = tmp;
+    }
+    globalTokens[globalTokenCount] = token;
+    globalTokenCount += 1;
+  }
+  private void readResourceTypeToken() throws IOException {
+    int resourceTypeId = dataIn.readInt();
+    skipUTF(); //String resourceTypeName = dataIn.readUTF();
+    skipUTF(); //String resourceTypeDesc = dataIn.readUTF();
+    int statCount = dataIn.readUnsignedShort();
+    byte[] typeCodes = new byte[statCount];
+
+    for (int i=0; i < statCount; i++) {
+      skipUTF(); //String statName = dataIn.readUTF();
+      typeCodes[i] = dataIn.readByte();
+      skipBoolean(); //boolean isCounter = dataIn.readBoolean();
+      if (this.archiveVersion >= 4) {
+        skipBoolean(); //boolean largerBetter = dataIn.readBoolean();
+      }
+      skipUTF(); //String units = dataIn.readUTF();
+      skipUTF(); //String desc = dataIn.readUTF();
+    }
+    if (resourceTypeId >= resourceTypes.length) {
+      byte[][] tmp = new byte[resourceTypeId+128][];
+      System.arraycopy(resourceTypes, 0, tmp, 0, resourceTypes.length);
+      resourceTypes = tmp;
+    }
+    resourceTypes[resourceTypeId] = typeCodes;
+
+    addGlobalToken(this.myIs.getBytes());
+  }
+  private void readResourceInstanceCreateToken(boolean initialize) throws IOException {
+    int resourceInstId = dataIn.readInt();
+    skipUTF(); //String name = dataIn.readUTF();
+    skipLong(); //long id = dataIn.readLong();
+    int resourceTypeId = dataIn.readInt();
+    
+    if (resourceInstId >= resourceInstanceBits.length) {
+      long[][] tmpBits = new long[resourceInstId+128][];
+      System.arraycopy(resourceInstanceBits, 0,
+                       tmpBits, 0, resourceInstanceBits.length);
+      resourceInstanceBits = tmpBits;
+
+      byte[][] tmpTypeCodes = new byte[resourceInstId+128][];
+      System.arraycopy(resourceInstanceTypeCodes, 0,
+                       tmpTypeCodes, 0, resourceInstanceTypeCodes.length);
+      resourceInstanceTypeCodes = tmpTypeCodes;
+
+      byte[][] tmpTokens = new byte[resourceInstId+128][];
+      System.arraycopy(resourceInstanceTokens, 0,
+                       tmpTokens, 0, resourceInstanceTokens.length);
+      resourceInstanceTokens = tmpTokens;
+    }
+    byte[] instTypeCodes = resourceTypes[resourceTypeId];
+    resourceInstanceTypeCodes[resourceInstId] = instTypeCodes;
+    resourceInstanceTokens[resourceInstId] = this.myIs.getBytes();
+    resourceInstanceTokens[resourceInstId][0] = RESOURCE_INSTANCE_INITIALIZE_TOKEN;
+    long[] instBits = new long[instTypeCodes.length];
+    resourceInstanceBits[resourceInstId] = instBits;
+    if (initialize) {
+      for (int i=0; i < instBits.length; i++) {
+        switch (instTypeCodes[i]) {
+        case BOOLEAN_CODE:
+        case BYTE_CODE:
+        case CHAR_CODE:
+          instBits[i] = dataIn.readByte();
+          break;
+        case WCHAR_CODE:
+          instBits[i] = dataIn.readUnsignedShort();
+          break;
+        case SHORT_CODE:
+          instBits[i] = dataIn.readShort();
+          break;
+        case INT_CODE:
+        case FLOAT_CODE:
+        case LONG_CODE:
+        case DOUBLE_CODE:
+          instBits[i] = readCompactValue();
+          break;
+        default:
+          throw new IOException(LocalizedStrings.ArchiveSplitter_UNEXPECTED_TYPECODE_VALUE_0.toLocalizedString(new Byte(instTypeCodes[i])));
+        }
+      }
+    }
+  }
+  private void readResourceInstanceDeleteToken() throws IOException {
+    int id = dataIn.readInt();
+    resourceInstanceTypeCodes[id] = null;
+    resourceInstanceBits[id] = null;
+    resourceInstanceTokens[id] = null;
+  }
+  private int readResourceInstId() throws IOException {
+    int token = dataIn.readUnsignedByte();
+    if (token <= MAX_BYTE_RESOURCE_INST_ID) {
+      return token;
+    } else if (token == ILLEGAL_RESOURCE_INST_ID_TOKEN) {
+      return ILLEGAL_RESOURCE_INST_ID;
+    } else if (token == SHORT_RESOURCE_INST_ID_TOKEN) {
+      return dataIn.readUnsignedShort();
+    } else { /* token == INT_RESOURCE_INST_ID_TOKEN */
+      return dataIn.readInt();
+    }
+  }
+  private void readTimeDelta() throws IOException {
+    int millisSinceLastSample = dataIn.readUnsignedShort();
+    if (millisSinceLastSample == INT_TIMESTAMP_TOKEN) {
+      millisSinceLastSample = dataIn.readInt();
+    }
+    this.currentDuration += millisSinceLastSample;
+    this.startTimeStamp += millisSinceLastSample;
+  }
+  private long readCompactValue() throws IOException {
+    long v = dataIn.readByte();
+    if (v < MIN_1BYTE_COMPACT_VALUE) {
+      if (v == COMPACT_VALUE_2_TOKEN) {
+        v = dataIn.readShort();
+      } else {
+        int bytesToRead = ((byte)v - COMPACT_VALUE_2_TOKEN) + 2;
+        v = dataIn.readByte(); // note the first byte will be a signed byte.
+        bytesToRead--;
+        while (bytesToRead > 0) {
+          v <<= 8;
+          v |= dataIn.readUnsignedByte();
+          bytesToRead--;
+        }
+      }
+    }
+    return v;
+  }
+  private void readSampleToken() throws IOException {
+    readTimeDelta();
+    int resourceInstId = readResourceInstId();
+    while (resourceInstId != ILLEGAL_RESOURCE_INST_ID) {
+      byte[] typeCodes = resourceInstanceTypeCodes[resourceInstId];
+      long[] bits =      resourceInstanceBits[resourceInstId];
+      int statOffset = dataIn.readUnsignedByte();
+      while (statOffset != ILLEGAL_STAT_OFFSET) {
+        long statDeltaBits;
+        switch (typeCodes[statOffset]) {
+        case BOOLEAN_CODE:
+        case BYTE_CODE:
+        case CHAR_CODE:
+          statDeltaBits = dataIn.readByte();
+          break;
+        case WCHAR_CODE:
+          statDeltaBits = dataIn.readUnsignedShort();
+          break;
+        case SHORT_CODE:
+          statDeltaBits = dataIn.readShort();
+          break;
+        case INT_CODE:
+        case FLOAT_CODE:
+        case LONG_CODE:
+        case DOUBLE_CODE:
+          statDeltaBits = readCompactValue();
+          break;
+        default:
+          throw new IOException(LocalizedStrings.ArchiveSplitter_UNEXPECTED_TYPECODE_VALUE_0.toLocalizedString(new Byte(typeCodes[statOffset])));
+        }
+        bits[statOffset] += statDeltaBits;
+        statOffset = dataIn.readUnsignedByte();
+      }
+      resourceInstId = readResourceInstId();
+    }
+  }
+  /**
+     * Returns true if token read, false if eof.
+     */
+  private boolean readToken() throws IOException {
+    byte token;
+    try {
+      token = this.dataIn.readByte();
+      switch (token) {
+      case HEADER_TOKEN:
+        readHeaderToken();
+        this.myIs.putBytes(this.dataOut);
+        break;
+      case RESOURCE_TYPE_TOKEN:
+        readResourceTypeToken();
+        this.myIs.putBytes(this.dataOut);
+        break;
+      case RESOURCE_INSTANCE_CREATE_TOKEN:
+      case RESOURCE_INSTANCE_INITIALIZE_TOKEN:
+        readResourceInstanceCreateToken(token == RESOURCE_INSTANCE_INITIALIZE_TOKEN);
+        this.myIs.putBytes(this.dataOut);
+        break;
+      case RESOURCE_INSTANCE_DELETE_TOKEN:
+        readResourceInstanceDeleteToken();
+        this.myIs.putBytes(this.dataOut);
+        break;
+      case SAMPLE_TOKEN:
+        readSampleToken();
+        this.myIs.putBytes(this.dataOut);
+        break;
+      default:
+        throw new IOException(LocalizedStrings.ArchiveSplitter_UNEXPECTED_TOKEN_BYTE_VALUE_0.toLocalizedString(new Byte(token)));
+      }
+      return true;
+    } catch (EOFException ignore) {
+      return false;
+    }
+  }
+
+  private File getOutputName() {
+    String inName = archiveName.getPath();
+    StringBuffer buf = new StringBuffer(inName.length()+4);
+    int idx = inName.lastIndexOf('.');
+    if (idx == -1) {
+      buf.append(inName);
+    } else {
+      buf.append(inName.substring(0, idx));
+    }
+    buf.append('-')
+      .append(this.splitCount);
+    if (idx != -1) {
+      buf.append(inName.substring(idx));
+    }
+    return new File(buf.toString());
+  }
+
+  private void startSplit() throws IOException {
+    this.currentDuration = 0;
+    this.splitCount++;
+    if (archiveName.getPath().endsWith(".gz")) {
+      this.output = new GZIPOutputStream(new FileOutputStream(getOutputName()), BUFFER_SIZE);
+    } else {
+      this.output = new BufferedOutputStream(new FileOutputStream(getOutputName()), BUFFER_SIZE);
+    }
+    this.dataOut = new DataOutputStream(this.output);
+
+
+    if (this.splitCount > 1) {
+      this.dataOut.writeByte(HEADER_TOKEN);
+      this.dataOut.writeByte(ARCHIVE_VERSION);
+      this.dataOut.writeLong(this.startTimeStamp);
+      this.dataOut.writeLong(this.systemId);
+      this.dataOut.writeLong(this.systemStartTimeStamp);
+      this.dataOut.writeInt(this.timeZoneOffset);
+      this.dataOut.writeUTF(this.timeZoneName);
+      this.dataOut.writeUTF(this.systemDirectory);
+      this.dataOut.writeUTF(this.productVersion);
+      this.dataOut.writeUTF(this.os);
+      this.dataOut.writeUTF(this.machine);
+    }
+    
+    for (int i=0; i < globalTokenCount; i++) {
+      this.dataOut.write(globalTokens[i]);
+    }
+    for (int i=0; i < resourceInstanceTokens.length; i++) {
+      if (resourceInstanceTokens[i] != null) {
+        this.dataOut.write(resourceInstanceTokens[i]);
+        byte[] instTypeCodes = resourceInstanceTypeCodes[i];
+        long[] instBits = resourceInstanceBits[i];
+        for (int j=0; j < instBits.length; j++) {
+          StatArchiveWriter.writeStatValue(instTypeCodes[j], instBits[j], this.dataOut);
+        }
+      }
+    }
+  }
+
+  private void endSplit() {
+    try {
+      this.dataOut.flush();
+    } catch (IOException ex) {
+    }
+    try {
+      this.output.close();
+    } catch (IOException ex) {
+      System.err.println("[warning] could not close " + getOutputName());
+    }
+  }
+  
+  public void split() throws IOException {
+    boolean done = false;
+    do {
+      done = true;
+      startSplit();
+      while (readToken()) {
+        if (this.currentDuration >= this.splitDuration) {
+          done = false;
+          break;
+        }
+      }
+      endSplit();
+    } while (!done);
+  }
+
+  private static class MyFilterInputStream extends FilterInputStream {
+    private byte[] readBytes = new byte[32000];
+    private int idx = 0;
+    public MyFilterInputStream(InputStream in) {
+      super(in);
+    }
+
+    /**
+     * Returns all the bytes, read or skipped, since the last reset.
+     */
+    public byte[] getBytes() {
+      byte[] result = new byte[idx];
+      System.arraycopy(readBytes, 0, result, 0, result.length);
+      return result;
+    }
+
+    /**
+     * Writes all the bytes, read or skipped, since the last reset
+     * to the specified output stream.
+     * Does a mark and reset after the write.
+     */
+    public void putBytes(DataOutputStream dataOut) throws IOException {
+      dataOut.write(readBytes, 0, idx);
+      idx = 0;
+    }
+    
+    @Override
+    public void close() throws IOException {
+      readBytes = null;
+      super.close();
+    }
+
+    @Override
+    public void reset() throws IOException {
+      idx = 0;
+      super.reset();
+    }
+    
+    @Override
+    public long skip(long n) throws IOException {
+      makeRoom((int)n);
+      int result = super.read(readBytes, idx, (int)n);
+      if (result == -1) {
+        return 0;
+      } else {
+        idx += result;
+        return result;
+      }
+    }
+    
+    private void makeRoom(int n) {
+      if (idx+n > readBytes.length) {
+        byte[] tmp = new byte[readBytes.length + n + 1024];
+        System.arraycopy(readBytes, 0, tmp, 0, readBytes.length);
+        readBytes = tmp;
+      }
+    }
+
+    @Override
+    public int read() throws IOException {
+      int result = super.read();
+      if (result != -1) {
+        makeRoom(1);
+        readBytes[idx] = (byte)result;
+        idx += 1;
+      }
+      return result;
+    }
+
+    @Override
+    public int read(byte[] b) throws IOException {
+      return read(b, 0, b.length);
+    }
+    @Override
+    public int read(byte[] b, int off, int len) throws IOException {
+      int result = super.read(b, off, len);
+      if (result != -1) {
+        makeRoom(result);
+        System.arraycopy(b, off, readBytes, idx, result);
+        idx += result;
+      }
+      return result;
+    }
+  }
+  
+  public static void main(String args[]) throws IOException {
+    if (args.length != 1) {
+      System.err.println(LocalizedStrings.ArchiveSplitter_USAGE.toLocalizedString() + ": com.gemstone.gemfire.internal.statistics.ArchiveSplitter <archive.gfs>");
+      System.exit(1);
+    }
+    ArchiveSplitter as = new ArchiveSplitter(new File(args[0]));
+    as.split();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7334c131/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/CallbackSampler.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/CallbackSampler.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/CallbackSampler.java
index 4bc3009..4b16a28 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/CallbackSampler.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/CallbackSampler.java
@@ -23,9 +23,6 @@ import java.util.concurrent.TimeUnit;
 import com.gemstone.gemfire.CancelCriterion;
 import com.gemstone.gemfire.Statistics;
 import com.gemstone.gemfire.SystemFailure;
-import com.gemstone.gemfire.internal.StatSamplerStats;
-import com.gemstone.gemfire.internal.StatisticsImpl;
-import com.gemstone.gemfire.internal.StatisticsManager;
 import com.gemstone.gemfire.internal.logging.LogService;
 
 import org.apache.logging.log4j.Logger;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7334c131/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/DummyStatisticsFactory.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/DummyStatisticsFactory.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/DummyStatisticsFactory.java
new file mode 100644
index 0000000..350e381
--- /dev/null
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/DummyStatisticsFactory.java
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+   
+package com.gemstone.gemfire.internal.statistics;
+
+import com.gemstone.gemfire.*;
+
+import java.io.*;
+
+/**
+ * A StatisticsFactory that creates disconnected statistics
+ */
+public class DummyStatisticsFactory implements StatisticsFactory {
+  
+  private final static StatisticsTypeFactoryImpl tf = (StatisticsTypeFactoryImpl) StatisticsTypeFactoryImpl.singleton();
+
+  /** Creates a new instance of DummyStatisticsFactory */
+  public DummyStatisticsFactory() {
+  }
+  
+  // StatisticsFactory methods
+  public Statistics createStatistics(StatisticsType type) {
+    return createStatistics(type, null, 1);
+  }
+  public Statistics createStatistics(StatisticsType type, String textId) {
+    return createStatistics(type, textId, 1);
+  }
+  public Statistics createStatistics(StatisticsType type, String textId, long numericId) {
+    Statistics result = new LocalStatisticsImpl(type, textId, numericId, 1, false, 0, null);
+    return result;
+  }
+
+//  /** for internal use only. Its called by {@link LocalStatisticsImpl#close}. */
+//  public void destroyStatistics(Statistics stats) {
+//    if (statsList.remove(stats)) {
+//      statsListModCount++;
+//    }
+//  }
+//  
+  public Statistics createAtomicStatistics(StatisticsType type) {
+    return createAtomicStatistics(type, null, 1);
+  }
+  public Statistics createAtomicStatistics(StatisticsType type, String textId) {
+    return createAtomicStatistics(type, textId, 1);
+  }
+  public Statistics createAtomicStatistics(StatisticsType type, String textId, long numericId) {
+    Statistics result = new LocalStatisticsImpl(type, textId, numericId, 1, true, 0, null);
+    return result;
+  }
+  public Statistics[] findStatisticsByType(StatisticsType type) {
+    return new Statistics[0];
+  }
+  public Statistics[] findStatisticsByTextId(String textId) {
+    return new Statistics[0];
+  }
+  public Statistics[] findStatisticsByNumericId(long numericId) {
+    return new Statistics[0];
+  }
+
+  public StatisticsType createType(String name, String description,
+                                   StatisticDescriptor[] stats) {
+    return tf.createType(name, description, stats);
+  }
+  public StatisticsType findType(String name) {
+    return tf.findType(name);
+  }
+  public StatisticsType[] createTypesFromXml(Reader reader)
+    throws IOException {
+    return tf.createTypesFromXml(reader);
+  }
+
+  public StatisticDescriptor createIntCounter(String name, String description,
+                                              String units) {
+    return tf.createIntCounter(name, description, units);
+  }
+  public StatisticDescriptor createLongCounter(String name, String description,
+                                               String units) {
+    return tf.createLongCounter(name, description, units);
+  }
+  public StatisticDescriptor createDoubleCounter(String name, String description,
+                                                 String units) {
+    return tf.createDoubleCounter(name, description, units);
+  }
+  public StatisticDescriptor createIntGauge(String name, String description,
+                                            String units) {
+    return tf.createIntGauge(name, description, units);
+  }
+  public StatisticDescriptor createLongGauge(String name, String description,
+                                             String units) {
+    return tf.createLongGauge(name, description, units);
+  }
+  public StatisticDescriptor createDoubleGauge(String name, String description,
+                                               String units) {
+    return tf.createDoubleGauge(name, description, units);
+  }
+  public StatisticDescriptor createIntCounter(String name, String description,
+                                              String units, boolean largerBetter) {
+    return tf.createIntCounter(name, description, units, largerBetter);
+  }
+  public StatisticDescriptor createLongCounter(String name, String description,
+                                               String units, boolean largerBetter) {
+    return tf.createLongCounter(name, description, units, largerBetter);
+  }
+  public StatisticDescriptor createDoubleCounter(String name, String description,
+                                                 String units, boolean largerBetter) {
+    return tf.createDoubleCounter(name, description, units, largerBetter);
+  }
+  public StatisticDescriptor createIntGauge(String name, String description,
+                                            String units, boolean largerBetter) {
+    return tf.createIntGauge(name, description, units, largerBetter);
+  }
+  public StatisticDescriptor createLongGauge(String name, String description,
+                                             String units, boolean largerBetter) {
+    return tf.createLongGauge(name, description, units, largerBetter);
+  }
+  public StatisticDescriptor createDoubleGauge(String name, String description,
+                                               String units, boolean largerBetter) {
+    return tf.createDoubleGauge(name, description, units, largerBetter);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7334c131/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/DummyStatisticsImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/DummyStatisticsImpl.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/DummyStatisticsImpl.java
new file mode 100644
index 0000000..b5c5ec1
--- /dev/null
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/DummyStatisticsImpl.java
@@ -0,0 +1,242 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.statistics;
+
+import java.util.function.DoubleSupplier;
+import java.util.function.IntSupplier;
+import java.util.function.LongSupplier;
+
+import com.gemstone.gemfire.*;
+
+/**
+ * An implementation of {@link Statistics} that does nothing.
+ * Setting the "gemfire.statsDisabled" to true causes it to be used.
+ *
+ * @see <A href="package-summary.html#statistics">Package introduction</A>
+ *
+ *
+ * @since GemFire 3.0
+ *
+ */
+public class DummyStatisticsImpl implements Statistics {
+  
+  private final StatisticsType type;
+  private final String textId;
+  private final long numericId;
+
+  ///////////////////////  Constructors  ///////////////////////
+
+  /**
+   * Creates a new statistics instance of the given type
+   *
+   * @param type
+   *        A description of the statistics
+   */
+  public DummyStatisticsImpl(StatisticsType type, String textId, long numericId) {
+    this.type = type;
+    this.textId = textId;
+    this.numericId = numericId;
+  }
+
+  public final void close() {
+  }
+
+  ////////////////////////  accessor Methods  ///////////////////////
+
+  public final int nameToId(String name) {
+    return this.type.nameToId(name);
+  }
+
+  public final StatisticDescriptor nameToDescriptor(String name) {
+    return this.type.nameToDescriptor(name);
+  }
+
+  public final long getUniqueId() {
+    return 0;
+  }
+
+  public final StatisticsType getType() {
+    return this.type;
+  }
+
+  public final String getTextId() {
+    return this.textId;
+  }
+  public final long getNumericId() {
+    return this.numericId;
+  }
+  public final boolean isAtomic() {
+    return true;
+  }
+  public final boolean isClosed() {
+    return false;
+  }
+  
+  ////////////////////////  set() Methods  ///////////////////////
+
+  public final void setInt(int id, int value) {
+  }
+
+  public final void setInt(StatisticDescriptor descriptor, int value) {
+  }
+
+  public final void setInt(String name, int value) {
+  }
+
+  public final void setLong(int id, long value) {
+  }
+
+  public final void setLong(StatisticDescriptor descriptor, long value) {
+  }
+
+  public final void setLong(String name, long value) {
+  }
+
+  public final void setDouble(int id, double value) {
+  }
+
+  public final void setDouble(StatisticDescriptor descriptor, double value) {
+  }
+
+  public final void setDouble(String name, double value) {
+  }
+
+  ///////////////////////  get() Methods  ///////////////////////
+
+  public final int getInt(int id) {
+    return 0;
+  }
+
+  public final int getInt(StatisticDescriptor descriptor) {
+    return 0;
+  }
+
+  public final int getInt(String name) {
+    return 0;
+  }
+
+  public final long getLong(int id) {
+    return 0;
+  }
+
+  public final long getLong(StatisticDescriptor descriptor) {
+    return 0;
+  }
+
+  public final long getLong(String name) {
+    return 0;
+  }
+
+  public final double getDouble(int id) {
+    return 0.0;
+  }
+
+  public final double getDouble(StatisticDescriptor descriptor) {
+    return 0.0;
+  }
+
+  public final double getDouble(String name) {
+    return 0.0;
+  }
+
+  private static final Number dummyNumber = Integer.valueOf(0);
+
+  public final Number get(StatisticDescriptor descriptor) {
+    return dummyNumber; 
+  }
+
+  public final Number get(String name) {
+    return dummyNumber; 
+  }
+
+  public final long getRawBits(StatisticDescriptor descriptor) {
+    return 0;
+  }
+
+  public final long getRawBits(String name) {
+    return 0;
+  }
+
+  ////////////////////////  inc() Methods  ////////////////////////
+
+  public final void incInt(int id, int delta) {
+  }
+
+  public final void incInt(StatisticDescriptor descriptor, int delta) {
+  }
+
+  public final void incInt(String name, int delta) {
+  }
+
+  public final void incLong(int id, long delta) {
+  }
+
+  public final void incLong(StatisticDescriptor descriptor, long delta) {
+  }
+
+  public final void incLong(String name, long delta) {
+  }
+
+  public final void incDouble(int id, double delta) {
+  }
+
+  public final void incDouble(StatisticDescriptor descriptor, double delta) {
+  }
+
+  public final void incDouble(String name, double delta) {
+  }
+
+  @Override
+  public IntSupplier setIntSupplier(final int id, final IntSupplier supplier) {
+    return null;
+  }
+
+  @Override
+  public IntSupplier setIntSupplier(final String name, final IntSupplier supplier) {
+    return null;
+  }
+
+  @Override
+  public IntSupplier setIntSupplier(final StatisticDescriptor descriptor, final IntSupplier supplier) {
+    return null;
+  }
+
+  @Override public LongSupplier setLongSupplier(final int id, final LongSupplier supplier) {
+    return null;
+  }
+
+  @Override public LongSupplier setLongSupplier(final String name, final LongSupplier supplier) {
+    return null;
+  }
+
+  @Override public LongSupplier setLongSupplier(final StatisticDescriptor descriptor, final LongSupplier supplier) {
+    return null;
+  }
+
+  @Override public DoubleSupplier setDoubleSupplier(final int id, final DoubleSupplier supplier) {
+    return null;
+  }
+
+  @Override public DoubleSupplier setDoubleSupplier(final String name, final DoubleSupplier supplier) {
+    return null;
+  }
+
+  @Override
+  public DoubleSupplier setDoubleSupplier(final StatisticDescriptor descriptor, final DoubleSupplier supplier) {
+    return null;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7334c131/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/GemFireStatSampler.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/GemFireStatSampler.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/GemFireStatSampler.java
new file mode 100644
index 0000000..c723b0c
--- /dev/null
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/GemFireStatSampler.java
@@ -0,0 +1,507 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.statistics;
+
+import com.gemstone.gemfire.Statistics;
+import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
+import com.gemstone.gemfire.distributed.internal.membership.InternalDistributedMember;
+import com.gemstone.gemfire.internal.GemFireVersion;
+import com.gemstone.gemfire.internal.OSProcess;
+import com.gemstone.gemfire.internal.PureJavaMode;
+import com.gemstone.gemfire.internal.admin.ListenerIdMap;
+import com.gemstone.gemfire.internal.admin.remote.StatListenerMessage;
+import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
+import com.gemstone.gemfire.internal.logging.LogService;
+import com.gemstone.gemfire.internal.logging.log4j.LocalizedMessage;
+import com.gemstone.gemfire.internal.logging.log4j.LogMarker;
+import com.gemstone.gemfire.internal.statistics.platform.OsStatisticsFactory;
+import com.gemstone.gemfire.internal.statistics.platform.ProcessStats;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.logging.log4j.Logger;
+
+/**
+ * GemFireStatSampler adds listeners and rolling archives to HostStatSampler.
+ * <p>
+ * The StatisticsManager is implemented by DistributedSystem.
+ * 
+ */
+public final class GemFireStatSampler extends HostStatSampler {
+
+  private static final Logger logger = LogService.getLogger();
+  
+  private final ListenerIdMap listeners = new ListenerIdMap();
+  
+  // TODO: change the listener maps to be copy-on-write
+  
+  private final Map<LocalStatListenerImpl, Boolean> localListeners = 
+      new ConcurrentHashMap<LocalStatListenerImpl, Boolean>();
+  
+  private final Map<InternalDistributedMember, List<RemoteStatListenerImpl>> recipientToListeners = 
+      new HashMap<InternalDistributedMember, List<RemoteStatListenerImpl>>();
+  
+  private final InternalDistributedSystem con;
+  
+  private int nextListenerId = 1;
+  private ProcessStats processStats = null;
+
+  //////////////////////  Constructors  //////////////////////
+
+  public GemFireStatSampler(InternalDistributedSystem con) {
+    super(con.getCancelCriterion(), new StatSamplerStats(con, con.getId()));
+    this.con = con;
+  }
+  
+  /**
+   * Returns the <code>ProcessStats</code> for this Java VM.  Note
+   * that <code>null</code> will be returned if operating statistics
+   * are disabled.
+   *
+   * @since GemFire 3.5
+   */
+  public final ProcessStats getProcessStats() {
+    return this.processStats;
+  }
+  
+  @Override
+  public String getProductDescription() {
+    return "GemFire " + GemFireVersion.getGemFireVersion()
+           + " #" + GemFireVersion.getBuildId()
+           + " as of " + GemFireVersion.getSourceDate();
+  }
+
+  public int addListener(InternalDistributedMember recipient, long resourceId, String statName) {
+    int result = getNextListenerId();
+    synchronized (listeners) {
+      while (listeners.get(result) != null) {
+        // previous one was still being used
+        result = getNextListenerId();
+      }
+      RemoteStatListenerImpl sl = RemoteStatListenerImpl.create(result, recipient, 
+          resourceId, statName, this);
+      listeners.put(result, sl);
+      List<RemoteStatListenerImpl> l = recipientToListeners.get(recipient);
+      if (l == null) {
+        l = new ArrayList<RemoteStatListenerImpl>();
+        recipientToListeners.put(recipient, l);
+      }
+      l.add(sl);
+    }
+    return result;
+  }
+  
+  public boolean removeListener(int listenerId) {
+    synchronized (listeners) {
+      RemoteStatListenerImpl sl = (RemoteStatListenerImpl)listeners.remove(listenerId);
+      if (sl != null) {
+        List<RemoteStatListenerImpl> l = recipientToListeners.get(sl.getRecipient());
+        l.remove(sl);
+      }
+      return sl != null;
+    }
+  }
+
+  public void removeListenersByRecipient(InternalDistributedMember recipient) {
+    synchronized (listeners) {
+      List<RemoteStatListenerImpl> l = recipientToListeners.get(recipient);
+      if (l != null && l.size() != 0) {
+        for (RemoteStatListenerImpl sl : l) {
+          listeners.remove(sl.getListenerId());
+        }
+        recipientToListeners.remove(recipient);
+      }
+    }
+  }
+
+  public void addLocalStatListener(LocalStatListener l, Statistics stats, String statName) {
+    LocalStatListenerImpl sl = null;
+    synchronized (LocalStatListenerImpl.class) {
+      sl = LocalStatListenerImpl.create(l, stats, statName);
+    }
+    this.localListeners.put(sl, Boolean.TRUE);
+  }
+
+  public boolean removeLocalStatListener(LocalStatListener listener) {
+    Iterator<Map.Entry<LocalStatListenerImpl, Boolean>> it = 
+                  this.localListeners.entrySet().iterator();
+    while (it.hasNext()) {
+      Map.Entry<LocalStatListenerImpl, Boolean> entry = it.next();
+      if (listener.equals(entry.getKey().getListener())) {
+        it.remove();
+        return true;
+      }
+    }
+    return false;
+  }
+
+  public Set<LocalStatListenerImpl> getLocalListeners() {
+    return this.localListeners.keySet();
+  }
+  
+  @Override
+  public final File getArchiveFileName() {
+    return this.con.getConfig().getStatisticArchiveFile();
+  }
+  
+  @Override
+  public final long getArchiveFileSizeLimit() {
+    if (fileSizeLimitInKB()) {
+      // use KB instead of MB to speed up rolling for testing
+      return ((long)this.con.getConfig().getArchiveFileSizeLimit()) * (1024);
+    } else {
+      return ((long)this.con.getConfig().getArchiveFileSizeLimit()) * (1024*1024);
+    }
+  }
+  
+  @Override
+  public final long getArchiveDiskSpaceLimit() {
+    if (fileSizeLimitInKB()) {
+      // use KB instead of MB to speed up removal for testing
+      return ((long)this.con.getConfig().getArchiveDiskSpaceLimit()) * (1024);
+    } else {
+      return ((long)this.con.getConfig().getArchiveDiskSpaceLimit()) * (1024*1024);
+    }
+  }
+  
+  @Override
+  protected void checkListeners() {
+    checkLocalListeners();
+    synchronized (listeners) {
+      if (listeners.size() == 0) {
+        return;
+      }
+      long timeStamp = System.currentTimeMillis();
+      Iterator<Map.Entry<InternalDistributedMember, List<RemoteStatListenerImpl>>> it1 = 
+          recipientToListeners.entrySet().iterator();
+      while (it1.hasNext()) {
+        if (stopRequested()) return;
+        Map.Entry<InternalDistributedMember, List<RemoteStatListenerImpl>> me = 
+            it1.next();
+        List<RemoteStatListenerImpl> l = me.getValue();
+        if (l.size() > 0) {
+          InternalDistributedMember recipient = (InternalDistributedMember)me.getKey();
+          StatListenerMessage msg =
+            StatListenerMessage.create(timeStamp, l.size());
+          msg.setRecipient(recipient);
+          for (RemoteStatListenerImpl statListener : l) {
+            if (getStatisticsManager().statisticsExists(statListener.getStatId())) {
+              statListener.checkForChange(msg);
+            } else {
+              // its stale; indicate this with a negative listener id
+              // fix for bug 29405
+              msg.addChange(-statListener.getListenerId(), 0);
+            }
+          }
+          this.con.getDistributionManager().putOutgoing(msg);
+        }
+      }
+    }
+  }
+  
+  @Override
+  protected final int getSampleRate() {
+    return this.con.getConfig().getStatisticSampleRate();
+  }
+  
+  @Override
+  public final boolean isSamplingEnabled() {
+    return this.con.getConfig().getStatisticSamplingEnabled();
+  }
+  
+  @Override
+  protected final StatisticsManager getStatisticsManager() {
+    return this.con;
+  }
+  
+  @Override
+  protected final OsStatisticsFactory getOsStatisticsFactory() {
+    return this.con;
+  }
+  
+  @Override
+  protected final long getSpecialStatsId() {
+    long statId = OSProcess.getId();
+    if (statId == 0 || statId == -1) {
+      statId = getStatisticsManager().getId();
+    }
+    return statId;
+  }
+  
+  @Override
+  protected final void initProcessStats(long id) {
+    if (PureJavaMode.osStatsAreAvailable()) {
+      if (osStatsDisabled()) {
+        logger.info(LogMarker.STATISTICS, LocalizedMessage.create(LocalizedStrings.GemFireStatSampler_OS_STATISTIC_COLLECTION_DISABLED_BY_OSSTATSDISABLED_SYSTEM_PROPERTY));
+      } else {
+        int retVal = HostStatHelper.initOSStats();
+        if ( retVal != 0 ) {
+          logger.error(LogMarker.STATISTICS, LocalizedMessage.create(LocalizedStrings.GemFireStatSampler_OS_STATISTICS_FAILED_TO_INITIALIZE_PROPERLY_SOME_STATS_MAY_BE_MISSING_SEE_BUGNOTE_37160)); 
+        }
+        HostStatHelper.newSystem(getOsStatisticsFactory());
+        String statName = getStatisticsManager().getName();
+        if (statName == null || statName.length() == 0) {
+          statName = "javaApp" + getStatisticsManager().getId();
+        }
+        Statistics stats = HostStatHelper.newProcess(getOsStatisticsFactory(), id, statName + "-proc");
+        this.processStats = HostStatHelper.newProcessStats(stats); 
+      }
+    }
+  }
+
+ @Override
+  protected final void sampleProcessStats(boolean prepareOnly) {
+    if (prepareOnly || osStatsDisabled() || !PureJavaMode.osStatsAreAvailable()) {
+      return;
+    }
+    List<Statistics> l = getStatisticsManager().getStatsList();
+    if (l == null) {
+      return;
+    }
+    if (stopRequested()) return;
+    HostStatHelper.readyRefreshOSStats();
+    Iterator<Statistics> it = l.iterator();
+    while (it.hasNext()) {
+      if (stopRequested()) return;
+      StatisticsImpl s = (StatisticsImpl)it.next();
+      if (s.usesSystemCalls()) {
+        HostStatHelper.refresh((LocalStatisticsImpl)s);
+      }
+    }
+  }
+
+ @Override
+  protected final void closeProcessStats() {
+    if (PureJavaMode.osStatsAreAvailable()) {
+      if (!osStatsDisabled()) {
+        if (this.processStats != null) {
+          this.processStats.close();
+        }
+        HostStatHelper.closeOSStats();
+      }
+    }
+  }
+
+  private void checkLocalListeners() {
+    for (LocalStatListenerImpl st : this.localListeners.keySet()) {
+      if (getStatisticsManager().statisticsExists(st.getStatId())) {
+        st.checkForChange();
+      }
+    }
+  }
+  
+  private int getNextListenerId() {
+    int result = nextListenerId++;
+    if (nextListenerId < 0) {
+      nextListenerId = 1;
+    }
+    return result;
+  }
+    
+  protected static abstract class StatListenerImpl {
+    protected Statistics stats;
+    protected StatisticDescriptorImpl stat;
+    protected boolean oldValueInitialized = false;
+    protected long oldValue;
+
+    public long getStatId() {
+      if (this.stats.isClosed()) {
+        return -1;
+      } else {
+        return this.stats.getUniqueId();
+      }
+    }
+    
+    protected abstract double getBitsAsDouble(long bits);
+  }
+
+  protected static abstract class LocalStatListenerImpl extends StatListenerImpl {
+    private LocalStatListener listener;
+    
+    public LocalStatListener getListener() {
+      return this.listener;
+    }
+    
+    static LocalStatListenerImpl create(LocalStatListener l, Statistics stats, String statName) {
+      LocalStatListenerImpl result = null;
+      StatisticDescriptorImpl stat = (StatisticDescriptorImpl)stats.nameToDescriptor(statName);
+      switch (stat.getTypeCode()) {
+      case StatisticDescriptorImpl.BYTE:
+      case StatisticDescriptorImpl.SHORT:
+      case StatisticDescriptorImpl.INT:
+      case StatisticDescriptorImpl.LONG:
+        result = new LocalLongStatListenerImpl();
+        break;
+      case StatisticDescriptorImpl.FLOAT:
+        result = new LocalFloatStatListenerImpl();
+        break;
+      case StatisticDescriptorImpl.DOUBLE:
+        result = new LocalDoubleStatListenerImpl();
+        break;
+      default:
+        throw new RuntimeException("Illegal field type " + stats.getType() + " for statistic");
+      }
+      result.stats = stats;
+      result.stat = stat;
+      result.listener = l;
+      return result;
+    }
+    
+    /**
+     * Checks to see if the value of the stat has changed. If it has then 
+     * the local listener is fired
+     */
+    public void checkForChange() {
+      long currentValue = stats.getRawBits(stat);
+      if (oldValueInitialized) {
+        if (currentValue == oldValue) {
+          return;
+        }
+      } else {
+        oldValueInitialized = true;
+      }
+      oldValue = currentValue;
+      listener.statValueChanged(getBitsAsDouble(currentValue));
+    }
+  }
+  
+  protected static class LocalLongStatListenerImpl extends LocalStatListenerImpl {
+    @Override
+    protected double getBitsAsDouble(long bits) {
+      return bits;
+    }
+  }
+
+  protected static class LocalFloatStatListenerImpl extends LocalStatListenerImpl {
+    @Override
+    protected double getBitsAsDouble(long bits) {
+      return Float.intBitsToFloat((int)bits);
+    }
+  }
+  
+  protected static class LocalDoubleStatListenerImpl extends LocalStatListenerImpl {
+    @Override
+    protected double getBitsAsDouble(long bits) {
+      return Double.longBitsToDouble(bits);
+    }
+  }
+
+  /**
+   * Used to register a StatListener.
+   */
+  protected static abstract class RemoteStatListenerImpl extends StatListenerImpl{
+    private int listenerId;
+    private InternalDistributedMember recipient;
+
+    @Override
+    public final int hashCode() {
+      return listenerId;
+    }
+    
+    @Override
+    public final boolean equals(Object o) {
+      if (o == null) {
+        return false;
+      }
+      if (o instanceof RemoteStatListenerImpl) {
+        return listenerId == ((RemoteStatListenerImpl)o).listenerId;
+      } else {
+        return false;
+      }
+    }
+
+    public int getListenerId() {
+      return this.listenerId;
+    }
+    
+    public InternalDistributedMember getRecipient() {
+      return this.recipient;
+    }
+    
+    static RemoteStatListenerImpl create(int listenerId, InternalDistributedMember recipient, long resourceId, String statName, HostStatSampler sampler) {
+      RemoteStatListenerImpl result = null;
+      Statistics stats = sampler.getStatisticsManager().findStatistics(resourceId);
+      StatisticDescriptorImpl stat = (StatisticDescriptorImpl)stats.nameToDescriptor(statName);
+      switch (stat.getTypeCode()) {
+      case StatisticDescriptorImpl.BYTE:
+      case StatisticDescriptorImpl.SHORT:
+      case StatisticDescriptorImpl.INT:
+      case StatisticDescriptorImpl.LONG:
+        result = new LongStatListenerImpl();
+        break;
+      case StatisticDescriptorImpl.FLOAT:
+        result = new FloatStatListenerImpl();
+        break;
+      case StatisticDescriptorImpl.DOUBLE:
+        result = new DoubleStatListenerImpl();
+        break;
+      default:
+        throw new RuntimeException(LocalizedStrings.GemFireStatSampler_ILLEGAL_FIELD_TYPE_0_FOR_STATISTIC.toLocalizedString(stats.getType()));
+      }
+      result.stats = stats;
+      result.stat = stat;
+      result.listenerId = listenerId;
+      result.recipient = recipient;
+      return result;
+    }
+    
+    /**
+     * Checks to see if the value of the stat has changed. If it has then it
+     * adds that change to the specified message.
+     */
+    public void checkForChange(StatListenerMessage msg) {
+      long currentValue = stats.getRawBits(stat);
+      if (oldValueInitialized) {
+        if (currentValue == oldValue) {
+          return;
+        }
+      } else {
+        oldValueInitialized = true;
+      }
+      oldValue = currentValue;
+      msg.addChange(listenerId, getBitsAsDouble(currentValue));
+    }
+  }
+
+  protected static class LongStatListenerImpl extends RemoteStatListenerImpl {
+    @Override
+    protected double getBitsAsDouble(long bits) {
+      return bits;
+    }
+  }
+
+  protected static class FloatStatListenerImpl extends RemoteStatListenerImpl {
+    @Override
+    protected double getBitsAsDouble(long bits) {
+      return Float.intBitsToFloat((int)bits);
+    }
+  }
+  
+  protected static class DoubleStatListenerImpl extends RemoteStatListenerImpl {
+    @Override
+    protected double getBitsAsDouble(long bits) {
+      return Double.longBitsToDouble(bits);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7334c131/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/HostStatHelper.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/HostStatHelper.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/HostStatHelper.java
new file mode 100644
index 0000000..b52eaae
--- /dev/null
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/HostStatHelper.java
@@ -0,0 +1,303 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.statistics;
+
+import com.gemstone.gemfire.*;
+//import com.gemstone.gemfire.util.*;
+import com.gemstone.gemfire.internal.PureJavaMode;
+import com.gemstone.gemfire.internal.SocketCreator;
+import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
+import com.gemstone.gemfire.internal.statistics.platform.LinuxProcFsStatistics;
+import com.gemstone.gemfire.internal.statistics.platform.LinuxProcessStats;
+import com.gemstone.gemfire.internal.statistics.platform.LinuxSystemStats;
+import com.gemstone.gemfire.internal.statistics.platform.OSXProcessStats;
+import com.gemstone.gemfire.internal.statistics.platform.OSXSystemStats;
+import com.gemstone.gemfire.internal.statistics.platform.OsStatisticsFactory;
+import com.gemstone.gemfire.internal.statistics.platform.ProcessStats;
+import com.gemstone.gemfire.internal.statistics.platform.SolarisProcessStats;
+import com.gemstone.gemfire.internal.statistics.platform.SolarisSystemStats;
+import com.gemstone.gemfire.internal.statistics.platform.WindowsProcessStats;
+import com.gemstone.gemfire.internal.statistics.platform.WindowsSystemStats;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+/**
+ * Provides native methods which fetch operating system statistics.
+ */
+public class HostStatHelper {
+  static final int SOLARIS_CODE = 1; // Sparc Solaris
+  static final int WINDOWS_CODE = 2;
+  static final int LINUX_CODE = 3; // x86 Linux
+  static final int OSX_CODE = 4;  // Mac OS X
+
+  static final int PROCESS_STAT_FLAG = 1;
+  static final int SYSTEM_STAT_FLAG = 2;
+  
+  static final int osCode;
+
+  static {
+    String osName = System.getProperty("os.name", "unknown");
+    if (! PureJavaMode.osStatsAreAvailable()) {
+      throw new RuntimeException(LocalizedStrings.HostStatHelper_HOSTSTATHELPER_NOT_ALLOWED_IN_PURE_JAVA_MODE.toLocalizedString());
+    } else if (osName.equals("SunOS")) {
+      osCode = SOLARIS_CODE;
+    } else if (osName.startsWith("Windows")) {
+      osCode = WINDOWS_CODE;
+    } else if (osName.startsWith("Linux")) {
+      osCode = LINUX_CODE;
+    } else if (osName.equals("Mac OS X")) { 
+      osCode = OSX_CODE;
+    } else {
+      throw new InternalGemFireException(LocalizedStrings.HostStatHelper_UNSUPPORTED_OS_0_SUPPORTED_OSS_ARE_SUNOSSPARC_SOLARIS_LINUXX86_AND_WINDOWS.toLocalizedString(osName));
+    }
+  }
+  public static boolean isWindows() {
+    return osCode == WINDOWS_CODE;
+  }
+  public static boolean isUnix() {
+    return osCode != WINDOWS_CODE;
+  }
+  public static boolean isSolaris() {
+    return osCode == SOLARIS_CODE;
+  }
+  public static boolean isLinux() {
+    return osCode == LINUX_CODE;
+  }
+  public static boolean isOSX() {
+      return osCode == OSX_CODE;
+  }
+  
+  private HostStatHelper() {
+    // instances are not allowed
+  }
+
+  static int initOSStats() {
+    if(isLinux()) {
+      return LinuxProcFsStatistics.init();
+    } else {
+      return HostStatHelper.init();
+    }
+  }
+  
+  static void closeOSStats() {
+    if(isLinux()) {
+      LinuxProcFsStatistics.close();
+    } else {
+      HostStatHelper.close();
+    }
+  }
+  
+  static void readyRefreshOSStats() {
+    if(isLinux()) {
+      LinuxProcFsStatistics.readyRefresh();
+    } else {
+      HostStatHelper.readyRefresh();
+    }
+  }
+  
+  /**
+   * Allocates and initializes any resources required to sample
+   * operating system statistics.
+   * returns 0 if initialization succeeded
+   */
+  private static native int init();
+  /**
+   * Frees up resources used by this class. Once close is called this
+   * class can no longer be used.
+   */
+  private static native void close();
+  /**
+   * Should be called before any calls to the refresh methods.
+   * On some platforms if this is not called then the refesh methods
+   * will just keep returning the same old data.
+   */
+  private static native void readyRefresh();
+  /**
+   * Refreshes the specified process stats instance by fetching
+   * the current OS values for the given stats and storing them in the instance.
+   */
+  private static void refreshProcess(LocalStatisticsImpl s) {
+    int pid = (int)s.getNumericId();
+    if(isLinux()) {
+      LinuxProcFsStatistics.refreshProcess(pid, s._getIntStorage(), s._getLongStorage(), s._getDoubleStorage());
+    } else {
+      refreshProcess(pid, s._getIntStorage(), s._getLongStorage(), s._getDoubleStorage());
+    }  
+  }
+  private static native void refreshProcess(int pid, int[] ints, long[] longs, double[] doubles);
+  /**
+   * Refreshes the specified system stats instance by fetching
+   * the current OS values for the local machine and storing them in
+   * the instance.
+   */
+  private static void refreshSystem(LocalStatisticsImpl s) {
+    if(isLinux()) {
+      LinuxProcFsStatistics.refreshSystem(s._getIntStorage(), s._getLongStorage(), s._getDoubleStorage());
+    } else {
+      refreshSystem(s._getIntStorage(), s._getLongStorage(), s._getDoubleStorage());
+    }
+  }
+  private static native void refreshSystem(int[] ints, long[] longs, double[] doubles);
+
+  /**
+   * The call should have already checked to make sure
+   * usesSystemCalls returns true.
+   */
+  public static void refresh(LocalStatisticsImpl stats) {
+    int flags = stats.getOsStatFlags();
+    if ((flags & PROCESS_STAT_FLAG) != 0) {
+      HostStatHelper.refreshProcess(stats);
+    } else if ((flags & SYSTEM_STAT_FLAG) != 0) {
+      HostStatHelper.refreshSystem(stats);
+    } else {
+      throw new RuntimeException(LocalizedStrings.HostStatHelper_UNEXPECTED_OS_STATS_FLAGS_0.toLocalizedString(Integer.valueOf(flags)));
+    }
+  }
+  
+  /**
+   * Creates and returns a {@link Statistics} with
+   * the given pid and name. The resource's stats will contain a snapshot
+   * of the current statistic values for the specified process.
+   */
+  public static Statistics newProcess(OsStatisticsFactory f, long pid, String name) {
+    Statistics stats;
+    switch (osCode) {
+    case SOLARIS_CODE:
+      stats = f.createOsStatistics(SolarisProcessStats.getType(),
+                                   name, pid, PROCESS_STAT_FLAG);
+      break;
+    case LINUX_CODE:
+      stats = f.createOsStatistics(LinuxProcessStats.getType(),
+                                   name, pid, PROCESS_STAT_FLAG);
+      break;
+    case OSX_CODE:
+        stats = f.createOsStatistics(OSXProcessStats.getType(),
+                                     name, pid, PROCESS_STAT_FLAG);
+        break;
+    case WINDOWS_CODE:
+      stats = f.createOsStatistics(WindowsProcessStats.getType(),
+                                   name, pid, PROCESS_STAT_FLAG);
+      break;
+    default:
+      throw new InternalGemFireException(LocalizedStrings.HostStatHelper_UNHANDLED_OSCODE_0_HOSTSTATHELPERNEWPROCESS.toLocalizedString(Integer.valueOf(osCode)));
+    }
+    // Note we don't call refreshProcess since we only want the manager to do that
+    return stats;
+  }
+
+  /**
+   * Creates a new <code>ProcessStats</code> instance that wraps the
+   * given <code>Statistics</code>.
+   *
+   * @see #newProcess
+   * @since GemFire 3.5
+   */
+  static ProcessStats newProcessStats(Statistics stats) {
+    switch (osCode) {
+    case SOLARIS_CODE:
+      return SolarisProcessStats.createProcessStats(stats);
+
+    case LINUX_CODE:
+      return LinuxProcessStats.createProcessStats(stats);
+
+    case WINDOWS_CODE:
+      return WindowsProcessStats.createProcessStats(stats);
+
+    case OSX_CODE:
+        return OSXProcessStats.createProcessStats(stats);
+        
+    default:
+      throw new InternalGemFireException(LocalizedStrings.HostStatHelper_UNHANDLED_OSCODE_0_HOSTSTATHELPERNEWPROCESSSTATS.toLocalizedString(Integer.valueOf(osCode)));
+    }
+  }
+
+  /**
+   * Creates and returns a {@link Statistics} with the current
+   * machine's stats. The resource's stats will contain a snapshot
+   * of the current statistic values for the local machine.
+   */
+  static void newSystem(OsStatisticsFactory f) {
+    Statistics stats;
+    switch (osCode) {
+    case SOLARIS_CODE:
+      stats = f.createOsStatistics(SolarisSystemStats.getType(),
+                                   getHostSystemName(),
+                                   getHostSystemId(),
+                                   SYSTEM_STAT_FLAG);
+      break;
+    case LINUX_CODE:
+      stats = f.createOsStatistics(LinuxSystemStats.getType(),
+                                   getHostSystemName(),
+                                   getHostSystemId(),
+                                   SYSTEM_STAT_FLAG);
+      break;
+    case WINDOWS_CODE:
+      stats = f.createOsStatistics(WindowsSystemStats.getType(),
+                                   getHostSystemName(),
+                                   getHostSystemId(),
+                                   SYSTEM_STAT_FLAG);
+      break;
+    case OSX_CODE:
+      stats = f.createOsStatistics(OSXSystemStats.getType(),
+                                     getHostSystemName(),
+                                     getHostSystemId(),
+                                     SYSTEM_STAT_FLAG);
+      break;
+    default:
+      throw new InternalGemFireException(LocalizedStrings.HostStatHelper_UNHANDLED_OSCODE_0_HOSTSTATHELPERNEWSYSTEM.toLocalizedString(Integer.valueOf(osCode)));
+    }
+    if (stats instanceof LocalStatisticsImpl) {
+      refreshSystem((LocalStatisticsImpl)stats);
+    } // otherwise its a Dummy implementation so do nothing
+  }
+
+  /**
+   * @return this machine's fully qualified hostname 
+   *         or "unknownHostName" if one cannot be found.
+   */
+  private static String getHostSystemName() {
+    String hostname = "unknownHostName";
+    try {
+      InetAddress addr = SocketCreator.getLocalHost();
+      hostname = addr.getCanonicalHostName();
+    } catch (UnknownHostException uhe) {
+    }
+    return hostname;
+  }
+  
+  /** 
+   * Generate a systemid based off of the ip address of the host.
+   * This duplicates the common implementation of 
+   * <code>long gethostid(void) </code>.
+   * Punt on the ipv6 case and just use the same algorithm.
+   * @return a psuedo unique id based on the ip address
+   */
+  private static long getHostSystemId() {
+    long id = 0L;
+    try {
+      InetAddress host = SocketCreator.getLocalHost();
+      byte[] addr = host.getAddress();
+      id = (addr[1] & 0xFFL) << 24 |  
+           (addr[0] & 0xFFL) << 16 |  
+           (addr[3] & 0xFFL) << 8  |  
+           (addr[2] & 0xFFL) << 0;
+    } catch (UnknownHostException uhe) {
+    }
+    return id;
+  }
+}


Mime
View raw message