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();
   }
 }
示例#2
0
 void connect(boolean requireSSL) {
   setConnectionState(ConnectionState.CONNECTING);
   try {
     tryConnect(requireSSL);
     setConnectionState(ConnectionState.CONNECTED);
   } catch (Exception e) {
     if (JConsole.isDebug()) {
       e.printStackTrace();
     }
     setConnectionState(ConnectionState.DISCONNECTED);
   }
 }
 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);
      }
    }