Examples of Calculable


Examples of org.rioproject.watch.Calculable

    /**
     * @see CounterWatchMBean#setCounter(long)
     */
    public void setCounter(long counter, String detail) {
        Calculable calculable = new Calculable(id, (double)counter, System.currentTimeMillis());
        calculable.setDetail(detail);
        addWatchRecord(calculable);
    }
View Full Code Here

Examples of org.rioproject.watch.Calculable

                lnrs.add(lnr);
                logs.add(log);
                watch.addThresholdListener(lnr);
                count++;
            }
            watch.addWatchRecord(new Calculable(id, 0.5));
            checkLogs(logs, "");
            watch.addWatchRecord(new Calculable(id, -0.1));
            checkLogs(logs, "breach(" + id + ",-0.1,0.0,1.0)");
            watch.addWatchRecord(new Calculable(id, 1.1));
            checkLogs(logs, "clear(" + id + ",1.1,0.0,1.0)"
                            + "breach(" + id + ",1.1,0.0,1.0)");
            watch.addWatchRecord(new Calculable(id, 0.5));
            checkLogs(logs, "clear(" + id + ",0.5,0.0,1.0)");
        }

        // Test adding the same listeners (should not change anything)
        for (LoggingThresholdListener lnr : lnrs) {
            watch.addThresholdListener(lnr);
        }
        watch.addWatchRecord(new Calculable(id, -0.1));
        checkLogs(logs, "breach(" + id + ",-0.1,0.0,1.0)");
        watch.addWatchRecord(new Calculable(id, 1.1));
        checkLogs(logs, "clear(" + id + ",1.1,0.0,1.0)"
                        + "breach(" + id + ",1.1,0.0,1.0)");
        watch.addWatchRecord(new Calculable(id, 0.5));
        checkLogs(logs, "clear(" + id + ",0.5,0.0,1.0)");

        // Test removing listeners
        count = 0;
        for (int checkpoint : checkpoints) {
            while (count < checkpoint) {
                LoggingThresholdListener lnr = lnrs.get(count);
                watch.removeThresholdListener(lnr);
                count++;
            }
            List<StringBuffer> removedLogs = logs.subList(0, count);
            List<StringBuffer> remainingLogs = logs.subList(count, logs.size());
            watch.addWatchRecord(new Calculable(id, 0.5));
            checkLogs(removedLogs, "");
            checkLogs(remainingLogs, "");
            watch.addWatchRecord(new Calculable(id, -0.1));
            checkLogs(removedLogs, "");
            checkLogs(remainingLogs, "breach(" + id + ",-0.1,0.0,1.0)");
            watch.addWatchRecord(new Calculable(id, 1.1));
            checkLogs(removedLogs, "");
            checkLogs(remainingLogs, "clear(" + id + ",1.1,0.0,1.0)"
                                     + "breach(" + id + ",1.1,0.0,1.0)");
            watch.addWatchRecord(new Calculable(id, 0.5));
            checkLogs(removedLogs, "");
            checkLogs(remainingLogs, "clear(" + id + ",0.5,0.0,1.0)");
        }

        // Test removing the same listeners (should not change anything)
        for (LoggingThresholdListener lnr : lnrs) {
            watch.removeThresholdListener(lnr);
        }
        watch.addWatchRecord(new Calculable(id, -0.1));
        checkLogs(logs, "");
        watch.addWatchRecord(new Calculable(id, 1.1));
        checkLogs(logs, "");
        watch.addWatchRecord(new Calculable(id, 0.5));
        checkLogs(logs, "");

        // Test adding 1, 10, and 100 listeners again
        count = 0;
        for (int checkpoint : checkpoints) {
            while (count < checkpoint) {
                LoggingThresholdListener lnr = lnrs.get(count);
                watch.addThresholdListener(lnr);
                count++;
            }
            List<StringBuffer> addedLogs = logs.subList(0, count);
            List<StringBuffer> remainingLogs = logs.subList(count, logs.size());
            watch.addWatchRecord(new Calculable(id, 0.5));
            checkLogs(addedLogs, "");
            checkLogs(remainingLogs, "");
            watch.addWatchRecord(new Calculable(id, -0.1));
            checkLogs(addedLogs, "breach(" + id + ",-0.1,0.0,1.0)");
            checkLogs(remainingLogs, "");
            watch.addWatchRecord(new Calculable(id, 1.1));
            checkLogs(addedLogs, "clear(" + id + ",1.1,0.0,1.0)"
                                 + "breach(" + id + ",1.1,0.0,1.0)");
            checkLogs(remainingLogs, "");
            watch.addWatchRecord(new Calculable(id, 0.5));
            checkLogs(addedLogs, "clear(" + id + ",0.5,0.0,1.0)");
            checkLogs(remainingLogs, "");
        }

        // Test adding illegal listener
