Package org.rioproject.watch

Examples of org.rioproject.watch.Calculable


        }

        public void notify(RemoteServiceEvent event) {
            SLAThresholdEvent slaEvent = (SLAThresholdEvent)event;
            SLA sla = slaEvent.getSLA();
            Calculable c = slaEvent.getCalculable();
            String type = slaEvent.getThresholdType().name();
            System.out.println(type+" current: "+c.getValue()+", low: " + sla.getLowThreshold() + ", high: " + sla.getHighThreshold());
            if(slaEvent.getThresholdType()== ThresholdType.BREACHED) {
                if(c.getValue()>sla.getHighThreshold())
                    upperBreachNotification = true;
                if(c.getValue()<sla.getLowThreshold())
                    lowerBreachNotification = true;
            }
        }
View Full Code Here


     * @see WatchMBean#getLastCalculableValue
     */
    public double getLastCalculableValue() {
        double value = 0;
        try {
            Calculable lastCalculable;
            if(localRef != null)
                lastCalculable = localRef.getLastCalculable();
            else
                lastCalculable = watchDataSource.getLastCalculable();
            if(lastCalculable != null) {
                value = lastCalculable.getValue();
            }
        } catch(Exception e) {
            logger.warn("Getting last calculable", e);
        }
        return(value);
View Full Code Here

    public void setElapsedTime(long elapsed, long now) {
        addWatchRecord(new StopWatchCalculable(id, elapsed, now));
    }

    public void setElapsedTime(long elapsed, long now, String detail) {
        Calculable calculable = new StopWatchCalculable(id, elapsed, now);
        calculable.setDetail(detail);
        addWatchRecord(calculable);
    }
View Full Code Here

        // Go through the checkpoints
        for (int checkpoint : checkpoints) {

            // Generate samples to reach the checkpoint
            while (added.size() < checkpoint) {
                Calculable c = new Calculable(watch.getId(), Math.random(),
                                              added.size());
                if (tryNulls && added.size() % 10 == 3) {
                    c = null;
                }
                added.add(c);
View Full Code Here

    /**
     * @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

                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

        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

        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

        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

        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

TOP

Related Classes of org.rioproject.watch.Calculable

Copyright © 2018 www.massapicom. 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.