Package com.sun.sgs.service

Examples of com.sun.sgs.service.Node


    private void handleLoginRequest() {
  logger.log(
      Level.FINEST,
      "handling login request for identity:{0}", identity);
 
  final Node node;
  try {
      /*
       * Get node assignment.
       */
      sessionService.nodeMapService.assignNode(
    ClientSessionHandler.class, identity);
      GetNodeTask getNodeTask = new GetNodeTask(identity);   
      sessionService.runTransactionalTask(getNodeTask, identity);
      node = getNodeTask.getNode();
      if (logger.isLoggable(Level.FINE)) {
    logger.log(Level.FINE, "identity:{0} assigned to node:{1}",
         identity, node);
      }
     
  } catch (Exception e) {
      logger.logThrow(
          Level.WARNING, e,
    "getting node assignment for identity:{0} throws", identity);
      sendLoginFailureAndDisconnect(
    new LoginFailureException(LOGIN_REFUSED_REASON, e));
      return;
  }

  long assignedNodeId = node.getId();
  if (assignedNodeId == sessionService.getLocalNodeId()) {
      /*
       * Handle this login request locally: Validate that the
       * user is allowed to log in, store the client session in
       * the data store (which assigns it an ID--the ID of the
View Full Code Here


        callStarted();   
        try {
            if (identity == null) {
                throw new NullPointerException("null id");
            }
            Node node = null;   // old node assignment
            final String serviceName = service.getName();

            // Check to see if we already have an assignment.  If so, we just
            // need to update the status.  Otherwise, we need to make our
            // persistent updates and notify listeners.  
View Full Code Here

    {
        assert (id != null);
       
        // Choose the node.  This needs to occur outside of a transaction,
        // as it could take a while. 
        final Node oldNode = old;
        final long newNodeId;
        try {
            newNodeId = assignPolicy.chooseNode(id, requestingNode);
        } catch (NoNodesAvailableException ex) {
            logger.logThrow(Level.FINEST, ex, "mapToNewNode: id {0} from {1}" +
                    " failed because no live nodes are available",
                    id, oldNode);
            throw ex;
        }

        if (oldNode != null && newNodeId == oldNode.getId()) {
            // We picked the same node.  This might be OK - the system might
            // only have one node, or the current node might simply be the
            // best one available.
            //
            // TBD - we might want a method on chooseNode which explicitly
            // excludes the current node, and returns something (a negative
            // number?) if there is no other choice.
            return newNodeId;
        }
       
        // Calculate the lookup keys for both the old and new nodes.
        // The id key is the same for both old and new.
        final String idkey = NodeMapUtil.getIdentityKey(id);
       
        // The oldNode will be null if this is the first assignment.
        final String oldNodeKey = (oldNode == null) ? null :
            NodeMapUtil.getNodeKey(oldNode.getId(), id);
        final String oldStatusKey = (oldNode == null) ? null :
            NodeMapUtil.getPartialStatusKey(id, oldNode.getId());

        final String newNodekey = NodeMapUtil.getNodeKey(newNodeId, id);
        final String newStatuskey = (serviceName == null) ? null :
                NodeMapUtil.getStatusKey(id, newNodeId, serviceName);
       
        final IdentityMO newidmo = new IdentityMO(id, newNodeId);
       
        try {
            runTransactionally(new AbstractKernelRunnable("MoveIdentity") {
                public void run() {                  
                    // First, we clean up any old mappings.
                    if (oldNode != null) {
                        try {
                            // Find the old IdentityMO, with the old node info.
                            IdentityMO oldidmo = (IdentityMO)
        dataService.getServiceBinding(idkey);

                            // Check once more for the assigned node - someone
                            // else could have mapped it before we got here.
                            // If so, just return.
                            if (oldidmo.getNodeId() != oldNode.getId()) {
                                return;
                            }

                            //Remove the old node->id key.
                            dataService.removeServiceBinding(oldNodeKey);

                            // Remove the old status information.  We don't
                            // retain any info about the old node's status.
                            Iterator<String> iter =
                                BoundNamesUtil.getServiceBoundNamesIterator(
                                    dataService, oldStatusKey);
                            while (iter.hasNext()) {
                                iter.next();
                                iter.remove();
                            }
                            // Remove the old IdentityMO with the old node info.
                            dataService.removeObject(oldidmo);
                        } catch (NameNotBoundException e) {
                            // The identity was removed before we could
                            // reassign it to a new node.
                            // Simply make the new assignment, as if oldNode
                            // was null to begin with.
                        }
                    }
                    // Add (or update) the id->node mapping.
                    dataService.setServiceBinding(idkey, newidmo);
                    // Add the node->id mapping
                    dataService.setServiceBinding(newNodekey, newidmo);
                    // Reference count
                    if (newStatuskey != null) {
                        dataService.setServiceBinding(newStatuskey, newidmo);
                    } else {
                        // This server has started the move, either through
                        // a node failure or load balancing.  Add the identity
                        // to the remove list so we will notice if the client
                        // never logs back in.
                        try {
                            canRemove(newidmo.getIdentity());
                        } catch (IOException ex) {
                            // won't happen;  this is a local call
                        }
                    }
                   
                } });
               
            GetNodeTask atask = new GetNodeTask(newNodeId);
            runTransactionally(atask);

            // Tell our listeners
            notifyListeners(oldNode, atask.getNode(), id);
        } catch (Exception e) {
            // We can get an IllegalStateException if this server shuts
            // down while we're moving identities from failed nodes.
            // TODO - check that those identities are properly removed.
            // Hmmm.  we've probably left some garbage in the data store.
            // The most likely problem is one in our own code.
            logger.logThrow(Level.FINE, e,
                            "Move {0} mappings from {1} to {2} failed",
                            id, oldNode.getId(), newNodeId);
        }

        return newNodeId;
    }
View Full Code Here

                    IdentityMO idmo = task.getId();
                    // idmo could be null if no identities are assigned
                    // to the node
                    if (idmo != null) {
                        Identity idToMove = idmo.getIdentity();
                        Node node = task.getNode();
                        try {
                            long newnode =
                                server.mapToNewNode(idToMove, null, node,
                                                 NodeAssignPolicy.SERVER_NODE);
                           
View Full Code Here

    private Health getNodeHealthTransactional() {
  if (!isLocalAlive()) {
      return Health.RED;
  } else {
      Node node = NodeImpl.getNode(dataService, localNodeId);
            if (node == null || !node.isAlive()) {
                reportFailure(localNodeId, CLASSNAME);
                return Health.RED;
            } else {
                return node.getHealth();
            }
  }
    }
View Full Code Here

      for (int i = 0; i < ids.length; i++) {
    if (ids[i] == localNodeId && health[i].isAlive()) {
        /* Don't notify the local node that it is alive. */
        continue;
    }
    Node node =
                        new NodeImpl(ids[i], hosts[i], health[i], backups[i]);
    notifyNodeListeners(node);
    if (!health[i].isAlive() && backups[i] == localNodeId) {
        notifyRecoveryListeners(node);
    }
View Full Code Here

        }
       
        serviceStats.getNodeOp.report();

        Context context = contextFactory.joinTransaction();
        Node node = context.get(id);
        logger.log(Level.FINEST, "getNode id:{0} returns {1}", id, node);
        return node;
    }
View Full Code Here

    {
        checkState();
        serviceStats.getIdentitiesOp.report();

        // Verify that the nodeId is valid.
        Node node = watchdogService.getNode(nodeId);
        if (node == null) {
            throw new UnknownNodeException("node id: " + nodeId);
        }
        IdentityIterator iter = new IdentityIterator(dataService, nodeId);
        logger.log(Level.FINEST, "getIdentities successful");
View Full Code Here

  /** {@inheritDoc} */
  public void run() {
      WatchdogService watchdogService =
    txnProxy.getService(WatchdogService.class);
      Node node = watchdogService.getNode(nodeId);
      isAlive = node != null && node.isAlive();
  }
View Full Code Here

        ClientSessionHandler handler)
  {
      ClientSessionImpl sessionImpl = eventQueue.getClientSession();
      sessionImpl.setRelocatingToNode(newNodeId);

      Node newNode = sessionService.watchdogService.getNode(newNodeId);
      if (newNode == null) {
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE,
             "Session:{0} unable to relocate from node:{1} " +
             "to FAILED node:{2}", this,
View Full Code Here

TOP

Related Classes of com.sun.sgs.service.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.