Search in sources :

Example 1 with AFn

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);
}
Also used : AFn(clojure.lang.AFn)

Example 2 with AFn

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);
    }
}
Also used : IMetric(backtype.storm.metric.api.IMetric) AFn(clojure.lang.AFn)

Example 3 with AFn

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);
    }
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) IMetric(backtype.storm.metric.api.IMetric) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) AFn(clojure.lang.AFn) RuntimeMXBean(java.lang.management.RuntimeMXBean)

Aggregations

AFn (clojure.lang.AFn)3 IMetric (backtype.storm.metric.api.IMetric)2 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)1 MemoryMXBean (java.lang.management.MemoryMXBean)1 RuntimeMXBean (java.lang.management.RuntimeMXBean)1