Search in sources :

Example 1 with LongLongPair

use of com.serotonin.db.pair.LongLongPair in project ma-core-public by infiniteautomation.

the class DataSourceDwr method getPollTimes.

/**
 * Get the latest poll times and thier durations
 * @param id
 * @return
 */
@DwrPermission(user = true)
public ProcessResult getPollTimes(int id) {
    ProcessResult result = new ProcessResult();
    DataSourceRT ds = Common.runtimeManager.getRunningDataSource(id);
    List<StringStringPair> polls = new ArrayList<StringStringPair>();
    if ((ds != null) && (ds instanceof PollingDataSource)) {
        List<LongLongPair> list = ((PollingDataSource) ds).getLatestPollTimes();
        String pollTime;
        for (LongLongPair poll : list) {
            StringBuilder duration = new StringBuilder();
            pollTime = Functions.getFullMilliSecondTime(poll.getKey());
            if (poll.getValue() >= 0) {
                // Format Duration Nicely
                Period period = new Period(poll.getValue());
                if (period.getHours() >= 1) {
                    duration.append(translate("common.duration.hours", period.getHours()));
                    duration.append(SPACE);
                }
                if (period.getMinutes() >= 1) {
                    duration.append(translate("common.duration.minutes", period.getMinutes()));
                    duration.append(SPACE);
                }
                if (period.getSeconds() >= 1) {
                    duration.append(translate("common.duration.seconds", period.getSeconds()));
                    duration.append(SPACE);
                }
                duration.append(translate("common.duration.millis", period.getMillis()));
            } else {
                duration.append(translate("event.ds.pollAborted"));
            }
            StringStringPair pair = new StringStringPair(pollTime, duration.toString());
            polls.add(pair);
        }
    }
    List<String> aborts = new ArrayList<String>();
    if ((ds != null) && (ds instanceof PollingDataSource)) {
        List<Long> list = ((PollingDataSource) ds).getLatestAbortedPollTimes();
        String pollTime;
        for (Long poll : list) {
            pollTime = Functions.getFullMilliSecondTime(poll);
            aborts.add(pollTime);
        }
    }
    result.addData("polls", polls);
    result.addData("aborts", aborts);
    return result;
}
Also used : StringStringPair(com.serotonin.db.pair.StringStringPair) LongLongPair(com.serotonin.db.pair.LongLongPair) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) Period(org.joda.time.Period) DataSourceRT(com.serotonin.m2m2.rt.dataSource.DataSourceRT) PollingDataSource(com.serotonin.m2m2.rt.dataSource.PollingDataSource) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 2 with LongLongPair

use of com.serotonin.db.pair.LongLongPair in project ma-core-public by infiniteautomation.

the class PollingDataSource method scheduleTimeoutImpl.

public synchronized void scheduleTimeoutImpl(long fireTime) {
    try {
        jobThread = Thread.currentThread();
        long startTs = Common.timer.currentTimeMillis();
        // backing up
        if ((cronPattern == null) && ((startTs - fireTime) > pollingPeriodMillis)) {
            incrementUnsuccessfulPolls(fireTime);
            return;
        }
        incrementSuccessfulPolls(fireTime);
        // Check if there were changes to the data points list.
        updateChangedPoints(fireTime);
        doPollNoSync(fireTime);
        // Save the poll time and duration
        long pollDuration = Common.timer.currentTimeMillis() - startTs;
        this.latestPollTimes.add(new LongLongPair(fireTime, pollDuration));
        this.lastPollDurationMonitor.setValue(pollDuration);
        // Trim the Queue
        while (this.latestPollTimes.size() > 10) this.latestPollTimes.poll();
    } finally {
        if (terminationLock != null) {
            synchronized (terminationLock) {
                terminationLock.notifyAll();
            }
        }
        updateSuccessfulPollQuotient();
        jobThread = null;
    }
}
Also used : LongLongPair(com.serotonin.db.pair.LongLongPair)

Aggregations

LongLongPair (com.serotonin.db.pair.LongLongPair)2 StringStringPair (com.serotonin.db.pair.StringStringPair)1 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1 DataSourceRT (com.serotonin.m2m2.rt.dataSource.DataSourceRT)1 PollingDataSource (com.serotonin.m2m2.rt.dataSource.PollingDataSource)1 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)1 ArrayList (java.util.ArrayList)1 Period (org.joda.time.Period)1