Package org.jboss.cache

Examples of org.jboss.cache.NodeSPI


      Fqn fqn = node.getFqn();
      acquireLock(ctx, fqn); // lock node
      if (fqnList != null) fqnList.add(fqn);

      // now wrap and add to the context
      NodeSPI rcn = wrapNodeForWriting(ctx, node, parent);
      if (rcn != null)
      {
         rcn.markForUpdate(dataContainer, writeSkewCheck);
         Map<Object, InternalNode<?, ?>> children = node.getChildrenMap();
         for (InternalNode child : children.values()) lockForWritingRecursive(child, node, ctx, fqnList);
      }
   }
View Full Code Here


   {
      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.
View Full Code Here

      return invokeNextInterceptor(ctx, command);
   }

   private void loadIfNeeded(InvocationContext ctx, Fqn fqn, Object key, boolean allKeys, boolean initNode, boolean acquireWriteLock, boolean recursive, boolean isMove, boolean bypassLoadingData, boolean shouldLoadIfNodeIsNull) throws Throwable
   {
      NodeSPI n = helper.wrapNodeForReading(ctx, fqn, true);
      if (n instanceof NullMarkerNode)
      {
         ctx.getLookedUpNodes().remove(fqn);
         n = null;
      }
      boolean mustLoad = mustLoad(n, key, allKeys || isMove, shouldLoadIfNodeIsNull);

      if (trace) log.trace("load element " + fqn + " mustLoad=" + mustLoad);

      if (mustLoad)
      {
         if (acquireWriteLock || initNode)
         {
            boolean isNew = n == null;
            n = helper.wrapNodeForWriting(ctx, fqn, true, false, true, false, true); // won't create any nodes but will acquire locks.
            if (isNew && n != null) n.setDataLoaded(false);
         }

         if (n == null || !n.isDeleted())
         {
            if (n == null && loader.exists(fqn))
            {
               // just create a dummy node in memory
               n = helper.wrapNodeForWriting(ctx, fqn, true, true, true, false, false);
               n.setDataLoaded(false);
            }
            if (!bypassLoadingData)
            {
               n = loadNode(ctx, fqn, n);
            }
         }
      }

      // The complete list of children aren't known without loading them
      if (recursive && n != null)
      {
         loadChildren(fqn, n.getDelegationTarget(), recursive, isMove, ctx);
      }
   }
