use of com.infiniteautomation.mango.monitor.ValueMonitorOwner in project ma-core-public by infiniteautomation.
the class MonitoredValuesTest method loadTest.
public void loadTest() {
// Setup a Timer
RealTimeTimer timer = new OrderedRealTimeTimer();
ThreadPoolExecutor executor = new OrderedThreadPoolExecutor(0, 100, 30L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new MangoThreadFactory("high", Thread.MAX_PRIORITY), new RejectedExecutionHandler() {
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
System.out.println("Rejected: " + r.toString());
}
}, false, timer.getTimeSource());
timer.init(executor);
// Create a monitor
IntegerMonitor monitor = new IntegerMonitor(MONITOR_ID, new TranslatableMessage("internal.monitor.BATCH_ENTRIES"), new ValueMonitorOwner() {
@Override
public void reset(String monitorId) {
IntegerMonitor mon = (IntegerMonitor) MONITORED_VALUES.getValueMonitor(MONITOR_ID);
mon.reset();
}
});
MONITORED_VALUES.addIfMissingStatMonitor(monitor);
// Start a task to count up
new TimeoutTask(new FixedRateTrigger(0, period), new TimeoutClient() {
@Override
public void scheduleTimeout(long fireTime) {
IntegerMonitor mon = (IntegerMonitor) MONITORED_VALUES.getValueMonitor(MONITOR_ID);
mon.addValue(1);
}
@Override
public String getThreadName() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getTaskId() {
// TODO Auto-generated method stub
return null;
}
@Override
public int getQueueSize() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void rejected(RejectedTaskReason reason) {
// TODO Auto-generated method stub
}
}, timer);
// Start a task to count down
new TimeoutTask(new FixedRateTrigger(0, period), new TimeoutClient() {
@Override
public void scheduleTimeout(long fireTime) {
IntegerMonitor mon = (IntegerMonitor) MONITORED_VALUES.getValueMonitor(MONITOR_ID);
mon.addValue(-1);
}
@Override
public String getThreadName() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getTaskId() {
// TODO Auto-generated method stub
return null;
}
@Override
public int getQueueSize() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void rejected(RejectedTaskReason reason) {
// TODO Auto-generated method stub
}
}, timer);
// Start a task to read
new TimeoutTask(new FixedRateTrigger(0, period), new TimeoutClient() {
@Override
public void scheduleTimeout(long fireTime) {
IntegerMonitor mon = (IntegerMonitor) MONITORED_VALUES.getValueMonitor(MONITOR_ID);
mon.getValue();
}
@Override
public String getThreadName() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getTaskId() {
// TODO Auto-generated method stub
return null;
}
@Override
public int getQueueSize() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void rejected(RejectedTaskReason reason) {
// TODO Auto-generated method stub
}
}, timer);
// Start a task to reset
new TimeoutTask(new FixedRateTrigger(0, period), new TimeoutClient() {
@Override
public void scheduleTimeout(long fireTime) {
IntegerMonitor mon = (IntegerMonitor) MONITORED_VALUES.getValueMonitor(MONITOR_ID);
mon.reset();
}
@Override
public String getThreadName() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getTaskId() {
// TODO Auto-generated method stub
return null;
}
@Override
public int getQueueSize() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void rejected(RejectedTaskReason reason) {
// TODO Auto-generated method stub
}
}, timer);
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Aggregations