public void run() {
   if (webServerUrl == null) {
     logger.log(Level.WARNING, "Web server url is null!");
     return;
   }
   try {
     while (running.get()) {
       try {
         URL url = new URL(webServerUrl + "collector.do");
         HttpURLConnection connection = (HttpURLConnection) url.openConnection();
         connection.setDoOutput(true);
         connection.setRequestMethod("POST");
         connection.setConnectTimeout(1000);
         connection.setReadTimeout(1000);
         final DataOutputStream out = new DataOutputStream(connection.getOutputStream());
         TimedMemberState ts = getTimedMemberState();
         ts.writeData(out);
         out.flush();
         connection.getInputStream();
       } catch (Exception e) {
         logger.log(Level.FINEST, e.getMessage(), e);
       }
       Thread.sleep(updateIntervalMs);
     }
   } catch (Throwable throwable) {
     logger.log(
         Level.FINEST, "Web Management Center will be closed due to exception.", throwable);
     shutdown();
   }
 }
 @Override
 public void doLocalOp() {
   Boolean result;
   try {
     result = arp.call();
     setResult(result);
   } catch (Exception e) {
     logger.log(Level.FINEST, e.getMessage(), e);
   }
 }
 public void sendResponse(int taskId, ConsoleRequest request) {
   try {
     URL url = new URL(webServerUrl + "putResponse.do");
     HttpURLConnection connection = (HttpURLConnection) url.openConnection();
     connection.setDoOutput(true);
     connection.setRequestMethod("POST");
     connection.setConnectTimeout(2000);
     connection.setReadTimeout(2000);
     OutputStream outputStream = connection.getOutputStream();
     DataOutputStream output = new DataOutputStream(outputStream);
     output.writeInt(taskId);
     output.writeInt(request.getType());
     request.writeResponse(ManagementCenterService.this, output);
     connection.getInputStream();
   } catch (Exception e) {
     logger.log(Level.FINEST, e.getMessage(), e);
   }
 }
    public void run() {
      if (webServerUrl == null) {
        logger.log(Level.WARNING, "Web server url is null!");
        return;
      }
      try {
        Random rand = new Random();
        Address address =
            ((MemberImpl) factory.node.getClusterImpl().getLocalMember()).getAddress();
        GroupConfig groupConfig = factory.getConfig().getGroupConfig();
        while (running.get()) {
          try {
            URL url =
                new URL(
                    webServerUrl
                        + "getTask.do?member="
                        + address.getHost()
                        + ":"
                        + address.getPort()
                        + "&cluster="
                        + groupConfig.getName());
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestProperty("Connection", "keep-alive");
            InputStream inputStream = connection.getInputStream();
            DataInputStream input = new DataInputStream(inputStream);

            int taskId = input.readInt();
            if (taskId > 0) {
              int requestType = input.readInt();
              ConsoleRequest request = consoleRequests[requestType];
              request.readData(input);
              sendResponse(taskId, request);
            }
          } catch (Exception e) {
            logger.log(Level.FINEST, e.getMessage(), e);
          }
          Thread.sleep(700 + rand.nextInt(300));
        }
      } catch (Throwable throwable) {
        logger.log(Level.FINEST, "Problem on management center while polling task.", throwable);
      }
    }
 public final void heartBeater() {
   if (!node.joined() || !node.isActive()) return;
   long now = Clock.currentTimeMillis();
   if (isMaster()) {
     List<Address> lsDeadAddresses = null;
     for (MemberImpl memberImpl : lsMembers) {
       final Address address = memberImpl.getAddress();
       if (!thisAddress.equals(address)) {
         try {
           Connection conn = node.connectionManager.getOrConnect(address);
           if (conn != null && conn.live()) {
             if ((now - memberImpl.getLastRead()) >= (MAX_NO_HEARTBEAT_MILLIS)) {
               conn = null;
               if (lsDeadAddresses == null) {
                 lsDeadAddresses = new ArrayList<Address>();
               }
               logger.log(
                   Level.WARNING,
                   "Added "
                       + address
                       + " to list of dead addresses because of timeout since last read");
               lsDeadAddresses.add(address);
             } else if ((now - memberImpl.getLastRead()) >= 5000
                 && (now - memberImpl.getLastPing()) >= 5000) {
               ping(memberImpl);
             }
             if ((now - memberImpl.getLastWrite()) > 500) {
               sendHeartbeat(conn);
             }
             Long lastConfirmation = memberMasterConfirmationTimes.get(memberImpl);
             if (lastConfirmation == null
                 || (now - lastConfirmation > MAX_NO_MASTER_CONFIRMATION_MILLIS)) {
               if (lsDeadAddresses == null) {
                 lsDeadAddresses = new ArrayList<Address>();
               }
               logger.log(
                   Level.WARNING,
                   "Added "
                       + address
                       + " to list of dead addresses because it has not sent a master confirmation recently");
               lsDeadAddresses.add(address);
             }
           } else if (conn == null && (now - memberImpl.getLastRead()) > 5000) {
             logMissingConnection(address);
             memberImpl.didRead();
           }
         } catch (Exception e) {
           logger.log(Level.SEVERE, e.getMessage(), e);
         }
       }
     }
     if (lsDeadAddresses != null) {
       for (Address address : lsDeadAddresses) {
         logger.log(Level.FINEST, "No heartbeat should remove " + address);
         doRemoveAddress(address);
       }
     }
   } else {
     // send heartbeat to master
     Address masterAddress = getMasterAddress();
     if (masterAddress != null) {
       final Connection connMaster = node.connectionManager.getOrConnect(masterAddress);
       MemberImpl masterMember = getMember(masterAddress);
       boolean removed = false;
       if (masterMember != null) {
         if ((now - masterMember.getLastRead()) >= (MAX_NO_HEARTBEAT_MILLIS)) {
           logger.log(
               Level.WARNING, "Master node has timed out its heartbeat and will be removed");
           doRemoveAddress(masterAddress);
           removed = true;
         } else if ((now - masterMember.getLastRead()) >= 5000
             && (now - masterMember.getLastPing()) >= 5000) {
           ping(masterMember);
         }
       }
       if (!removed) {
         sendHeartbeat(connMaster);
       }
     }
     for (MemberImpl member : lsMembers) {
       if (!member.localMember()) {
         Address address = member.getAddress();
         Connection conn = node.connectionManager.getOrConnect(address);
         if (conn != null) {
           sendHeartbeat(conn);
         } else {
           logger.log(Level.FINEST, "Could not connect to " + address + " to send heartbeat");
         }
       }
     }
   }
 }