Exemplo n.º 1
0
  public void doJoin() {
    NodeEngineImpl nodeEngine = null;
    synchronized (joinerLock) {
      for (Address address : joinAddresses) {
        NodeEngineImpl ne = nodes.get(address);
        if (ne != null && ne.isRunning() && ne.getNode().joined()) {
          nodeEngine = ne;
          break;
        }
      }
      Address master = null;
      if (nodeEngine != null) {
        if (nodeEngine.getNode().isMaster()) {
          master = nodeEngine.getThisAddress();
        } else {
          master = nodeEngine.getMasterAddress();
        }
      }
      if (master == null) {
        master = node.getThisAddress();
      }
      node.setMasterAddress(master);
      if (node.getMasterAddress().equals(node.getThisAddress())) {
        node.setJoined();
        node.setAsMaster();
      } else {
        final ClusterJoinManager clusterJoinManager = node.clusterService.getClusterJoinManager();

        for (int i = 0; !node.joined() && node.isRunning() && i < 2000; i++) {
          try {
            clusterJoinManager.sendJoinRequest(node.getMasterAddress(), true);
            Thread.sleep(50);
          } catch (InterruptedException e) {
            e.printStackTrace();
            break;
          }
        }
        if (!node.joined()) {
          logger.severe(
              "Node["
                  + node.getThisAddress()
                  + "] should have been joined to "
                  + node.getMasterAddress());
          node.shutdown(true);
        }
      }
    }
  }
  @Override
  public void run() {
    final ClusterServiceImpl clusterService = getService();
    final ILogger logger = getLogger();

    final ClusterState clusterState = clusterService.getClusterState();

    if (clusterState == ClusterState.PASSIVE) {
      final NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
      if (nodeEngine.isRunning()) {
        logger.info(
            "Shutting down node in cluster passive state. Requested by: " + getCallerAddress());
        new Thread(
                new Runnable() {
                  @Override
                  public void run() {
                    final Node node = nodeEngine.getNode();
                    node.hazelcastInstance.getLifecycleService().shutdown();
                  }
                },
                nodeEngine.getHazelcastThreadGroup().getThreadNamePrefix(".clusterShutdown"))
            .start();
      } else {
        logger.info("Node is already shutting down. NodeState: " + nodeEngine.getNode().getState());
      }
    } else {
      logger.severe(
          "Can not shut down node because cluster is in "
              + clusterState
              + " state. Requested by: "
              + getCallerAddress());
    }
  }
Exemplo n.º 3
0
 public void doJoin(AtomicBoolean joined) {
   NodeEngineImpl nodeEngine = null;
   synchronized (joinerLock) {
     for (Address address : addresses) {
       NodeEngineImpl ne = nodes.get(address);
       if (ne != null && ne.getNode().isActive() && ne.getNode().joined()) {
         nodeEngine = ne;
         break;
       }
     }
     Address master = null;
     if (nodeEngine != null) {
       if (nodeEngine.getNode().isMaster()) {
         master = nodeEngine.getThisAddress();
       } else {
         master = nodeEngine.getMasterAddress();
       }
     }
     if (master == null) {
       master = node.getThisAddress();
     }
     node.setMasterAddress(master);
     if (node.getMasterAddress().equals(node.getThisAddress())) {
       node.setJoined();
     } else {
       for (int i = 0; !node.joined() && i < 1000; i++) {
         try {
           node.clusterService.sendJoinRequest(node.getMasterAddress(), true);
           Thread.sleep(50);
         } catch (InterruptedException e) {
           e.printStackTrace();
         }
       }
       if (!node.joined()) {
         throw new AssertionError(
             "Node["
                 + thisAddress
                 + "] should have been joined to "
                 + node.getMasterAddress());
       }
     }
   }
 }
Exemplo n.º 4
0
 public boolean write(SocketWritable socketWritable) {
   final Packet packet = (Packet) socketWritable;
   if (nodeEngine.getNode().isActive()) {
     packet.setConn(thisConnection);
     MemberImpl member = nodeEngine.getClusterService().getMember(thisAddress);
     if (member != null) {
       member.didRead();
     }
     nodeEngine.handlePacket(packet);
     return true;
   }
   return false;
 }
Exemplo n.º 5
0
 public boolean write(SocketWritable socketWritable) {
   final Packet packet = (Packet) socketWritable;
   if (nodeEngine.getNode().isActive()) {
     Packet newPacket = readFromPacket(packet);
     MemberImpl member = nodeEngine.getClusterService().getMember(localEndpoint);
     if (member != null) {
       member.didRead();
     }
     nodeEngine.getPacketTransceiver().receive(newPacket);
     return true;
   }
   return false;
 }
  public OperationServiceImpl(NodeEngineImpl nodeEngine) {
    this.nodeEngine = nodeEngine;
    this.node = nodeEngine.getNode();
    this.thisAddress = node.getThisAddress();
    this.logger = node.getLogger(OperationService.class);
    this.serializationService = (InternalSerializationService) nodeEngine.getSerializationService();

    this.backpressureRegulator =
        new BackpressureRegulator(
            node.getProperties(), node.getLogger(BackpressureRegulator.class));

    int coreSize = Runtime.getRuntime().availableProcessors();
    boolean reallyMultiCore = coreSize >= CORE_SIZE_CHECK;
    int concurrencyLevel = reallyMultiCore ? coreSize * CORE_SIZE_FACTOR : CONCURRENCY_LEVEL;

    this.invocationRegistry =
        new InvocationRegistry(
            node.getLogger(OperationServiceImpl.class),
            backpressureRegulator.newCallIdSequence(),
            concurrencyLevel);

    this.invocationMonitor =
        new InvocationMonitor(
            nodeEngine,
            thisAddress,
            node.getHazelcastThreadGroup(),
            node.getProperties(),
            invocationRegistry,
            node.getLogger(InvocationMonitor.class),
            serializationService,
            nodeEngine.getServiceManager());

    this.operationBackupHandler = new OperationBackupHandler(this);

    this.responseHandler =
        new ResponseHandler(
            node.getLogger(ResponseHandler.class),
            node.getSerializationService(),
            invocationRegistry,
            nodeEngine);
    this.asyncResponseHandler =
        new AsyncResponseHandler(
            node.getHazelcastThreadGroup(),
            node.getLogger(AsyncResponseHandler.class),
            responseHandler,
            node.getProperties());

    this.operationExecutor =
        new OperationExecutorImpl(
            node.getProperties(),
            node.loggingService,
            thisAddress,
            new OperationRunnerFactoryImpl(this),
            node.getHazelcastThreadGroup(),
            node.getNodeExtension());

    this.slowOperationDetector =
        new SlowOperationDetector(
            node.loggingService,
            operationExecutor.getGenericOperationRunners(),
            operationExecutor.getPartitionOperationRunners(),
            node.getProperties(),
            node.getHazelcastThreadGroup());
  }