private <T extends Stats> T getStats(String name, StatsBuilder<T> builder, StatsOptions options) { Stats stats = statsRegistry.get(name); //Use double locking pattern. The map should get populated with required set //during startup phase so for later calls should not hit the synchronized block if (stats == null) { synchronized (this){ stats = statsRegistry.get(name); //If still null then go ahead and create it within lock if (stats == null){ if (options.isOnlyMetricEnabled()) { stats = builder.newMetric(this, name); } else if (options.isOnlyTimeSeriesEnabled()) { stats = new SimpleStats(getTimerSeriesStats(name, builder), builder.getType()); } else { stats = builder.newComposite(getTimerSeriesStats(name, builder), this, name); } statsRegistry.put(name, stats); } } } if (builder.isInstance(stats)) { //noinspection unchecked return (T) stats; } throw new IllegalStateException(); }
private synchronized SimpleStats getStats(String type, boolean resetValueEachSecond, SimpleStats.Type statsType, StatsOptions options){ Type enumType = Type.getType(type); SimpleStats stats = statsMeters.get(type); if (stats == null){ if (enumType != null) { stats = new SimpleStats(repoStats.getCounter(enumType), statsType); } else if (options.isTimeSeriesEnabled()) { stats = new SimpleStats(repoStats.getCounter(type, resetValueEachSecond), statsType); } else { stats = new SimpleStats(new AtomicLong(), statsType); } statsMeters.put(type, stats); } return stats; } }
private <T extends Stats> T getStats(String name, StatsBuilder<T> builder, StatsOptions options) { Stats stats = statsRegistry.get(name); //Use double locking pattern. The map should get populated with required set //during startup phase so for later calls should not hit the synchronized block if (stats == null) { synchronized (this){ stats = statsRegistry.get(name); //If still null then go ahead and create it within lock if (stats == null){ if (options.isOnlyMetricEnabled()) { stats = builder.newMetric(this, name); } else if (options.isOnlyTimeSeriesEnabled()) { stats = new SimpleStats(getTimerSeriesStats(name, builder), builder.getType()); } else { stats = builder.newComposite(getTimerSeriesStats(name, builder), this, name); } statsRegistry.put(name, stats); } } } if (builder.isInstance(stats)) { //noinspection unchecked return (T) stats; } throw new IllegalStateException(); }
private synchronized SimpleStats getStats(String type, boolean resetValueEachSecond, SimpleStats.Type statsType, StatsOptions options){ Type enumType = Type.getType(type); SimpleStats stats = statsMeters.get(type); if (stats == null){ if (enumType != null) { stats = new SimpleStats(repoStats.getCounter(enumType), statsType); } else if (options.isTimeSeriesEnabled()) { stats = new SimpleStats(repoStats.getCounter(type, resetValueEachSecond), statsType); } else { stats = new SimpleStats(new AtomicLong(), statsType); } statsMeters.put(type, stats); } return stats; } }
private <T extends Stats> T getStats(String name, StatsBuilder<T> builder, StatsOptions options) { Stats stats = statsRegistry.get(name); //Use double locking pattern. The map should get populated with required set //during startup phase so for later calls should not hit the synchronized block if (stats == null) { synchronized (this){ stats = statsRegistry.get(name); //If still null then go ahead and create it within lock if (stats == null){ if (options.isOnlyMetricEnabled()) { stats = builder.newMetric(this, name); } else if (options.isOnlyTimeSeriesEnabled()) { stats = new SimpleStats(getTimerSeriesStats(name, builder), builder.getType()); } else { stats = builder.newComposite(getTimerSeriesStats(name, builder), this, name); } statsRegistry.put(name, stats); } } } if (builder.isInstance(stats)) { //noinspection unchecked return (T) stats; } throw new IllegalStateException(); }