View Full Code Here

         if (workspaceNode.isDirty())
         {
            Fqn fqn = workspaceNode.getFqn();
            if (trace) log.trace("Validating version for node [" + fqn + "]");

            NodeSPI underlyingNode;
            underlyingNode = dataContainer.peek(fqn, true, true);

            // 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 (underlyingNode == null && !workspaceNode.isCreated() && !workspaceNode.isRemoved())
            {
               throw new DataVersioningException("Underlying node for " + fqn + " is null, and this node wasn't newly created in this transaction!  We have a concurrent deletion event.");
            }

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

            if (underlyingNode != null && !underlyingNode.isValid())
            {
               // we havea  tombstone
               if (!workspaceNode.isCreated() && !workspaceNode.isRemoved())
                  throw new DataVersioningException("Underlying node doesn't exist but a tombstone does; workspace node should be marked as created!");
               if (underlyingNode.getVersion().newerThan(workspaceNode.getVersion()))
               {
                  // we have an out of date node here
                  throw new DataVersioningException("Version mismatch for node " + fqn + ": underlying node with version " + workspaceNode.getNode().getVersion() + " is newer than workspace node, with version " + workspaceNode.getVersion());
               }
            }

            if (!workspaceNode.isCreated() && (workspaceNode.isRemoved() || workspaceNode.isModified()))
            {
               // if the real node is null, throw a DVE
               if (underlyingNode == null)
               {
                  // but not if the WSN has also been deleted
                  if (!workspaceNode.isRemoved())
                     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");
               }
               // if there is a DataVersion type mismatch here, leave it up to the DataVersion impl to barf if necessary.  - JBCACHE-962
               else if (underlyingNode.getVersion().newerThan(workspaceNode.getVersion()))
               {
                  // we have an out of date node here
                  throw new DataVersioningException("Version mismatch for node " + fqn + ": underlying node with version " + workspaceNode.getNode().getVersion() + " is newer than workspace node, with version " + workspaceNode.getVersion());
               }
            }
View Full Code Here

      if (log.isDebugEnabled()) log.debug("Commiting successfully validated changes for GlobalTransaction " + gtx);
      Collection<WorkspaceNode> workspaceNodes = workspace.getNodes().values();
      for (WorkspaceNode workspaceNode : workspaceNodes)
      {
         NodeSPI underlyingNode = workspaceNode.getNode();
         // short circuit if this node is deleted?
         if (workspaceNode.isRemoved())
         {
            if (trace) log.trace("Workspace node " + workspaceNode.getFqn() + " deleted; removing");

            if (underlyingNode.getFqn().isRoot())
            {
               throw new CacheException("An illegal attempt to delete the root node!");
            }
            else
            {
               // mark it as invalid so any direct references are marked as such
               underlyingNode.setValid(false, true);
               // we need to update versions here, too
               performVersionUpdate(underlyingNode, workspaceNode);

               if (!useTombstones)
               {
                  // don't retain the tombstone
                  NodeSPI parent = underlyingNode.getParentDirect();
                  if (parent == null)
                  {
                     throw new CacheException("Underlying node " + underlyingNode + " has no parent");
                  }

                  parent.removeChildDirect(underlyingNode.getFqn().getLastElement());
               }
            }
         }
         else
         {
            boolean updateVersion = false;
            if (workspaceNode.isChildrenModified() || workspaceNode.isResurrected()) // if it is newly created make sure we remove all underlying children that may exist, to solve a remove-and-create-in-tx condition
            {
               if (trace) log.trace("Updating children since node has modified children");
               // merge children.
               List<Set<Fqn>> deltas = workspaceNode.getMergedChildren();

               if (trace) log.trace("Applying children deltas to parent node " + underlyingNode.getFqn());

               if (workspaceNode.isResurrected())
               {
                  // mark it as invalid so any direct references are marked as such
                  Map childNode = underlyingNode.getChildrenMapDirect();
                  for (Object o : childNode.values())
                  {
                     NodeSPI cn = (NodeSPI) o;
                     cn.setValid(false, true);
                     if (!useTombstones) underlyingNode.removeChildDirect(cn.getFqn().getLastElement());
                  }
               }

               for (Fqn child : deltas.get(0))
               {
                  NodeSPI childNode = workspace.getNode(child).getNode();
                  underlyingNode.addChildDirect(childNode);
                  childNode.setValid(true, false);
               }

               for (Fqn child : deltas.get(1))
               {
                  // mark it as invalid so any direct references are marked as such
                  NodeSPI childNode = underlyingNode.getChildDirect(child.getLastElement());
                  if (childNode != null) childNode.setValid(false, true);

                  if (!useTombstones) underlyingNode.removeChildDirect(child.getLastElement());
               }

               updateVersion = underlyingNode.isLockForChildInsertRemove();
View Full Code Here

         TransactionWorkspace<?, ?> workspace = getTransactionWorkspace(ctx);
         if (log.isDebugEnabled()) log.debug("Locking nodes in transaction workspace for GlobalTransaction " + gtx);

         for (WorkspaceNode workspaceNode : workspace.getNodes().values())
         {
            NodeSPI node = workspaceNode.getNode();

            boolean isWriteLockNeeded = workspaceNode.isDirty() || (workspaceNode.isChildrenModified() && (configuration.isLockParentForChildInsertRemove() || node.isLockForChildInsertRemove()));

            boolean acquired = lockManager.lockAndRecord(node, isWriteLockNeeded ? WRITE : READ, ctx);
            if (acquired)
            {
               if (trace) log.trace("Acquired lock on node " + node.getFqn());
            }
            else
            {
               throw new CacheException("Unable to acquire lock on node " + node.getFqn());
            }

         }

         // locks have acquired so lets pass on up
View Full Code Here

      }

      // Create if node had not been created already
      if (node == null)
      {
         NodeSPI temp = helper.wrapNodeForWriting(ctxt, fqn, true, true, true, false, false);
         node = temp.getDelegationTarget();
      }

      // Create one DataNode per child, mark as UNINITIALIZED
      for (Object name : childrenNames)
      {
         Fqn childFqn = Fqn.fromRelativeElements(fqn, name);

         // create child if it didn't exist
         NodeSPI child = helper.wrapNodeForWriting(ctxt, childFqn, true, true, true, false, false);
         if (child.isCreated()) child.setDataLoaded(false);
         if ((isMove || isActivation) && recursive)
         {
            // load data for children as well!
            child.setInternalState(loader.get(child.getFqn()));
            child.setDataLoaded(true);
         }

         if (recursive)
         {
            loadChildren(child.getFqn(), child.getDelegationTarget(), true, isMove, ctxt);
         }
      }
      node.setChildrenLoaded(true);
   }
View Full Code Here

   {
      Fqn fqn = command.getFqn();
      if (fqn != null)
      {
         loadIfNeeded(ctx, fqn, null, false, false, false, ctx.getTransactionContext(), false, false, true);
         NodeSPI n = dataContainer.peek(fqn, true, true);
         loadChildren(fqn, n, false, false, ctx);
      }
      return invokeNextInterceptor(ctx, command);
   }
View Full Code Here

      return invokeNextInterceptor(ctx, command);
   }

   private void loadIfNeeded(InvocationContext ctx, Fqn fqn, Object key, boolean allKeys, boolean initNode, boolean acquireLock, TransactionContext transactionContext, boolean recursive, boolean isMove, boolean bypassLoadingData) throws Throwable
   {
      NodeSPI n = dataContainer.peek(fqn, true, true);
      Object lockOwner = lockManager.getLockOwner(ctx);
      boolean needLock = n != null && !lockManager.ownsLock(fqn, lockOwner);
      boolean mustLoad = false;
      try
      {
View Full Code Here

      for (Object name : childrenNames)
      {
         Fqn childFqn = Fqn.fromElements(name);// this is a RELATIVE Fqn!!

         // create child if it didn't exist
         NodeSPI child = node.addChildDirect(childFqn);
         if ((isMove || isActivation) && recursive)
         {
            // load data for children as well!
            child.setInternalState(loader.get(child.getFqn()));
            child.setDataLoaded(true);
         }

         if (recursive)
         {
            loadChildren(child.getFqn(), child, true, isMove, ctxt);
         }
      }
      lock(fqn, recursive ? LockType.WRITE : LockType.READ, true, ctxt);// recursive=true: lock entire subtree
      node.setChildrenLoaded(true);
   }
View Full Code Here

TOP

Related Classes of org.jboss.cache.NodeSPI

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.