Package org.jboss.cache.optimistic

Examples of org.jboss.cache.optimistic.WorkspaceNode


   private Object getChildNamesAndNotify(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 nameSet = workspaceNode.getChildrenNames();
         workspace.addNode(workspaceNode);
         notifier.notifyNodeVisited(fqn, false, ctx);
         return nameSet;
      }
   }
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 = peekNode(ctx, fqn, false, 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

         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

   private Object getValueForKey(Object[] args, TransactionWorkspace workspace)
   {
      Fqn fqn = (Fqn) args[0];
      Object key = args[1];
      WorkspaceNode workspaceNode = getOrCreateWorkspaceNode(fqn, workspace, false);

      if (workspaceNode == null)
      {
         if (log.isDebugEnabled()) log.debug("unable to find node " + fqn + " in workspace.");
         return null;
      }
      else
      {
         //add this node into the wrokspace
         Object val = workspaceNode.get(key);
         workspace.addNode(workspaceNode);
         return val;
      }
   }
View Full Code Here

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

      WorkspaceNode workspaceNode = getOrCreateWorkspaceNode(fqn, workspace, false);

      if (workspaceNode == null)
      {
         if (log.isDebugEnabled()) log.debug("unable to find node " + fqn + " in workspace.");
         return null;
      }
      else
      {
         workspace.addNode(workspaceNode);
         return workspaceNode.getNode();
      }
   }
View Full Code Here

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

      WorkspaceNode workspaceNode = getOrCreateWorkspaceNode(fqn, workspace, false);

      if (workspaceNode == null)
      {
         if (log.isDebugEnabled()) log.debug("unable to find node " + fqn + " in workspace.");
         return null;
      }
      else
      {
         Object keySet = workspaceNode.getKeys();
         workspace.addNode(workspaceNode);
         return keySet;
      }
   }
View Full Code Here

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

      WorkspaceNode workspaceNode = getOrCreateWorkspaceNode(fqn, workspace, false);

      if (workspaceNode == null)
      {
         if (log.isDebugEnabled()) log.debug("unable to find node " + fqn + " in workspace.");
         return null;
      }
      else
      {
         Object nameSet = workspaceNode.getChildrenNames();
         workspace.addNode(workspaceNode);
         return nameSet;
      }
   }
View Full Code Here

   }

   private WorkspaceNode getOrCreateWorkspaceNode(Fqn fqn, TransactionWorkspace workspace, boolean undeleteIfNecessary)
   {
      if (log.isTraceEnabled()) log.trace("Attempting to get node " + fqn + " into the workspace");
      WorkspaceNode workspaceNode = workspace.getNode(fqn);
      // if we do not have the node then we need to add it to the workspace
      if (workspaceNode == null)
      {
         DataNode node = cache.peek(fqn);
         if (node == null)
         {
            workspaceNode = null; // seems to happen quite a bit
         }
         else
         {
            workspaceNode = NodeFactory.getInstance().createWorkspaceNode(node, workspace);
            workspace.addNode(workspaceNode);
         }
      }
      // the node has been deleted dude!
      if (workspaceNode != null && workspaceNode.isDeleted())
      {
         if (log.isDebugEnabled()) log.debug("Node " + fqn + " has been deleted in the workspace.");
         if (undeleteIfNecessary)
         {
            workspaceNode.markAsDeleted(false);
            // re-add to parent
            WorkspaceNode parent = getOrCreateWorkspaceNode(fqn.getParent(), workspace, true);
            parent.addChild(workspaceNode);
         }
         else
         {
            workspaceNode = null;
         }
View Full Code Here

       * 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

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.