View Full Code Here

Examples of org.rioproject.watch.Calculable

        String id = "watch";
        ThresholdWatch watch = (ThresholdWatch) construct1(id);
        watch.setThresholdValues(new ThresholdValues(0, 1));
        StringBuffer log = new StringBuffer();
        LoggingThresholdListener lnr = new LoggingThresholdListener(id, log);
        watch.addWatchRecord(new Calculable(id, 0.5));
        watch.addWatchRecord(new Calculable(id, -0.1));
        watch.addWatchRecord(new Calculable(id, 1.1));
        watch.addThresholdListener(lnr);
        Assert.assertEquals("", log.toString());
        watch.addWatchRecord(new Calculable(id, 0.5));
        Assert.assertEquals("clear(" + id + ",0.5,0.0,1.0)", log.toString());
        Utils.close(watch.getWatchDataSource());
    }
View Full Code Here

Examples of org.rioproject.watch.Calculable

        watch.setThresholdValues(thValues);
        String suffix = "," + thValues.getLowThreshold()
                        + "," + thValues.getHighThreshold() + ")";

        // The idea is to test the most important situations
        watch.addWatchRecord(new Calculable(id, 0));                // 0
        checkLog(log, "");
        watch.addWatchRecord(new Calculable(id, -1));               // -1
        checkLog(log, "");
        watch.addWatchRecord(new Calculable(id, -1.1));             // -1.1
        checkLog(log, lower ? "breach(w,-1.1" + suffix : "");
        watch.addWatchRecord(new Calculable(id, -1));               // -1
        checkLog(log, "");
        watch.addWatchRecord(new Calculable(id, 0));                // 0
        checkLog(log, lower ? "clear(w,0.0" + suffix : "");
        watch.addWatchRecord(new Calculable(id, -1.1));             // -1.1
        checkLog(log, lower ? "breach(w,-1.1" + suffix : "");
        watch.addWatchRecord(new Calculable(id, 1.1));              // 1.1
        if (lower & upper) {
            checkLog(log, "clear(w,1.1" + suffix
                          + "breach(w,1.1" + suffix);
        } else if (lower) {
            checkLog(log, "clear(w,1.1" + suffix);
        } else if (upper) {
            checkLog(log, "breach(w,1.1" + suffix);
        } else {
            checkLog(log, "");
        }
        watch.addWatchRecord(new Calculable(id, 0));                // 0
        checkLog(log, upper ? "clear(w,0.0" + suffix : "");

        // The other way around
        watch.addWatchRecord(new Calculable(id, 1));                // 1
        checkLog(log, "");
        watch.addWatchRecord(new Calculable(id, 1.1));              // 1.1
        checkLog(log, upper ? "breach(w,1.1" + suffix : "");
        watch.addWatchRecord(new Calculable(id, 1));                // 1
        checkLog(log, "");
        watch.addWatchRecord(new Calculable(id, 0));                // 0
        checkLog(log, upper ? "clear(w,0.0" + suffix : "");
        watch.addWatchRecord(new Calculable(id, 1.1));              // 1.1
        checkLog(log, upper ? "breach(w,1.1" + suffix : "");
        watch.addWatchRecord(new Calculable(id, -1.1));             // -1.1
        if (lower & upper) {
            checkLog(log, "clear(w,-1.1" + suffix
                          + "breach(w,-1.1" + suffix);
        } else if (upper) {
            checkLog(log, "clear(w,-1.1" + suffix);
        } else if (lower) {
            checkLog(log, "breach(w,-1.1" + suffix);
        } else {
            checkLog(log, "");
        }
        watch.addWatchRecord(new Calculable(id, 0));                // 0
        checkLog(log, lower ? "clear(w,0.0" + suffix : "");

        Utils.close(watch.getWatchDataSource());
    }
