Package org.jboss.cache.optimistic

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


   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

    }

    private void simpleValidate(Collection nodes)
        throws CacheException
    {
        WorkspaceNode workspaceNode;

        boolean trace = log.isTraceEnabled();
        for (Iterator it = nodes.iterator(); it.hasNext();)
        {
           workspaceNode = (WorkspaceNode) it.next();
           if (workspaceNode.isDirty())
           {
               Fqn fqn = workspaceNode.getFqn();
               if (trace) log.trace("Validating version for node [" + fqn + "]");
               OptimisticTreeNode realNode = (OptimisticTreeNode) cache._get(fqn);

               // if this is a newly created node then we expect the underlying node to be null.
               // also, if the node has been deleted in the WS and the underlying node is null, this *may* be ok ... will test again later when comparing versions
               // if not, we have a problem...
               if (realNode == null && !workspaceNode.isCreated() && !workspaceNode.isDeleted())
               {
                   throw new DataVersioningException("Real node for " + fqn + " is null, and this wasn't newly created in this tx!");
               }

              // needs to have been created AND modified - we allow concurrent creation if no data is put into the node
              if (realNode != null && workspaceNode.isCreated() && workspaceNode.isModified())
              {
                 throw new DataVersioningException("Tx attempted to create " + fqn + " anew.  It has already been created since this tx started by another (possibly remote) tx.");
              }

               if (!workspaceNode.isCreated() && (workspaceNode.isDeleted() || workspaceNode.isModified()))
               {
                  // if the real node is null, throw a DVE
                  if (realNode == null)
                  {
                     // but not if the WSN has also been deleted
                     if (!workspaceNode.isDeleted())
                        throw new DataVersioningException("Unable to compare versions since the underlying node has been deleted by a concurrent transaction!");
                     else
                        if (trace) log.trace("The data node ["+fqn+"] is null, but this is ok since the workspace node is marked as deleted as well");
                  }
                  else if (realNode.getVersion().newerThan( workspaceNode.getVersion() ))
                  {
                     // newerThan() will internally test if the DataVersion types being compared tally up, and will barf if
                     // necessary with an appropriate DataVersioningException.
                     // we have an out of date node here
                     throw new DataVersioningException("DataNode [" + fqn + "] version " + ((OptimisticTreeNode)workspaceNode.getNode()).getVersion() + " is newer than workspace node " + workspaceNode.getVersion());
                  }
               }
           }
           else
           {
               if (trace) log.trace("Node [" + workspaceNode.getFqn() + "] doesn't need validating as it isn't dirty");
           }
        }
    }
