Package org.jboss.cache.optimistic

Examples of org.jboss.cache.optimistic.TransactionWorkspace



   @Override
   public Object visitMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable
   {
      TransactionWorkspace workspace = getTransactionWorkspace(ctx);
      WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace, true, true);
      if (ctx.isOriginLocal() && ctx.getOptionOverrides() != null && ctx.getOptionOverrides().getDataVersion() != null)
      {
         throw new CacheException("Setting a data version while performing a move() is not supported!!");
      }
View Full Code Here


   }

   @Override
   public Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable
   {
      TransactionWorkspace workspace = getTransactionWorkspace(ctx);
      WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace, true, true);

      if (workspaceNode != null)
      {
         setVersioning(ctx, workspace, workspaceNode);
View Full Code Here

   }

   @Override
   public Object visitClearDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable
   {
      TransactionWorkspace workspace = getTransactionWorkspace(ctx);
      WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace, true, true);
      if (workspaceNode != null)
      {
         setVersioning(ctx, workspace, workspaceNode);
      }
View Full Code Here

   }

   @Override
   public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
   {
      TransactionWorkspace workspace = getTransactionWorkspace(ctx);
      Object result;
      WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace, false, false);

      if (workspaceNode == null)
      {
         if (trace) log.debug("Unable to find node " + command.getFqn() + " in workspace.");
         result = null;
      }
      else
      {
         //add this node into the wrokspace
         notifier.notifyNodeVisited(command.getFqn(), true, ctx);
         Object val = workspaceNode.get(command.getKey());
         workspace.addNode(workspaceNode);
         notifier.notifyNodeVisited(command.getFqn(), false, ctx);
         result = val;
      }
      return result;
   }
View Full Code Here

   }

   @Override
   public Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable
   {
      TransactionWorkspace workspace = getTransactionWorkspace(ctx);
      Object result;
      Fqn fqn = command.getFqn();
      WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, fqn, workspace, false, false);
      if (workspaceNode == null)
      {
         if (trace) log.trace("unable to find node " + fqn + " in workspace.");
         result = null;
      }
      else
      {
         notifier.notifyNodeVisited(fqn, true, ctx);
         Object keySet = workspaceNode.getKeys();
         workspace.addNode(workspaceNode);
         notifier.notifyNodeVisited(fqn, false, ctx);
         result = keySet;
      }
      return result;
   }
View Full Code Here

   }

   @Override
   public Object visitGetDataMapCommand(InvocationContext ctx, GetDataMapCommand command) throws Throwable
   {
      TransactionWorkspace workspace = getTransactionWorkspace(ctx);
      Object result;
      WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace, false, false);
      if (workspaceNode == null)
      {
         if (trace) log.trace("unable to find node " + command.getFqn() + " in workspace.");
         result = null;
      }
      else
      {
         notifier.notifyNodeVisited(command.getFqn(), true, ctx);
         Object data = workspaceNode.getData();
         workspace.addNode(workspaceNode);
         notifier.notifyNodeVisited(command.getFqn(), false, ctx);
         result = data;
      }
      return result;
   }
View Full Code Here

   }

   @Override
   public Object visitGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable
   {
      TransactionWorkspace workspace = getTransactionWorkspace(ctx);
      Object result;
      WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace, false, false);
      if (workspaceNode == null)
      {
         if (trace) log.trace("Unable to find node " + command.getFqn() + " in workspace.");
         result = null;
      }
      else
      {
         notifier.notifyNodeVisited(command.getFqn(), true, ctx);
         Object nameSet = workspaceNode.getChildrenNames();
         workspace.addNode(workspaceNode);
         notifier.notifyNodeVisited(command.getFqn(), false, ctx);
         result = nameSet;
      }
      return result;
   }
View Full Code Here

   }

   @Override
   public Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
   {
      TransactionWorkspace workspace = getTransactionWorkspace(ctx);
      Object result;
      WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, command.getFqn(), workspace, false, false);
      if (workspaceNode == null)
      {
         if (trace) log.trace("Unable to find node " + command.getFqn() + " in workspace.");
         result = null;
      }
      else if (workspaceNode.isRemoved())
      {
         if (trace) log.trace("Attempted to retrieve node " + command.getFqn() + " but it has been deleted!");
         result = null;
      }
      else
      {
         notifier.notifyNodeVisited(command.getFqn(), true, ctx);
         workspace.addNode(workspaceNode);
         notifier.notifyNodeVisited(command.getFqn(), false, ctx);
         result = workspaceNode.getNode();
      }
      return result;
   }
