Search in sources :

Example 1 with StatusUpdateException

use of com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResource.StatusUpdateException in project ma-modules-public by infiniteautomation.

the class MangoTaskTemporaryResourceManager method scheduleTimeout.

private void scheduleTimeout(TemporaryResource<T, AbstractRestException> 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) {
            try {
                resource.timeOut();
            } catch (StatusUpdateException e) {
                if (log.isDebugEnabled()) {
                    log.debug("Tried to time out resource but it was already complete", e);
                }
            }
        }

        @Override
        public String getThreadName() {
            return "Temporary resource timeout " + resource.getResourceType() + " " + resource.getId();
        }

        @Override
        public void rejected(RejectedTaskReason reason) {
            super.rejected(reason);
            try {
                resource.timeOut();
            } catch (StatusUpdateException e) {
                if (log.isDebugEnabled()) {
                    log.debug("Tried to time out resource but it was already complete", e);
                }
            }
        }
    });
}
Also used : StatusUpdateException(com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResource.StatusUpdateException) TimeoutClient(com.serotonin.m2m2.util.timeout.TimeoutClient) Date(java.util.Date) RejectedTaskReason(com.serotonin.timer.RejectedTaskReason) TimeoutTask(com.serotonin.m2m2.util.timeout.TimeoutTask)

Example 2 with StatusUpdateException

use of com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResource.StatusUpdateException in project ma-modules-public by infiniteautomation.

the class MangoTaskTemporaryResourceManager method scheduleRemoval.

private void scheduleRemoval(TemporaryResource<T, AbstractRestException> 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) {
            try {
                resource.remove();
            } catch (StatusUpdateException e) {
                if (log.isDebugEnabled()) {
                    log.debug("Tried to remove resource but it was already complete", e);
                }
            }
        }

        @Override
        public String getThreadName() {
            return "Temporary resource expiration " + resource.getResourceType() + " " + resource.getId();
        }

        @Override
        public void rejected(RejectedTaskReason reason) {
            super.rejected(reason);
            try {
                resource.remove();
            } catch (StatusUpdateException e) {
                if (log.isDebugEnabled()) {
                    log.debug("Tried to remove resource but it was already complete", e);
                }
            }
        }
    });
}
Also used : StatusUpdateException(com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResource.StatusUpdateException) TimeoutClient(com.serotonin.m2m2.util.timeout.TimeoutClient) Date(java.util.Date) RejectedTaskReason(com.serotonin.timer.RejectedTaskReason) TimeoutTask(com.serotonin.m2m2.util.timeout.TimeoutTask)

Aggregations

StatusUpdateException (com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResource.StatusUpdateException)2 TimeoutClient (com.serotonin.m2m2.util.timeout.TimeoutClient)2 TimeoutTask (com.serotonin.m2m2.util.timeout.TimeoutTask)2 RejectedTaskReason (com.serotonin.timer.RejectedTaskReason)2 Date (java.util.Date)2