use of clojure.lang.AFn in project data.int-map by clojure.
the class IntSet method range.
public ISet range(final long epoch, final long min, final long max) {
if (max < min) {
return new IntSet(leafSize);
}
if (mapKey(min) == mapKey(max)) {
ISet set = (ISet) map.get(mapKey(min), null);
set = set == null ? null : set.range(epoch, leafOffset(min), leafOffset(max));
return set == null ? new IntSet(leafSize) : new IntSet(leafSize, log2LeafSize, Nodes.Empty.EMPTY.assoc(mapKey(min), epoch, null, set));
}
INode mapPrime = map.range(mapKey(min), mapKey(max));
mapPrime = mapPrime == null ? Nodes.Empty.EMPTY : mapPrime.update(mapKey(min), epoch, new AFn() {
public Object invoke(Object v) {
return v != null ? ((ISet) v).range(epoch, leafOffset(min), leafSize) : null;
}
}).update(mapKey(max), epoch, new AFn() {
public Object invoke(Object v) {
return v != null ? ((ISet) v).range(epoch, 0, leafOffset(max)) : null;
}
});
return new IntSet(leafSize, log2LeafSize, mapPrime);
}
use of clojure.lang.AFn in project storm by nathanmarz.
the class SystemBolt method prepare.
@Override
public void prepare(final Map stormConf, TopologyContext context, OutputCollector collector) {
if (_prepareWasCalled && !"local".equals(stormConf.get(Config.STORM_CLUSTER_MODE))) {
throw new RuntimeException("A single worker should have 1 SystemBolt instance.");
}
_prepareWasCalled = true;
int bucketSize = RT.intCast(stormConf.get(Config.TOPOLOGY_BUILTIN_METRICS_BUCKET_SIZE_SECS));
final RuntimeMXBean jvmRT = ManagementFactory.getRuntimeMXBean();
context.registerMetric("uptimeSecs", new IMetric() {
@Override
public Object getValueAndReset() {
return jvmRT.getUptime() / 1000.0;
}
}, bucketSize);
context.registerMetric("startTimeSecs", new IMetric() {
@Override
public Object getValueAndReset() {
return jvmRT.getStartTime() / 1000.0;
}
}, bucketSize);
context.registerMetric("newWorkerEvent", new IMetric() {
boolean doEvent = true;
@Override
public Object getValueAndReset() {
if (doEvent) {
doEvent = false;
return 1;
} else
return 0;
}
}, bucketSize);
final MemoryMXBean jvmMemRT = ManagementFactory.getMemoryMXBean();
context.registerMetric("memory/heap", new MemoryUsageMetric(new AFn() {
public Object invoke() {
return jvmMemRT.getHeapMemoryUsage();
}
}), bucketSize);
context.registerMetric("memory/nonHeap", new MemoryUsageMetric(new AFn() {
public Object invoke() {
return jvmMemRT.getNonHeapMemoryUsage();
}
}), bucketSize);
for (GarbageCollectorMXBean b : ManagementFactory.getGarbageCollectorMXBeans()) {
context.registerMetric("GC/" + b.getName().replaceAll("\\W", ""), new GarbageCollectorMetric(b), bucketSize);
}
}
use of clojure.lang.AFn in project jstorm by alibaba.
the class SystemBolt method prepare.
@Override
public void prepare(final Map stormConf, TopologyContext context, OutputCollector collector) {
if (_prepareWasCalled && !"local".equals(stormConf.get(Config.STORM_CLUSTER_MODE))) {
throw new RuntimeException("A single worker should have 1 SystemBolt instance.");
}
_prepareWasCalled = true;
int bucketSize = RT.intCast(stormConf.get(Config.TOPOLOGY_BUILTIN_METRICS_BUCKET_SIZE_SECS));
final RuntimeMXBean jvmRT = ManagementFactory.getRuntimeMXBean();
context.registerMetric("uptimeSecs", new IMetric() {
@Override
public Object getValueAndReset() {
return jvmRT.getUptime() / 1000.0;
}
}, bucketSize);
context.registerMetric("startTimeSecs", new IMetric() {
@Override
public Object getValueAndReset() {
return jvmRT.getStartTime() / 1000.0;
}
}, bucketSize);
context.registerMetric("newWorkerEvent", new IMetric() {
boolean doEvent = true;
@Override
public Object getValueAndReset() {
if (doEvent) {
doEvent = false;
return 1;
} else
return 0;
}
}, bucketSize);
final MemoryMXBean jvmMemRT = ManagementFactory.getMemoryMXBean();
context.registerMetric("memory/heap", new MemoryUsageMetric(new AFn() {
public Object invoke() {
return jvmMemRT.getHeapMemoryUsage();
}
}), bucketSize);
context.registerMetric("memory/nonHeap", new MemoryUsageMetric(new AFn() {
public Object invoke() {
return jvmMemRT.getNonHeapMemoryUsage();
}
}), bucketSize);
for (GarbageCollectorMXBean b : ManagementFactory.getGarbageCollectorMXBeans()) {
context.registerMetric("GC/" + b.getName().replaceAll("\\W", ""), new GarbageCollectorMetric(b), bucketSize);
}
}
Aggregations