View Full Code Here

      if (targetFqn == null) return;

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

         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)
               log.trace("setting versioning of " + workspaceNode.getFqn() + " to be " + (workspaceNode.isVersioningImplicit() ? "implicit" : "explicit"));

            // now add the wrapped child node into the transaction space
            workspace.addNode(workspaceNode);
            workspaceNode.markAsCreated();
            // save in list so we can broadcast our created nodes outside
            // the synch block
            nodesCreated.add(workspaceNode.getFqn());
         }
         else
         {
            // node does exist but might not be in the workspace
            workspaceNode = workspace.getNode(currentNode.getFqn());
            // wrap it up so we can put it in later if we need to
            if (workspaceNode == null)
            {
               if (trace)
                  log.trace("Child node " + currentNode.getFqn() + " doesn't exist in workspace or has been deleted.  Adding to workspace in gtx " + gtx);

               workspaceNode = lockAndCreateWorkspaceNode(nodeFactory, currentNode, workspace, gtx, lockAcquisitionTimeout);

               // if the underlying node is a tombstone then mark the workspace node as newly created
               if (!currentNode.isValid()) workspaceNode.markAsCreated();

               if (isTargetFqn && !workspace.isVersioningImplicit())
               {
                  workspaceNode.setVersion(version);
                  workspaceNode.setVersioningImplicit(false);
               }
               else
               {
                  workspaceNode.setVersioningImplicit(true);
               }
               if (trace)
                  log.trace("setting versioning of " + workspaceNode.getFqn() + " to be " + (workspaceNode.isVersioningImplicit() ? "implicit" : "explicit"));
               workspace.addNode(workspaceNode);
            }
            else if (workspaceNode.isRemoved())
            {
               if (trace) log.trace("Found node but it is deleted in this workspace.  Needs resurrecting.");
               undeleteWorkspaceNode(workspaceNode, workspace);
View Full Code Here

        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);
                    }
                    else
                    {
                        if (log.isTraceEnabled()) log.trace(" Parent node " + workspaceNode.getFqn() + " exists in workspace " + gtx);
                    }
                    copy = (Fqn) tmpFqn.clone();
                    // this does not add it into the real child nodes - but in its
                    // local child map for the transaction

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

                    DataNode tempNode = (DataNode) workspaceNode.createChild(childName, copy, workspaceNode.getNode(), cache, versionToPassIn);

                    childWorkspaceNode = NodeFactory.getInstance().createWorkspaceNode(tempNode, workspace);
                   childWorkspaceNode.setVersioningImplicit(versionToPassIn == null || !isTargetFqn);
                   if (log.isTraceEnabled()) log.trace("setting versioning of " + childWorkspaceNode.getFqn() + " to be " + (childWorkspaceNode.isVersioningImplicit() ? "implicit" : "explicit"));

                    // now add the wrapped child node into the transaction space
                    workspace.addNode(childWorkspaceNode);
                    childWorkspaceNode.markAsCreated();
                    // save in list so we can broadcast our created nodes outside
                    // the synch block
                    nodesCreated.add(tmpFqn);

                }
                else
                {
                    // node does exist but might not be in the workspace
                    childWorkspaceNode = workspace.getNode(tempChildNode.getFqn());
                    // wrap it up so we can put it in later if we need to
                    if (childWorkspaceNode == null || childWorkspaceNode.isDeleted())
                    {
                        if (log.isDebugEnabled()) log.debug("Child node "+tempChildNode.getFqn()+" doesn't exist in workspace or has been deleted.  Adding to workspace in gtx " + gtx);
                        childWorkspaceNode = NodeFactory.getInstance().createWorkspaceNode(tempChildNode, workspace);
                        if (isTargetFqn && !workspace.isVersioningImplicit())
                        {
                           childWorkspaceNode.setVersion(version);
                           childWorkspaceNode.setVersioningImplicit(false);
                        }
                       else
View Full Code Here

TOP

Related Classes of org.jboss.cache.optimistic.TransactionWorkspace

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.