コード例 #1
0
 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
 public TimedMemberState getTimedMemberState() {
   if (running.get()) {
     final MemberStateImpl memberState = new MemberStateImpl();
     createMemberState(memberState);
     GroupConfig groupConfig = factory.getConfig().getGroupConfig();
     TimedMemberState timedMemberState = new TimedMemberState();
     timedMemberState.setMaster(factory.node.isMaster());
     if (timedMemberState.getMaster()) {
       timedMemberState.setMemberList(new ArrayList<String>());
       Set<Member> memberSet = factory.getCluster().getMembers();
       for (Member member : memberSet) {
         MemberImpl memberImpl = (MemberImpl) member;
         Address address = memberImpl.getAddress();
         timedMemberState.getMemberList().add(address.getHost() + ":" + address.getPort());
       }
     }
     timedMemberState.setMemberState(memberState);
     timedMemberState.setClusterName(groupConfig.getName());
     timedMemberState.setInstanceNames(getLongInstanceNames());
     return timedMemberState;
   }
   return null;
 }