Package org.jboss.cache.optimistic

Examples of org.jboss.cache.optimistic.WorkspaceNode


    * @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.isRemoved())
      {
         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

       * 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

      boolean debug = log.isDebugEnabled();

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

      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 = dataContainer.getRoot();
         workspaceNode = lockAndCreateWorkspaceNode(nodeFactory, node, workspace, gtx, lockAcquisitionTimeout);
         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(Fqn.fromRelativeElements(workspaceNode.getFqn(), childName));
            if (peekInWorkspace != null && peekInWorkspace.isCreated())
            {
               // exists in workspace and has just been created.
               currentNode = peekInWorkspace.getNode();
               if (peekInWorkspace.isRemoved())
               {
                  peekInWorkspace.setRemoved(false);
                  // add in parent again
                  workspaceNode.addChild(peekInWorkspace);
               }
            }
         }
View Full Code Here

      boolean locked = lockManager.lock(node, READ, gtx, timeout);

      if (!locked)
         throw new TimeoutException("Unable to lock node " + node.getFqn() + " after timeout " + timeout + " for copying into workspace");

      WorkspaceNode wn = nodeFactory.createWorkspaceNode(node, workspace);

      lockManager.unlock(node, gtx);
      return wn;
   }
View Full Code Here

        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

    * 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

        // 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

         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

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.