Package org.quickserver.net.client

Examples of org.quickserver.net.client.Host


 
 
  public static void monitor() {
    HostMonitoringService hms = null;
    List fullList = null;
    Host host = null;
    char newStatus = 'U';
    try {
      List list = new ArrayList(listToMonitor);
      Iterator iterator = list.iterator();             
     
      while(iterator.hasNext()) {
        hms = (HostMonitoringService) iterator.next();
       
        Date now = new Date();     
        if(hms.getNextCheckOn()!=null && hms.getNextCheckOn().after(now)) {
          continue;
        }
       
        fullList = hms.getHostList().getFullList();
        List activeList = new ArrayList();
       
        Iterator hostIterator = fullList.iterator();
       
        hms.setLastCheckedOn(now);
        long nextTime = hms.getLastCheckedOn().getTime() +
            (hms.getIntervalInSec()/2)*1000;
        hms.setNextCheckOn(new Date(nextTime));
             
        while(hostIterator.hasNext()) {
          host = (Host) hostIterator.next();         
         
          if(host.getNextCheckOn()==null || host.getNextCheckOn().before(now)) {
            char oldStatus = host.getStatus();
            if(host.getStatus()!=Host.MAINTENANCE) {
              try {
                newStatus = hms.getHostMonitor().monitor(host);
              } catch (Exception er) {
                logger.log(Level.WARNING, "Error in HostMonitor1: "+er, er);
                er.printStackTrace();
                newStatus = Host.ERROR;
              }             
            } else {
              newStatus = host.getStatus();
            }
            host.setStatus(newStatus);
           
            if(newStatus==Host.ACTIVE) {
              activeList.add(host);
            } else if(host.getStatus()!=Host.MAINTENANCE) {
              //try again..
              try {
                newStatus = hms.getHostMonitor().monitor(host);
              } catch (Exception er) {
                logger.log(Level.WARNING, "Error in HostMonitor2: "+er, er);
                er.printStackTrace();
                newStatus = Host.ERROR;
              }
              if(newStatus==Host.ACTIVE) {
                activeList.add(host);
              }
              host.setStatus(newStatus);
            }
           
            if(newStatus != oldStatus) {
              List myListnersList = hms.getListnersList();
              if(myListnersList!=null) {
                Iterator listnersIterator = myListnersList.iterator();
                HostStateListener listener = null;
                while(listnersIterator.hasNext()) {
                  listener = (HostStateListener) listnersIterator.next();
                  if(listener!=null) {
                    listener.stateChanged(host, oldStatus, newStatus);
                  } else {
                    logger.warning("listener was null!");
                  }
                }
              } else {
                logger.warning("No listners set "+host+
                    "; old status: "+oldStatus+
                    ";new status:"+newStatus);
              }
            }
            if(host.getLastCheckedOn()!=null) {
              long newTime = host.getLastCheckedOn().getTime() +
                  hms.getIntervalInSec()*1000;
              host.setNextCheckOn(new Date(newTime));
            } else {
              logger.warning("host.getLastCheckedOn() was null "+host);
            }
           
          } else {
            //last monitored status is good for use
            if(host.getStatus()==Host.ACTIVE) {
              activeList.add(host);
            }
          }
          hms.getHostList().setActiveList(activeList);//update back
         
View Full Code Here

TOP

Related Classes of org.quickserver.net.client.Host

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.