Package org.jboss.cache.optimistic

Examples of org.jboss.cache.optimistic.WorkspaceNode


   @Override
   public Object visitGetDataMapCommand(InvocationContext ctx, GetDataMapCommand command) throws Throwable
   {
      TransactionWorkspace workspace = getTransactionWorkspace(ctx);
      Object result;
      WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace, false, false);
      if (workspaceNode == null)
      {
         if (trace) log.trace("unable to find node " + command.getFqn() + " in workspace.");
         result = null;
      }
      else
      {
         notifier.notifyNodeVisited(command.getFqn(), true, ctx);
         Object data = workspaceNode.getData();
         workspace.addNode(workspaceNode);
         notifier.notifyNodeVisited(command.getFqn(), false, ctx);
         result = data;
      }
      return result;
View Full Code Here


   @Override
   public Object visitGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable
   {
      TransactionWorkspace workspace = getTransactionWorkspace(ctx);
      Object result;
      WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace, false, false);
      if (workspaceNode == null)
      {
         if (trace) log.trace("Unable to find node " + command.getFqn() + " in workspace.");
         result = null;
      }
      else
      {
         notifier.notifyNodeVisited(command.getFqn(), true, ctx);
         Object nameSet = workspaceNode.getChildrenNames();
         workspace.addNode(workspaceNode);
         notifier.notifyNodeVisited(command.getFqn(), false, ctx);
         result = nameSet;
      }
      return result;
View Full Code Here

   @Override
   public Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
   {
      TransactionWorkspace workspace = getTransactionWorkspace(ctx);
      Object result;
      WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace, false, false);
      if (workspaceNode == null)
      {
         if (trace) log.trace("Unable to find node " + command.getFqn() + " in workspace.");
         result = null;
      }
      else if (workspaceNode.isDeleted())
      {
         if (trace) log.trace("Attempted to retrieve node " + command.getFqn() + " but it has been deleted!");
         result = null;
      }
      else
      {
         notifier.notifyNodeVisited(command.getFqn(), true, ctx);
         workspace.addNode(workspaceNode);
         notifier.notifyNodeVisited(command.getFqn(), false, ctx);
         result = workspaceNode.getNode();
      }
      return result;
   }
View Full Code Here

      {
         log.warn("Attempting to move the root node.  Not taking any action, treating this as a no-op.");
         return;
      }

      WorkspaceNode oldParent = fetchWorkspaceNode(ctx, nodeFqn.getParent(), ws, false, true);
      if (oldParent == null) throw new NodeNotExistsException("Node " + nodeFqn.getParent() + " does not exist!");

      if (parentFqn.equals(oldParent.getFqn()))
      {
         log.warn("Attempting to move a node in same place.  Not taking any action, treating this as a no-op.");
         return;
      }
      // retrieve parent
      WorkspaceNode parent = fetchWorkspaceNode(ctx, parentFqn, ws, false, true);
      if (parent == null) throw new NodeNotExistsException("Node " + parentFqn + " does not exist!");

      Object nodeName = nodeFqn.getLastElement();

      // now that we have the parent and target nodes:
      // first correct the pointers at the pruning point
      oldParent.removeChild(nodeName);

      // parent pointer is calculated on the fly using Fqns.
      // now adjust Fqns of node and all children.
      Fqn nodeNewFqn = Fqn.fromRelativeElements(parent.getFqn(), nodeFqn.getLastElement());

      // pre-notify
      notifier.notifyNodeMoved(nodeFqn, nodeNewFqn, true, ctx);
      recursiveMoveNode(ctx, node, parent.getFqn(), ws);

      // remove old nodes. this may mark some nodes which have already been moved as deleted
      removeNode(ws, node, false, ctx);

      // post-notify
View Full Code Here

    * @param ws      transaction workspace
    */
   private void recursiveMoveNode(InvocationContext ctx, WorkspaceNode node, Fqn newBase, TransactionWorkspace ws)
   {
      Fqn newFqn = Fqn.fromRelativeElements(newBase, node.getFqn().getLastElement());
      WorkspaceNode movedNode = fetchWorkspaceNode(ctx, newFqn, ws, true, true);
      movedNode.putAll(node.getData());

      // invoke children
      for (Object n : node.getChildrenNames())
      {
         WorkspaceNode child = fetchWorkspaceNode(ctx, Fqn.fromRelativeElements(node.getFqn(), n), ws, false, true);
         if (child != null) recursiveMoveNode(ctx, child, newFqn, ws);
      }
   }
