Examples of WorkspaceNode


Examples of org.jboss.cache.optimistic.WorkspaceNode

        if (transactionEntry == null)
        {
            throw new CacheException("Unable to map global transaction " + gtx + " to transaction entry");
        }

        WorkspaceNode workspaceNode, childWorkspaceNode = null;
        Object childName;

        List nodesCreated = new ArrayList();
        // how many levels do we have?
        int treeNodeSize = fqn.size();

        InvocationContext ctx = getInvocationContext();

        // try and get the root from the transaction
        TransactionWorkspace workspace = transactionEntry.getTransactionWorkSpace();

        synchronized( workspace )
        {
            DataVersion version = null;
            if (ctx.getOptionOverrides() != null && ctx.getOptionOverrides().getDataVersion() != null)
            {
                version = ctx.getOptionOverrides().getDataVersion();
                workspace.setVersioningImplicit( false );
            }

            if (log.isDebugEnabled()) log.debug(" Getting root fqn from workspace  for gtx " + gtx);
            workspaceNode = workspace.getNode(cache.getRoot().getFqn());

            // we do not have the root so lets wrap it in case we need to add it
            // to the transaction
            if (workspaceNode == null)
            {
                workspaceNode = NodeFactory.getInstance().createWorkspaceNode(cache.getRoot(), workspace);
                workspace.addNode(workspaceNode);
                if (log.isDebugEnabled()) log.debug(" created root node " + workspaceNode + " in workspace " + gtx);
            }
            else
            {
                if (log.isDebugEnabled()) log.debug(" Already found root node " + workspaceNode + " in workspace " + gtx);
            }

            // we will always have one root node here, by this stage
            Fqn tmpFqn = Fqn.ROOT;
            Fqn copy;
            for (int i = 0; i < treeNodeSize; i++)
            {
                boolean isTargetFqn = (i == (treeNodeSize - 1));
                childName = fqn.get(i);

                // build up intermediate node fqn from original Fqn
                tmpFqn = new Fqn(tmpFqn, childName);

                // current workspace node canot be null.
                // try and get the child of current node

                if (log.isTraceEnabled()) log.trace(" Entering synchronized nodewrapper access  for gtx " + gtx);
                TreeNode tempChildNode = workspaceNode.getChild(childName);

//                if (log.isDebugEnabled()) log.debug(" Entered synchronized workspaceNode " + workspaceNode + " access  for gtx " + gtx);

                // no child exists with this name
                if (tempChildNode == null)
                {
                    if (log.isTraceEnabled()) log.trace("Child node "+childName+" doesn't exist.  Creating new node.");
                    // we put the parent node into the workspace as we are changing it's children
                    WorkspaceNode tempCheckWrapper = workspace.getNode(workspaceNode.getFqn());
                    if (tempCheckWrapper == null || tempCheckWrapper.isDeleted())
                    {
                        //add a new one or overwrite an existing one that has been deleted
                        if (log.isTraceEnabled()) log.trace("Parent node "+workspaceNode.getFqn()+" doesn't exist in workspace or has been deleted.  Adding to workspace in gtx " + gtx);
                        workspace.addNode(workspaceNode);
                    }
View Full Code Here

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 (log.isTraceEnabled()) log.trace("Fqn " + f + " not found in workspace; not using a data version.");
         return null;
      }
      if (n.isVersioningImplicit())
      {
         DefaultDataVersion v = (DefaultDataVersion) n.getVersion();
         if (log.isTraceEnabled()) log.trace("Fqn " + f + " has implicit versioning.  Broadcasting an incremented version.");
         return v.increment();
      }
      else
      {
         if (log.isTraceEnabled()) log.trace("Fqn " + f + " has explicit versioning.  Broadcasting the version as-is.");
         return n.getVersion();
      }
   }
View Full Code Here

Examples of org.jboss.cache.optimistic.WorkspaceNode

        // 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 writeLock = workspaceNode.isDirty() || workspaceNode.isCreated() || workspaceNode.isDeleted() || (workspaceNode.isChildrenModified() && cache.getLockParentForChildInsertRemove());

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

Examples of org.jboss.cache.optimistic.WorkspaceNode

         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

Examples of org.jboss.cache.optimistic.WorkspaceNode

      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

Examples of org.jboss.cache.optimistic.WorkspaceNode

   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

Examples of org.jboss.cache.optimistic.WorkspaceNode

   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

Examples of org.jboss.cache.optimistic.WorkspaceNode

   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

Examples of org.jboss.cache.optimistic.WorkspaceNode

   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

Examples of org.jboss.cache.optimistic.WorkspaceNode

   }

   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
TOP
Copyright © 2018 www.massapi.com. 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.