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