View Full Code Here

   {
      // it is already removed - we can ignore it
      if (workspaceNode == null) return false;

      Fqn parentFqn = workspaceNode.getFqn().getParent();
      WorkspaceNode parentNode = fetchWorkspaceNode(ctx, parentFqn, workspace, false, true);
      if (parentNode == null) throw new NodeNotExistsException("Unable to find parent node with fqn " + parentFqn);

      // pre-notify
      if (notify) notifier.notifyNodeRemoved(workspaceNode.getFqn(), true, workspaceNode.getData(), ctx);

      Fqn nodeFqn = workspaceNode.getFqn();
      parentNode.removeChild(nodeFqn.getLastElement());

      SortedMap<Fqn, WorkspaceNode> tailMap = workspace.getNodesAfter(workspaceNode.getFqn());

      for (WorkspaceNode toDelete : tailMap.values())
      {
View Full Code Here

    * @param includeInvalidNodes
    * @return a node, if found, or null if not.
    */
   private WorkspaceNode fetchWorkspaceNode(InvocationContext ctx, Fqn fqn, TransactionWorkspace workspace, boolean undeleteIfNecessary, boolean includeInvalidNodes)
   {
      WorkspaceNode workspaceNode = workspace.getNode(fqn);
      // if we do not have the node then we need to add it to the workspace
      if (workspaceNode == null)
      {
         NodeSPI node = dataContainer.peek(fqn, true, includeInvalidNodes);
         if (node == null) return null;
         GlobalTransaction gtx = ctx.getGlobalTransaction();
         workspaceNode = lockAndCreateWorkspaceNode(nodeFactory, node, workspace, gtx, lockAcquisitionTimeout);

         // and add the node to the workspace.
         workspace.addNode(workspaceNode);
      }

      // Check that the workspace node has been marked as deleted.
      if (workspaceNode.isDeleted())
      {
         if (trace) log.trace("Node " + fqn + " has been deleted in the workspace.");
         if (undeleteIfNecessary)
         {
            undeleteWorkspaceNode(workspaceNode, fetchWorkspaceNode(ctx, fqn.getParent(), workspace, undeleteIfNecessary, includeInvalidNodes));
         }
         else if (!includeInvalidNodes)
         {
            // don't return deleted nodes if undeleteIfNecessary is false!
            workspaceNode = null;
         }
      }

      // set implicit node versioning flag.
      if (workspaceNode != null && !(workspaceNode.getVersion() instanceof DefaultDataVersion))
      {
         workspaceNode.setVersioningImplicit(false);
      }

      // now make sure all parents are in the wsp as well
      if (workspaceNode != null && !fqn.isRoot())
         fetchWorkspaceNode(ctx, fqn.getParent(), workspace, false, includeInvalidNodes);
View Full Code Here

        // should be an ordered list
        Collection nodes = workspace.getNodes().values();

        for (Iterator it = nodes.iterator(); it.hasNext();)
        {
            WorkspaceNode workspaceNode = (WorkspaceNode) it.next();
            DataNode node = workspaceNode.getNode();

            boolean acquired = node.acquire(gtx, lockAcquisitionTimeout, DataNode.LOCK_TYPE_WRITE);
            if (acquired)
            {
                if (log.isTraceEnabled()) log.trace("acquired lock on node " + node.getName());
View Full Code Here

         if (tx == null || !isValid(tx))
         {
            throw new CacheException("Must be in a valid transaction " + m);
         }

         WorkspaceNode workspaceNode = getOrCreateWorkspaceNode(getFqn(args), workspace, true);
         if (workspaceNode == null && m.getMethodId() == MethodDeclarations.dataGravitationCleanupMethod_id)
         {
            workspaceNode = getOrCreateWorkspaceNode(getBackupFqn(args), workspace, true);
         }


         if (workspaceNode != null)
         {
            // use explicit versioning
            if (ctx.getOptionOverrides() != null && ctx.getOptionOverrides().getDataVersion() != null)
            {
               workspace.setVersioningImplicit(false);
               DataVersion version = ctx.getOptionOverrides().getDataVersion();

               workspaceNode.setVersion(version);
               if (log.isTraceEnabled()) log.trace("Setting versioning for node " + workspaceNode.getFqn() + " to explicit");
               workspaceNode.setVersioningImplicit(false);
            }
            else
            {
               if (log.isTraceEnabled()) log.trace("Setting versioning for node " + workspaceNode.getFqn() + " to implicit");
               workspaceNode.setVersioningImplicit(true);
            }
         }
         else
         {
            // "fail-more-silently" patch thanks to Owen Taylor - JBCACHE-767
View Full Code Here

      boolean debug = log.isDebugEnabled();

      Fqn parentFqn = temp.getFqn();

      // get a wrapped parent
      WorkspaceNode parentNode = getOrCreateWorkspaceNode(parentFqn, workspace, false);
      if (parentNode == null)
      {
         // chk if this has been removed in the same tx
         parentNode = workspace.getNode(parentFqn);
         if (parentNode == null || !parentNode.isDeleted())
            throw new CacheException("Unable to find parent node with Fqn " + parentFqn);
      }

      parentNode.removeChild(workspaceNode.getName());
      workspace.addNode(parentNode);
      if (debug) log.debug("added parent node " + parentNode.getFqn() + " to workspace");
      Fqn nodeFqn = workspaceNode.getFqn();

      // Mark this node and all children as deleted
      workspace.addNode(workspaceNode); // deleted below
      SortedMap tailMap = workspace.getNodesAfter(workspaceNode.getFqn());

      for (Iterator it = tailMap.entrySet().iterator(); it.hasNext();)
      {
         WorkspaceNode toDelete = (WorkspaceNode) ((Map.Entry) it.next()).getValue();
         if (toDelete.getFqn().isChildOrEquals(nodeFqn))
         {
            if (debug) log.debug("marking node " + toDelete.getFqn() + " as deleted");
            toDelete.markAsDeleted(true);
         }
         else
         {
            break; // no more children, we came to the end
         }
View Full Code Here

TOP

Related Classes of org.jboss.cache.optimistic.WorkspaceNode

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.