Package org.apache.cloudstack.framework.messagebus

Examples of org.apache.cloudstack.framework.messagebus.MessageDetector


    }

    @Override
    public boolean waitAndCheck(AsyncJob job, String[] wakeupTopicsOnMessageBus, long checkIntervalInMilliSeconds, long timeoutInMiliseconds, Predicate predicate) {

        MessageDetector msgDetector = new MessageDetector();
        String[] topics = Arrays.copyOf(wakeupTopicsOnMessageBus, wakeupTopicsOnMessageBus.length + 1);
        topics[topics.length - 1] = AsyncJob.Topics.JOB_STATE;

        msgDetector.open(_messageBus, topics);
        try {
            long startTick = System.currentTimeMillis();
            while (timeoutInMiliseconds < 0 || System.currentTimeMillis() - startTick < timeoutInMiliseconds) {
                msgDetector.waitAny(checkIntervalInMilliSeconds);
                job = _jobDao.findById(job.getId());
                if (job.getStatus().done()) {
                    return true;
                }

                if (predicate.checkCondition()) {
                    return true;
                }
            }
        } finally {
            msgDetector.close();
        }

        return false;
    }
View Full Code Here


        _messageBus.clearAll();
    }

    public void testMessageDetector() {
        MessageDetector detector = new MessageDetector();
        detector.open(_messageBus, new String[] {"VM", "Host"});

        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 2; i++) {
                    try {
                        Thread.sleep(3000);
                    } catch (InterruptedException e) {
                    }
                    _messageBus.publish(null, "Host", PublishScope.GLOBAL, null);
                }
            }
        });
        thread.start();

        try {
            int count = 0;
            while (count < 2) {
                detector.waitAny(1000);
            }
        } finally {
            detector.close();
        }

        try {
            thread.join();
        } catch (InterruptedException e) {
View Full Code Here

    }

    @Override
    public boolean waitAndCheck(AsyncJob job, String[] wakeupTopicsOnMessageBus, long checkIntervalInMilliSeconds, long timeoutInMiliseconds, Predicate predicate) {

        MessageDetector msgDetector = new MessageDetector();
        String[] topics = Arrays.copyOf(wakeupTopicsOnMessageBus, wakeupTopicsOnMessageBus.length + 1);
        topics[topics.length - 1] = AsyncJob.Topics.JOB_STATE;

        msgDetector.open(_messageBus, topics);
        try {
            long startTick = System.currentTimeMillis();
            while (timeoutInMiliseconds < 0 || System.currentTimeMillis() - startTick < timeoutInMiliseconds) {
                msgDetector.waitAny(checkIntervalInMilliSeconds);
                job = _jobDao.findById(job.getId());
                if (job.getStatus().done()) {
                    return true;
                }

                if (predicate.checkCondition()) {
                    return true;
                }
            }
        } finally {
            msgDetector.close();
        }

        return false;
    }
View Full Code Here

   
    _messageBus.clearAll();
  }
 
  public void testMessageDetector() {
    MessageDetector detector = new MessageDetector();
    detector.open(_messageBus, new String[] {"VM", "Host"});
   
    Thread thread = new Thread(new Runnable() {
      @Override
      public void run() {
        for(int i = 0; i < 2; i++) {
          try {
            Thread.sleep(3000);
          } catch (InterruptedException e) {
          }
          _messageBus.publish(null, "Host", PublishScope.GLOBAL, null);
        }
      }
    });
    thread.start();
   
    try {
      int count = 0;
      while(count < 2) {
        if(detector.waitAny(1000)) {
          System.out.println("Detected signal on bus");
          count++;
        } else {
          System.out.println("Waiting timed out");
        }
      }
    } finally {
      detector.close();
    }
   
    try {
      thread.join();
    } catch (InterruptedException e) {
View Full Code Here

TOP

Related Classes of org.apache.cloudstack.framework.messagebus.MessageDetector

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.