Package org.jboss.cache.optimistic

Examples of org.jboss.cache.optimistic.WorkspaceNode


    * Digs out the DataVersion for a given Fqn.  If the versioning is explicit, it is passed as-is.  If implicit, it is
    * cloned and then incremented, and the clone is returned.
    */
   private DataVersion getVersionToBroadcast(TransactionWorkspace w, Fqn f)
   {
      WorkspaceNode n = w.getNode(f);
      if (n == null)
      {
         if (trace) log.trace("Fqn " + f + " not found in workspace; not using a data version.");
         return null;
      }
      if (n.isVersioningImplicit())
      {
         DefaultDataVersion v = (DefaultDataVersion) n.getVersion();
         if (trace)
            log.trace("Fqn " + f + " has implicit versioning.  Broadcasting an incremented version.");

         // potential bug here - need to check if we *need* to increment at all, because of Configuration.isLockParentForChildInsertRemove()
         return v.increment();
      }
      else
      {
         if (trace) log.trace("Fqn " + f + " has explicit versioning.  Broadcasting the version as-is.");
         return n.getVersion();
      }
   }
View Full Code Here


   }

   protected DataVersion getNodeVersion(TransactionWorkspace w, Fqn f)
   {
      if (w == null) return null;
      WorkspaceNode wn = w.getNode(f);
      if (wn == null) return null; // JBCACHE-1297
      DataVersion v = wn.getVersion();

      if (wn.isVersioningImplicit())
      {
         // then send back an incremented version
         v = ((DefaultDataVersion) v).increment();
      }
View Full Code Here

      if (MethodDeclarations.isCrudMethod(m.getMethodId()))
      {
         GlobalTransaction gtx = getGlobalTransaction(ctx);
         TransactionWorkspace workspace = getTransactionWorkspace(gtx);
         Fqn fqn = getFqn(args, m.getMethodId());
         WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, fqn, workspace, MethodDeclarations.removeNodeMethodLocal_id != m.getMethodId(), true);

         // in the case of a data gravitation cleanup, if the primary Fqn does not exist the backup one may.
         if (workspaceNode == null && m.getMethodId() == MethodDeclarations.dataGravitationCleanupMethod_id)
         {
            workspaceNode = fetchWorkspaceNode(ctx, getBackupFqn(args), workspace, true, true);
         }

         if (workspaceNode != null)
         {
            // use explicit versioning
            if (ctx.getOptionOverrides() != null && ctx.getOptionOverrides().getDataVersion() != null)
            {
               // if the method call is a move() then barf.  Note that remove calls will set data versions explicitly, regardless.
               if (ctx.isOriginLocal() && m.getMethodId() == MethodDeclarations.moveMethodLocal_id)
                  throw new CacheException("Setting a data version while performing a move() is not supported!!");

               workspace.setVersioningImplicit(false);
               DataVersion version = ctx.getOptionOverrides().getDataVersion();

               workspaceNode.setVersion(version);
               if (trace) log.trace("Setting versioning for node " + workspaceNode.getFqn() + " to explicit");

               workspaceNode.setVersioningImplicit(false);
            }
            else
            {
               if (trace) 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

      {
         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(new Fqn(nodeName));

      // parent pointer is calculated on the fly using Fqns.
      // now adjust Fqns of node and all children.
      Fqn nodeNewFqn = new Fqn(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 = new Fqn(newBase, node.getFqn().getLastElement());
      WorkspaceNode movedNode = fetchWorkspaceNode(ctx, newFqn, ws, true, true);
      movedNode.putAll(node.getData());

      // process children
      for (Object n : node.getChildrenNames())
      {
         WorkspaceNode child = fetchWorkspaceNode(ctx, new Fqn(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

   private Object getValueForKeyAndNotify(Object[] args, TransactionWorkspace workspace, InvocationContext ctx)
   {
      Fqn fqn = (Fqn) args[0];
      Object key = args[1];
      WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, fqn, workspace, false, false);

      if (workspaceNode == null)
      {
         if (trace) log.debug("Unable to find node " + fqn + " in workspace.");
         return null;
      }
      else
      {
         //add this node into the wrokspace
         notifier.notifyNodeVisited(fqn, true, ctx);
         Object val = workspaceNode.get(key);
         workspace.addNode(workspaceNode);
         notifier.notifyNodeVisited(fqn, false, ctx);
         return val;
      }
   }
View Full Code Here

   private Object getNodeAndNotify(Object[] args, TransactionWorkspace workspace, InvocationContext ctx)
   {
      Fqn fqn = (Fqn) args[0];

      WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, fqn, workspace, false, false);

      if (workspaceNode == null)
      {
         if (trace) log.trace("Unable to find node " + fqn + " in workspace.");
         return null;
      }
      else if (workspaceNode.isDeleted())
      {
         if (trace) log.trace("Attempted to retrieve node " + fqn + " but it has been deleted!");
         return null;
      }
      else
      {
         notifier.notifyNodeVisited(fqn, true, ctx);
         workspace.addNode(workspaceNode);
         notifier.notifyNodeVisited(fqn, false, ctx);
         return workspaceNode.getNode();
      }
   }
View Full Code Here

   private Object getKeysAndNotify(Object[] args, TransactionWorkspace workspace, InvocationContext ctx)
   {
      Fqn fqn = (Fqn) args[0];

      WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, fqn, workspace, false, false);

      if (workspaceNode == null)
      {
         if (trace) log.trace("unable to find node " + fqn + " in workspace.");
         return null;
      }
      else
      {
         notifier.notifyNodeVisited(fqn, true, ctx);
         Object keySet = workspaceNode.getKeys();
         workspace.addNode(workspaceNode);
         notifier.notifyNodeVisited(fqn, false, ctx);
         return keySet;
      }
   }
View Full Code Here

   private Object getDataAndNotify(Object[] args, TransactionWorkspace workspace, InvocationContext ctx)
   {
      Fqn fqn = (Fqn) args[0];

      WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, fqn, workspace, false, false);

      if (workspaceNode == null)
      {
         if (trace) log.trace("unable to find node " + fqn + " in workspace.");
         return null;
      }
      else
      {
         notifier.notifyNodeVisited(fqn, true, ctx);
         Object data = workspaceNode.getData();
         workspace.addNode(workspaceNode);
         notifier.notifyNodeVisited(fqn, false, ctx);
         return data;
      }
   }
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.