Package org.jboss.cache

Examples of org.jboss.cache.NodeSPI


   {
      if (fqn == null)
      {
         throw new NodeNotLoadedException();
      }
      NodeSPI n = ctx.lookUpNode(fqn);

      if (n != null)
      {
         return n.getDataDirect();
      }
      else
      {
         throw new NodeNotLoadedException();
      }
View Full Code Here


   {
      if (!inTransaction())
      {
         loader.removeData(command.getFqn());
         // we need to mark this node as data loaded
         NodeSPI n = ctx.lookUpNode(command.getFqn());
         if (n != null)
         {
            n.setDataLoaded(true);
         }
      }
      return invokeNextInterceptor(ctx, command);
   }
View Full Code Here

         try
         {
            for (Fqn f : affectedFqns)
            {
               // NOT going to store tombstones!!
               NodeSPI n = ctx.lookUpNode(f);
               if (n != null && !n.isDeleted())
               {
                  Map internalState = n.getInternalState(false);
                  loader.put(f, internalState);
               }
            }
         }
         finally
View Full Code Here

   public Object visitMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable
   {
      List<Fqn> fqns = new ArrayList<Fqn>();
      fqns.add(command.getTo());
      //  peek into Node and get a hold of all child fqns as these need to be in the workspace.
      NodeSPI node = dataContainer.peek(command.getFqn(), true, true);
      greedyGetFqns(fqns, node, command.getTo());
      if (trace) log.trace("Adding Fqns " + fqns + " for a move() operation.");
      for (Fqn f : fqns)
      {
         createNode(ctx, f, true);
View Full Code Here

      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);
               }
            }
         }

         if (currentNode == null)
         {
            // no child exists with this name; create it in the underlying data structure and then add it to the workspace.
            if (trace) log.trace("Creating new child, since it doesn't exist in the cache.");
            // we put the parent node into the workspace as we are changing its children.
            // at this point "workspaceNode" refers to the parent of the current node.  It should never be null if
            // you got this far!
            if (workspaceNode.isRemoved())
            {
               //add a new one or overwrite an existing one that has been deleted
               if (trace)
                  log.trace("Parent node doesn't exist in workspace or has been deleted.  Adding to workspace.");
               workspace.addNode(workspaceNode);
               if (!(workspaceNode.getVersion() instanceof DefaultDataVersion))
                  workspaceNode.setVersioningImplicit(false);
            }
            else
            {
               if (trace) log.trace("Parent node exists: " + workspaceNode);
            }

            // get the version passed in, if we need to use explicit versioning.
            DataVersion versionToPassIn = null;
            if (isTargetFqn && !workspace.isVersioningImplicit()) versionToPassIn = version;

            NodeSPI newUnderlyingChildNode = workspaceNode.createChild(childName, workspaceNode.getNode(), cache, versionToPassIn);

            // now assign "workspaceNode" to the new child created.
            workspaceNode = lockAndCreateWorkspaceNode(nodeFactory, newUnderlyingChildNode, workspace, gtx, lockAcquisitionTimeout);
            workspaceNode.setVersioningImplicit(versionToPassIn == null || !isTargetFqn);
            if (trace)
View Full Code Here

      node.getLock().releaseAll();
   }

   public boolean ownsLock(Fqn fqn, LockType lockType, Object owner)
   {
      NodeSPI n = dataContainer.peek(fqn, true, true);
      if (n == null) return false;
      NodeLock lock = n.getLock();
      switch (lockType)
      {
         case READ:
            return lock.isReadLocked() && lock.isOwner(owner);
         case WRITE:
View Full Code Here

      boolean created = false;
      // if the tx associated with the current thread is rolling back, barf! JBCACHE-923
      if (gtx != null) TransactionTable.assertTransactionValid(ctx);

      Object owner = (gtx != null) ? gtx : currentThread;
      NodeSPI currentNode;
      if (trace) log.trace("Attempting to lock node " + fqn + " for owner " + owner);
      long expiryTime = System.currentTimeMillis() + timeout;
      currentNode = rootNode;
      NodeSPI parent = null;
      Object childName = null;
      int currentIndex = -1;
      int targetFqnSize = fqn.size();

      do
      {
         if (currentNode == null)
         {
            if (createIfNotExists)
            {
               // if the new node is to be marked as deleted, do not notify!
               currentNode = parent.addChildDirect(childName, !skipNotification);
               created = true;
               if (trace) log.trace("Child node was null, so created child node " + childName);
               if (createdNodes != null) createdNodes.add(currentNode);
            }
            else
            {
               if (trace)
                  log.trace("failed to find or create child " + childName + " of node " + parent);
               return false;
            }
         }
         else
         {
            if (!currentNode.isValid() && createIfNotExists) currentNode.setValid(true, false);
         }

         LockType lockTypeRequired = LockType.READ;
         if (created || writeLockNeeded(ctx, lockType, currentIndex, acquireWriteLockOnParent, createIfNotExists, fqn, currentNode))
         {
            lockTypeRequired = WRITE;
         }

         Fqn currentNodeFqn = currentNode.getFqn();
         // actually acquire the lock we need.  This method blocks.
         acquireNodeLock(ctx, currentNode, owner, lockTypeRequired, timeout);

         LockUtil.manageReverseRemove(ctx, currentNode, reverseRemoveCheck, createdNodes, commandsFactory);
         // make sure the lock we acquired isn't on a deleted node/is an orphan!!
         // look into invalidated nodes as well
         NodeSPI repeek = dataContainer.peek(currentNodeFqn, true, true);
         if (currentNode != repeek)
         {
            if (trace)
               log.trace("Was waiting for and obtained a lock on a node that doesn't exist anymore!  Attempting lock acquisition again.");
            // we have an orphan!! Lose the unnecessary lock and re-acquire the lock (and potentially recreate the node).
View Full Code Here

      // DON'T make a remote call if this is a remote call in the first place - leads to deadlocks - JBCACHE-1103
      if (!isCacheReady() || !cache.getInvocationContext().isOriginLocal()) return null;
      lock.acquireLock(name, true);
      try
      {
         NodeSPI n = cache.peek(name, false);
         if (n == null)
         {
            GetKeyValueCommand command = commandsFactory.buildGetKeyValueCommand(name, key, true);
            return callRemote(command);
         }
         else
         {
            // dont bother with a remote call
            return n.getDirect(key);
         }
      }
      finally
      {
         lock.releaseLock(name);
View Full Code Here

      // DON'T make a remote call if this is a remote call in the first place - leads to deadlocks - JBCACHE-1103
      if (!isCacheReady() || !cache.getInvocationContext().isOriginLocal()) return false;
      lock.acquireLock(name, true);
      try
      {
         NodeSPI n = cache.peek(name, true);
         if (n == null)
         {
            GetKeyValueCommand command = commandsFactory.buildGetKeyValueCommand(name, key, true);
            return callRemote(command);
         }
         else
         {
            // dont bother with a remote call
            return n.getDirect(key);
         }
      }
      finally
      {
         lock.releaseLock(name);
View Full Code Here

      if (canProvideState && (fetchPersistentState || fetchTransientState))
      {
         marshaller.objectToObjectStream(true, out);
         long startTime = System.currentTimeMillis();
         NodeSPI rootNode = cache.peek(fqn, false, false);

         try
         {
            if (log.isDebugEnabled())
            {
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.