View Full Code Here

        Collection nodes = workspace.getNodes().values();

        boolean trace = log.isTraceEnabled();
        for (Iterator it = nodes.iterator(); it.hasNext();)
        {
            WorkspaceNode wrappedNode = (WorkspaceNode) it.next();
           if (trace) log.trace("Analysing node " + wrappedNode.getFqn() + " in workspace.");
            // short circuit if this node is deleted?
            if (wrappedNode.isDeleted())
            {
                // handle notifications

                if (trace) log.trace("Node's been deleted; removing");
                DataNode dNode = wrappedNode.getNode();
                cache.notifyNodeRemove(dNode.getFqn(), true);

                if (dNode.getFqn().isRoot())
                {
                    log.warn("Attempted to delete the root node");
                }
                else
                {
                    DataNode parent = (DataNode) dNode.getParent();
                    parent.removeChild( dNode.getName() );
                }
                cache.notifyNodeRemoved(dNode.getFqn());
                cache.notifyNodeRemove(dNode.getFqn(), false);
            }
            else
            {
                // "Will somebody please think of the children!!"
                // if (wrappedNode.hasCreatedOrRemovedChildren() handleChildNodes(wrappedNode);
                //if (wrappedNode.isModified())
                //{
              OptimisticTreeNode current = (OptimisticTreeNode) wrappedNode.getNode();
              boolean updateVersion = false;

              if (wrappedNode.isChildrenModified())
              {
                 log.trace("Updating children since node has modified children");
                 // merge children.
                 List deltas = wrappedNode.getMergedChildren();

                 if (trace) log.trace("Applying children deltas to parent node " + current.getFqn());
                 for (Iterator i = ((Set) deltas.get(0)).iterator(); i.hasNext();)
                 {
                     TreeNode child = (TreeNode) i.next();
                     current.addChild(child.getName(), child);
                 }

                 for (Iterator i = ((Set) deltas.get(1)).iterator(); i.hasNext();)
                 {
                    TreeNode child = (TreeNode) i.next();
                    current.removeChild(child.getName());
                 }

                  updateVersion = cache.getLockParentForChildInsertRemove();
              }

               if (wrappedNode.isModified() || wrappedNode.isCreated())
               {
                    cache.notifyNodeModify(wrappedNode.getFqn(), true);

                    log.trace("Merging data since node is dirty");
                    Map mergedData = wrappedNode.getMergedData();
                    current.put(mergedData, true);
                    updateVersion = true;
                    cache.notifyNodeModified(wrappedNode.getFqn());
                    cache.notifyNodeModify(wrappedNode.getFqn(), false);
               }
              
               if (updateVersion)
               {
                    if (wrappedNode.isVersioningImplicit())
                    {
                        if (trace) log.trace("Versioning is implicit; incrementing.");
                        if (wrappedNode.getVersion() instanceof DefaultDataVersion)
                           current.setVersion(((DefaultDataVersion)wrappedNode.getVersion()).increment());
                       else
                           log.debug("Even though no explicit version was passed in, node has an external DataVersion impl.  Don't know how to increment, not incrementing.");
                    }
                    else
                    {
                        if (trace) log.trace("Versioning is explicit; not attempting an increment.");
                        current.setVersion(wrappedNode.getVersion());
                    }
                    if (trace) log.trace("Setting version of node from " + wrappedNode.getVersion() + " to " + current.getVersion());
                }
                else
                {
                    if (trace) log.trace("Version update on " + wrappedNode.getFqn() + " not necessary since the node is not dirty or LockParentForChildInsertRemove is set to false");
                    cache.notifyNodeVisited(wrappedNode.getFqn());
                }
            }
        }

    }
View Full Code Here

      {
         // do nothing
      }
      if (!locked)
         throw new TimeoutException("Unable to lock node " + node.getFqn() + " after timeout " + timeout + " for copying into workspace");
      WorkspaceNode wn = nodeFactory.createWorkspaceNode(node, workspace);
      node.getLock().release(gtx);
      return wn;
   }
View Full Code Here

      boolean debug = log.isDebugEnabled();

      GlobalTransaction gtx = getGlobalTransaction(ctx);
      TransactionWorkspace workspace = getTransactionWorkspace(gtx);

      WorkspaceNode workspaceNode;

      List<Fqn> nodesCreated = new ArrayList<Fqn>();

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

      // start with the ROOT node and then work our way down to the node necessary, creating nodes along the way.
      workspaceNode = workspace.getNode(Fqn.ROOT);
      if (debug) log.debug("GlobalTransaction: " + gtx + "; Root: " + workspaceNode);

      // we do not have the root in the workspace!  Put it into thr workspace now.
      if (workspaceNode == null)
      {
         NodeSPI node = cache.getRoot();
         workspaceNode = lockAndCreateWorkspaceNode(nodeFactory, node, workspace, gtx, lockAcquisitionTimeout);
         //workspaceNode = nodeFactory.createWorkspaceNode(node, workspace);
         workspace.addNode(workspaceNode);
         log.debug("Created root node in workspace.");
      }
      else
      {
         log.debug("Found root node in workspace.");
      }

      // iterate through the target Fqn's elements.
      int targetFqnSize = targetFqn.size(), currentDepth = 1;
      for (Object childName : targetFqn.peekElements())
      {
         boolean isTargetFqn = (currentDepth == targetFqnSize);
         currentDepth++;

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

         if (debug) log.debug("Attempting to get child " + childName);
         NodeSPI currentNode = workspaceNode.getNode().getChildDirect(childName);

         if (currentNode == null)
         {
            // first test that it exists in the workspace and has been created in thix tx!
            WorkspaceNode peekInWorkspace = workspace.getNode(new Fqn(workspaceNode.getFqn(), childName));
            if (peekInWorkspace != null && peekInWorkspace.isCreated())
            {
               // exists in workspace and has just been created.
               currentNode = peekInWorkspace.getNode();
               if (peekInWorkspace.isDeleted()) undeleteWorkspaceNode(peekInWorkspace, workspaceNode);
            }
         }

         if (currentNode == null)
         {
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.