use of com.serotonin.m2m2.util.timeout.TimeoutClient 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();
}
}
}
use of com.serotonin.m2m2.util.timeout.TimeoutClient in project ma-core-public by infiniteautomation.
the class EmailHandlerRT method scheduleTimeout.
//
// TimeoutClient
//
public synchronized void scheduleTimeout(EventInstance evt, long fireTime) {
// Get the email addresses to send to
Set<String> addresses = MailingListDao.instance.getRecipientAddresses(vo.getEscalationRecipients(), new DateTime(fireTime));
// Send the escalation.
sendEmail(evt, NotificationType.ESCALATION, addresses);
// have not been overridden.
if (vo.isSendInactive() && !vo.isInactiveOverride())
inactiveRecipients.addAll(addresses);
if (vo.isRepeatEscalations()) {
// While evt will probably show ack'ed if ack'ed, the possibility exists for it to be deleted
// and in which case we want to notice rather than send emails forever.
EventInstance dbEvent = EventDao.instance.get(evt.getId());
if (dbEvent != null && !dbEvent.isAcknowledged() && dbEvent.isActive()) {
long delayMS = Common.getMillis(vo.getEscalationDelayType(), vo.getEscalationDelay());
escalationTask = new ModelTimeoutTask<EventInstance>(delayMS, this, dbEvent);
}
}
}
use of com.serotonin.m2m2.util.timeout.TimeoutClient in project ma-modules-public by infiniteautomation.
the class MangoTaskTemporaryResourceManager method scheduleTimeout.
private void scheduleTimeout(TemporaryResource<T, AbstractRestV2Exception> resource) {
if (resource.getTimeout() <= 0)
return;
TaskData tasks = (TaskData) resource.getData();
Date timeoutDate = new Date(resource.getStartTime().getTime() + resource.getTimeout());
// TimeoutTask schedules itself to be executed
tasks.timeoutTask = new TimeoutTask(timeoutDate, new TimeoutClient() {
@Override
public void scheduleTimeout(long fireTime) {
resource.timeOut();
}
@Override
public String getThreadName() {
return "Temporary resource timeout " + resource.getResourceType() + " " + resource.getId();
}
@Override
public void rejected(RejectedTaskReason reason) {
super.rejected(reason);
resource.timeOut();
}
});
}
use of com.serotonin.m2m2.util.timeout.TimeoutClient in project ma-modules-public by infiniteautomation.
the class MangoTaskTemporaryResourceManager method scheduleRemoval.
private void scheduleRemoval(TemporaryResource<T, AbstractRestV2Exception> resource) {
if (resource.getExpiration() <= 0) {
resource.remove();
return;
}
TaskData tasks = (TaskData) resource.getData();
Date expirationDate = new Date(resource.getCompletionTime().getTime() + resource.getExpiration());
// TimeoutTask schedules itself to be executed
tasks.expirationTask = new TimeoutTask(expirationDate, new TimeoutClient() {
@Override
public void scheduleTimeout(long fireTime) {
resource.remove();
}
@Override
public String getThreadName() {
return "Temporary resource expiration " + resource.getResourceType() + " " + resource.getId();
}
@Override
public void rejected(RejectedTaskReason reason) {
super.rejected(reason);
resource.remove();
}
});
}
Aggregations