Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2008, Red Hat Middleware LLC, and individual contributors
   * as indicated by the @author tags.
   * See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   * This copyrighted material is made available to anyone wishing to use,
   * modify, copy, or redistribute it subject to the terms and conditions
   * of the GNU Lesser General Public License, v. 2.1.
  * This program is distributed in the hope that it will be useful, but WITHOUT A
  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
  * You should have received a copy of the GNU Lesser General Public License,
  * v.2.1 along with this distribution; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  * MA  02110-1301, USA.
  *
  * (C) 2008,
  * @author Red Hat Middleware LLC.
  */
 package com.arjuna.ats.internal.arjuna.objectstore;
 
 
Two phase volatile store. Allows for recoverable and shared object instances to participate in a transaction. Does not support all recovery methods that are specific to persistent (durable) object stores.

Author(s):
marklittle
 
 
 public class TwoPhaseVolatileStore extends ObjectStore
 {
     public TwoPhaseVolatileStore(ObjectStoreEnvironmentBean objectStoreEnvironmentBeanthrows ObjectStoreException 
     {
         super(objectStoreEnvironmentBean);
     }

    
Obtain all of the Uids for a specified type.

Parameters:
s The type to scan for.
buff The object state in which to store the Uids
m The file type to look for (e.g., committed, shadowed).
Returns:
true if no errors occurred, false otherwise.
 
 
     public boolean allObjUids(String sInputObjectState buffint mthrows ObjectStoreException
     {
         throw new ObjectStoreException("Operation not supported by this implementation");
     }

    
Obtain all types of objects stored in the object store.

Parameters:
buff The state in which to store the types.
Returns:
true if no errors occurred, false otherwise.
 
 
     public boolean allTypes(InputObjectState buffthrows ObjectStoreException
     {
         throw new ObjectStoreException("Operation not supported by this implementation");
     }

    

Parameters:
u The object to query.
tn The type of the object to query.
Returns:
the current state of the object's state (e.g., shadowed, committed ...)
 
 
     public int currentState(Uid uString tnthrows ObjectStoreException
     {
         if (..isTraceEnabled()) {
             ..trace("TwoPhaseVolatileStore.currentState(Uid=" + u + ", typeName=" + tn + ")");
         }
 
         StateInstance inst = .get(u);
         
         if (inst != null)
         {
             if (inst.original != null)
                 return .;
             else
             {
                if (inst.shadow != null)
                    return .;
            }
        }
        
        return .;
    }

    

Returns:
the name of the object store.
    public String getStoreName()
    {
        return "TwoPhaseVolatileStore";
    }

    
Commit the object's state in the object store.

Parameters:
u The object to work on.
tn The type of the object to work on.
Returns:
true if no errors occurred, false otherwise.
    public boolean commit_state(Uid uString tnthrows ObjectStoreException
    {
        synchronized ()
        {
            StateInstance inst = .get(u);
            if (inst == null)
                throw new ObjectStoreException("Could not find state instance to commit!");
            synchronized (inst)
            {
                if (inst.shadow != null)
                {
                    inst.original = inst.shadow;
                    inst.shadow = null;
                    inst.owner = null;
                    
                    return true;
                }
                else
                    return false;
            }
        }
    }

    
Hide the object's state in the object store. Used by crash recovery.

Parameters:
u The object to work on.
tn The type of the object to work on.
Returns:
true if no errors occurred, false otherwise.
    public boolean hide_state(Uid uString tnthrows ObjectStoreException
    {
        throw new ObjectStoreException("Operation not supported by this implementation");
    }

    
Reveal a hidden object's state.

Parameters:
u The object to work on.
tn The type of the object to work on.
Returns:
true if no errors occurred, false otherwise.
    public boolean reveal_state(Uid uString tnthrows ObjectStoreException
    {
        throw new ObjectStoreException("Operation not supported by this implementation");
    }

    
Read the object's committed state.

Parameters:
u The object to work on.
tn The type of the object to work on.
Returns:
the state of the object.
    {
        if (..isTraceEnabled()) {
            ..trace("TwoPhaseVolatileStore.read_committed(Uid=" + u + ", typeName=" + tn + ")");
        }
 
        synchronized ()
        {
            StateInstance inst = .get(u);
            if (inst == null)
                return null;
            synchronized (inst)
            {
                if ((inst.original != null) && ((inst.owner == null) || (inst.owner == Thread.currentThread())))
                {
                    return new InputObjectState(inst.original);
                }
                else
                    return null;
            }
        }
    }

    
Read the object's shadowed state.

Parameters:
u The object to work on.
tn The type of the object to work on.
Returns:
the state of the object.
    {
        synchronized ()
        {
            StateInstance inst = .get(u);
            if (inst == null)
                return null;
            synchronized (inst)
            {
                if ((inst.shadow != null) && ((inst.owner == null) || (inst.owner == Thread.currentThread())))
                {
                    return new InputObjectState(inst.shadow);
                }
                else
                    return null;
            }
        }
    }

    
Remove the object's committed state.

Parameters:
u The object to work on.
tn The type of the object to work on.
Returns:
true if no errors occurred, false otherwise.
    public boolean remove_committed(Uid uString tnthrows ObjectStoreException
    {
        if (..isTraceEnabled()) {
            ..trace("TwoPhaseVolatileStore.remove_committed(Uid=" + u + ", typeName=" + tn + ")");
        }
        synchronized ()
        {
            StateInstance inst = .get(u);
            if (inst == null)
                return false;
            synchronized (inst)
            {
                if ((inst.original != null) && (inst.owner == Thread.currentThread()))
                {
                    inst.original = null;
                    inst.owner = null;
                    
                    return true;
                }
                else
                    return false;
            }
        }
    }

    
Remove the object's uncommitted state.

Parameters:
u The object to work on.
tn The type of the object to work on.
Returns:
true if no errors occurred, false otherwise.
    public boolean remove_uncommitted(Uid uString tnthrows ObjectStoreException
    {
        synchronized ()
        {
            StateInstance inst = .get(u);
            if (inst == null)
                return false;
            synchronized (inst)
            {
                if ((inst.shadow != null) && (inst.owner == Thread.currentThread()))
                {
                    inst.shadow = null;
                    inst.owner = null;
                    
                    return true;
                }
                else
                    return false;
            }
        }
    }

    
Write a new copy of the object's committed state.

Parameters:
u The object to work on.
tn The type of the object to work on.
buff The state to write.
Returns:
true if no errors occurred, false otherwise.
    public boolean write_committed(Uid uString tnOutputObjectState buffthrows ObjectStoreException
    {
        if (..isTraceEnabled()) {
            ..trace("TwoPhaseVolatileStore.write_committed(Uid=" + u + ", typeName=" + tn + ")");
        }
        synchronized ()
        {
            StateInstance inst = .get(u);
            if (inst == null)
            {
                .put(u,  new StateInstance(buffnulltnu, Thread.currentThread()));
            }
            else
            {
                synchronized (inst)
                {
                    if (inst.original == null)
                    {
                        inst.original = buff;
                        inst.owner = Thread.currentThread();
                    }
                    else
                        return false;
                }
            }
            
            return true;
        }
    }

    
Write a copy of the object's uncommitted state.

Parameters:
u The object to work on.
tn The type of the object to work on.
buff The state to write.
Returns:
true if no errors occurred, false otherwise.
    public boolean write_uncommitted(Uid uString tnOutputObjectState buffthrows ObjectStoreException
    {
        synchronized ()
        {
            StateInstance inst = .get(u);
            if (inst == null)
            {
                inst = new StateInstance(nullbufftnu, Thread.currentThread());
                
                .put(uinst);
            }
            else
            {
                if (inst.shadow != null)
                {
                    return false// probably another thread trying to commit optimistically.
                }
                else              
                {
                    inst.shadow = buff;
                    inst.owner = Thread.currentThread();
                }
            }
    
            return true;
        }
    }

    
Suppress directories of the specified type from allTypes etc?
    protected boolean supressEntry(String name)
    {
        return false;
    }
    
    private class StateInstance
    {
        public StateInstance (OutputObjectState origOutputObjectState sdString tnUid uThread o)
        {
             = orig;
             = sd;
             = tn;
             = u;
             = o;
        }
        
        public String toString ()
        {
            return "StateInstance < original "+( == null ? "empty" : "present")+", shadow "+( == null ? "empty" : "present")+", "++" "++", "++" >";
        }
        
        public OutputObjectState original;
        public OutputObjectState shadow;
        public String typeName;
        public Uid uid;
        public Thread owner;
    }
    
    /*
     * This could potentially grow indefinitely. Place a limit on the size?
     */
    
    //private WeakHashMap<Uid, StateInstance> _stateMap = new WeakHashMap<Uid, StateInstance>();
    
New to GrepCode? Check out our FAQ X