Search in sources :

Example 1 with IntegerMonitor

use of com.infiniteautomation.mango.monitor.IntegerMonitor 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();
        }
    }
}
Also used : OrderedRealTimeTimer(com.serotonin.timer.OrderedRealTimeTimer) MangoThreadFactory(com.serotonin.m2m2.rt.maint.MangoThreadFactory) FixedRateTrigger(com.serotonin.timer.FixedRateTrigger) OrderedThreadPoolExecutor(com.serotonin.timer.OrderedThreadPoolExecutor) RejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler) OrderedRealTimeTimer(com.serotonin.timer.OrderedRealTimeTimer) RealTimeTimer(com.serotonin.timer.RealTimeTimer) ValueMonitorOwner(com.infiniteautomation.mango.monitor.ValueMonitorOwner) TimeoutTask(com.serotonin.m2m2.util.timeout.TimeoutTask) TimeoutClient(com.serotonin.m2m2.util.timeout.TimeoutClient) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) OrderedThreadPoolExecutor(com.serotonin.timer.OrderedThreadPoolExecutor) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) IntegerMonitor(com.infiniteautomation.mango.monitor.IntegerMonitor) RejectedTaskReason(com.serotonin.timer.RejectedTaskReason)

Example 2 with IntegerMonitor

use of com.infiniteautomation.mango.monitor.IntegerMonitor in project ma-modules-public by infiniteautomation.

the class InternalDataSourceRT method forcePointRead.

@Override
public void forcePointRead(DataPointRT dataPoint) {
    InternalPointLocatorRT locator = dataPoint.getPointLocator();
    ValueMonitor<?> m = Common.MONITORED_VALUES.getValueMonitor(locator.getPointLocatorVO().getMonitorId());
    if (m != null) {
        if (m instanceof IntegerMonitor)
            dataPoint.updatePointValue(new PointValueTime((double) ((IntegerMonitor) m).getValue(), Common.timer.currentTimeMillis()));
        else if (m instanceof LongMonitor)
            dataPoint.updatePointValue(new PointValueTime((double) ((LongMonitor) m).getValue(), Common.timer.currentTimeMillis()));
        else if (m instanceof DoubleMonitor)
            dataPoint.updatePointValue(new PointValueTime((double) ((DoubleMonitor) m).getValue(), Common.timer.currentTimeMillis()));
        else if (m instanceof AtomicIntegerMonitor)
            dataPoint.updatePointValue(new PointValueTime((double) ((AtomicIntegerMonitor) m).getValue(), Common.timer.currentTimeMillis()));
    }
}
Also used : PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) LongMonitor(com.infiniteautomation.mango.monitor.LongMonitor) AtomicIntegerMonitor(com.infiniteautomation.mango.monitor.AtomicIntegerMonitor) AtomicIntegerMonitor(com.infiniteautomation.mango.monitor.AtomicIntegerMonitor) IntegerMonitor(com.infiniteautomation.mango.monitor.IntegerMonitor) DoubleMonitor(com.infiniteautomation.mango.monitor.DoubleMonitor)

Example 3 with IntegerMonitor

use of com.infiniteautomation.mango.monitor.IntegerMonitor in project ma-modules-public by infiniteautomation.

the class InternalDataSourceRT method doPoll.

@Override
public void doPoll(long time) {
    if (createsPoints) {
        for (ValueMonitor<?> m : Common.MONITORED_VALUES.getMonitors()) {
            if (createPointsPattern.matcher(m.getId()).matches() && !monitorMap.containsKey(m.getId()))
                createMonitorPoint(m);
        }
    }
    for (DataPointRT dataPoint : dataPoints) {
        InternalPointLocatorRT locator = dataPoint.getPointLocator();
        ValueMonitor<?> m = Common.MONITORED_VALUES.getValueMonitor(locator.getPointLocatorVO().getMonitorId());
        if (m != null) {
            if (m instanceof IntegerMonitor)
                dataPoint.updatePointValue(new PointValueTime((double) ((IntegerMonitor) m).getValue(), time));
            else if (m instanceof LongMonitor)
                dataPoint.updatePointValue(new PointValueTime((double) ((LongMonitor) m).getValue(), time));
            else if (m instanceof DoubleMonitor)
                dataPoint.updatePointValue(new PointValueTime((double) ((DoubleMonitor) m).getValue(), time));
            else if (m instanceof AtomicIntegerMonitor)
                dataPoint.updatePointValue(new PointValueTime((double) ((AtomicIntegerMonitor) m).getValue(), time));
        }
    }
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) LongMonitor(com.infiniteautomation.mango.monitor.LongMonitor) AtomicIntegerMonitor(com.infiniteautomation.mango.monitor.AtomicIntegerMonitor) AtomicIntegerMonitor(com.infiniteautomation.mango.monitor.AtomicIntegerMonitor) IntegerMonitor(com.infiniteautomation.mango.monitor.IntegerMonitor) DoubleMonitor(com.infiniteautomation.mango.monitor.DoubleMonitor)

Aggregations

IntegerMonitor (com.infiniteautomation.mango.monitor.IntegerMonitor)3 AtomicIntegerMonitor (com.infiniteautomation.mango.monitor.AtomicIntegerMonitor)2 DoubleMonitor (com.infiniteautomation.mango.monitor.DoubleMonitor)2 LongMonitor (com.infiniteautomation.mango.monitor.LongMonitor)2 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)2 ValueMonitorOwner (com.infiniteautomation.mango.monitor.ValueMonitorOwner)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)1 MangoThreadFactory (com.serotonin.m2m2.rt.maint.MangoThreadFactory)1 TimeoutClient (com.serotonin.m2m2.util.timeout.TimeoutClient)1 TimeoutTask (com.serotonin.m2m2.util.timeout.TimeoutTask)1 FixedRateTrigger (com.serotonin.timer.FixedRateTrigger)1 OrderedRealTimeTimer (com.serotonin.timer.OrderedRealTimeTimer)1 OrderedThreadPoolExecutor (com.serotonin.timer.OrderedThreadPoolExecutor)1 RealTimeTimer (com.serotonin.timer.RealTimeTimer)1 RejectedTaskReason (com.serotonin.timer.RejectedTaskReason)1 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1