コード例 #1
0
 private Address findMasterWithMulticast() {
   try {
     final String ip = System.getProperty("join.ip");
     if (ip == null) {
       JoinInfo joinInfo = node.createJoinInfo();
       for (; node.isActive() && currentTryCount.incrementAndGet() <= maxTryCount.get(); ) {
         joinInfo.setTryCount(currentTryCount.get());
         node.multicastService.send(joinInfo);
         if (node.getMasterAddress() == null) {
           //noinspection BusyWait
           Thread.sleep(10);
         } else {
           return node.getMasterAddress();
         }
       }
     } else {
       logger.log(Level.FINEST, "RETURNING join.ip");
       return new Address(ip, config.getNetworkConfig().getPort());
     }
   } catch (final Exception e) {
     if (logger != null) {
       logger.log(Level.WARNING, e.getMessage(), e);
     }
   } finally {
     this.currentTryCount.set(0);
   }
   return null;
 }
コード例 #2
0
 public void onReceivedJoinInfo(JoinInfo joinInfo) {
   if (joinInfo.getTryCount() > this.currentTryCount.get() + 20) {
     int timeoutSeconds =
         (config.getNetworkConfig().getJoin().getMulticastConfig().getMulticastTimeoutSeconds()
                 + 4)
             * 100;
     this.maxTryCount.set(timeoutSeconds);
   }
 }
コード例 #3
0
 public void searchForOtherClusters(SplitBrainHandler splitBrainHandler) {
   final BlockingQueue q = new LinkedBlockingQueue();
   MulticastListener listener =
       new MulticastListener() {
         public void onMessage(Object msg) {
           systemLogService.logJoin("MulticastListener onMessage " + msg);
           if (msg != null && msg instanceof JoinInfo) {
             JoinInfo joinInfo = (JoinInfo) msg;
             if (node.address != null && !node.address.equals(joinInfo.address)) {
               q.offer(msg);
             }
           }
         }
       };
   node.multicastService.addMulticastListener(listener);
   node.multicastService.send(node.createJoinInfo());
   systemLogService.logJoin("Sent multicast join request");
   try {
     JoinInfo joinInfo = (JoinInfo) q.poll(3, TimeUnit.SECONDS);
     if (joinInfo != null) {
       if (joinInfo.getMemberCount() == 1) {
         // if the other cluster has just single member, that may be a newly starting node
         // instead of a split node.
         // Wait 2 times 'WAIT_SECONDS_BEFORE_JOIN' seconds before processing merge JoinInfo.
         Thread.sleep(node.groupProperties.WAIT_SECONDS_BEFORE_JOIN.getInteger() * 1000L * 2);
       }
       if (shouldMerge(joinInfo)) {
         logger.log(
             Level.WARNING, node.address + " is merging [multicast] to " + joinInfo.address);
         targetAddress = joinInfo.address;
         node.clusterManager.sendClusterMergeToOthers(targetAddress);
         splitBrainHandler.restart();
         return;
       }
     }
   } catch (InterruptedException ignored) {
   } catch (Exception e) {
     if (logger != null) {
       logger.log(Level.WARNING, e.getMessage(), e);
     }
   } finally {
     node.multicastService.removeMulticastListener(listener);
   }
 }