View Full Code Here

Examples of org.rioproject.watch.Calculable

        thresholdManager.setThresholdValues(thresholdValues);
        MyThresholdListener listener = new MyThresholdListener();
        thresholdManager.addThresholdListener(listener);

        List<Calculable> calculables = new LinkedList<Calculable>();
        calculables.add(new Calculable("foo", 30.1));
        calculables.add(new Calculable("foo", 32.1));
        calculables.add(new Calculable("foo", 19.6)); // breached
        calculables.add(new Calculable("foo", 1.3))// breached
        calculables.add(new Calculable("foo", 18.3)); // breached
        calculables.add(new Calculable("foo", 28.6)); // breached
        calculables.add(new Calculable("foo", 58.7)); // cleared && breached
        calculables.add(new Calculable("foo", 20.7)); // cleared && breached
        /*
         * With a step of 2, the low threshold notifications will begin at 29. So:
         * 1st notify at 29, next at 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1
         */

 
View Full Code Here

Examples of org.rioproject.watch.Calculable

        thresholdManager.setThresholdValues(thresholdValues);
        MyThresholdListener listener = new MyThresholdListener();
        thresholdManager.addThresholdListener(listener);

        List<Calculable> calculables = new LinkedList<Calculable>();
        calculables.add(new Calculable("foo", .301));
        calculables.add(new Calculable("foo", .321));
        calculables.add(new Calculable("foo", .196)); // breached
        calculables.add(new Calculable("foo", .03))// breached
        calculables.add(new Calculable("foo", .183)); // breached
        calculables.add(new Calculable("foo", .286)); // breached
        calculables.add(new Calculable("foo", .587)); // cleared && breached
        calculables.add(new Calculable("foo", .207)); // cleared && breached
        /*
         * With a step of 2, the low threshold notifications will begin at 29. So:
         * 1st notify at 29, next at 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1
         */
        for(Calculable calculable : calculables) {
View Full Code Here

Examples of org.rioproject.watch.Calculable

        }
    }
    private List<Calculable> makeCalculables(int num) {
        List<Calculable> calcs = new ArrayList<Calculable>();
        for(int i=0; i<num; i++) {
            calcs.add(new Calculable("foo", i, System.currentTimeMillis()));
        }
        return calcs;
    }
View Full Code Here

Examples of org.rioproject.watch.Calculable

         *   thresholdValues:   valid object, null
         *   type:              BREACHED, CLEARED, 0, 12345
         */

        final Object[] sources = new Object[] { new Object(), null};
        final Calculable[] calculables = new Calculable[] {new Calculable(), null};
        final ThresholdValues[] tvs = new ThresholdValues[] { new ThresholdValues(), null};
        final ThresholdType[] types = new ThresholdType[] {
                ThresholdType.BREACHED, ThresholdType.CLEARED};

        Object[][] combinations = ArrayUtils.combinations(new Object[][] {
                sources, calculables, tvs, types});
        for (Object[] combination : combinations) {
            Object source = combination[0];
            Calculable calculable = (Calculable) combination[1];
            ThresholdValues tv = (ThresholdValues) combination[2];
            ThresholdType type = (ThresholdType) combination[3];

            if (source == null) {
                try {
View Full Code Here

Examples of org.rioproject.watch.Calculable

         */

        ThresholdEvent event = new ThresholdEvent(new Object());
        Assert.assertSame(null, event.getCalculable());

        Calculable c = new Calculable();
        event.setCalculable(c);
        Assert.assertSame(c, event.getCalculable());
    }
View Full Code Here

Examples of org.rioproject.watch.Calculable

         *   calculable: valid alculable, null
         */

        ThresholdEvent event = new ThresholdEvent(new Object());

        Calculable c = new Calculable();
        event.setCalculable(c);
        Assert.assertSame(c, event.getCalculable());

        event.setCalculable(null);
        Assert.assertSame(null, event.getCalculable());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.