Search in sources :

Example 1 with TimerHandler

use of com.sun.btrace.shared.TimerHandler in project btrace by btraceio.

the class BTraceRuntime method startImpl.

private void startImpl() {
    if (timerHandlers != null) {
        timer = new Timer(true);
        TimerTask[] timerTasks = new TimerTask[timerHandlers.length];
        wrapToTimerTasks(timerTasks);
        for (int index = 0; index < timerHandlers.length; index++) {
            final TimerHandler th = timerHandlers[index];
            long period = th.period;
            String periodArg = th.periodArg;
            if (periodArg != null) {
                period = parseLong(args.template(periodArg), period);
            }
            timer.schedule(timerTasks[index], period, period);
        }
    }
    if (lowMemoryHandlers != null) {
        initMemoryMBean();
        initMemoryListener();
        initMemoryPoolList();
        lowMemoryHandlerMap = new HashMap<>();
        for (LowMemoryHandler lmh : lowMemoryHandlers) {
            String poolName = args.template(lmh.pool);
            lowMemoryHandlerMap.put(poolName, lmh);
        }
        for (MemoryPoolMXBean mpoolBean : memPoolList) {
            String name = mpoolBean.getName();
            LowMemoryHandler lmh = lowMemoryHandlerMap.get(name);
            if (lmh != null) {
                if (mpoolBean.isUsageThresholdSupported()) {
                    mpoolBean.setUsageThreshold(lmh.threshold);
                }
            }
        }
        NotificationEmitter emitter = (NotificationEmitter) memoryMBean;
        emitter.addNotificationListener(memoryListener, null, null);
    }
    leave();
}
Also used : TimerHandler(com.sun.btrace.shared.TimerHandler) NotificationEmitter(javax.management.NotificationEmitter) Timer(java.util.Timer) TimerTask(java.util.TimerTask) LowMemoryHandler(com.sun.btrace.shared.LowMemoryHandler) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean)

Example 2 with TimerHandler

use of com.sun.btrace.shared.TimerHandler in project btrace by btraceio.

the class BTraceRuntime method wrapToTimerTasks.

private void wrapToTimerTasks(TimerTask[] tasks) {
    for (int index = 0; index < timerHandlers.length; index++) {
        final TimerHandler th = timerHandlers[index];
        tasks[index] = new TimerTask() {

            final Method mthd;

            {
                Method m = null;
                try {
                    m = th.getMethod(clazz);
                } catch (NoSuchMethodException e) {
                }
                mthd = m;
            }

            @Override
            public void run() {
                if (mthd != null) {
                    try {
                        mthd.invoke(null, (Object[]) null);
                    } catch (Throwable th) {
                    }
                }
            }
        };
    }
}
Also used : TimerHandler(com.sun.btrace.shared.TimerHandler) TimerTask(java.util.TimerTask) Method(java.lang.reflect.Method)

Aggregations

TimerHandler (com.sun.btrace.shared.TimerHandler)2 TimerTask (java.util.TimerTask)2 LowMemoryHandler (com.sun.btrace.shared.LowMemoryHandler)1 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)1 Method (java.lang.reflect.Method)1 Timer (java.util.Timer)1 NotificationEmitter (javax.management.NotificationEmitter)1