コード例 #1
0
 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);
   }
 }
コード例 #2
0
    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);
      }
    }
コード例 #3
0
 public void register(ConsoleRequest consoleRequest) {
   consoleRequests[consoleRequest.getType()] = consoleRequest;
 }