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 <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 <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(); }