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;
 
 
An in-memory ObjectStore that never writes to stable storage. Useless for most production apps, but handy for some performance testing cases. Does not support crash recovery methods as there is no stable state to recover.

Author(s):
Jonathan Halliday (jonathan.halliday@redhat.com), 2008-10
 
 public class VolatileStore extends ObjectStore
 {
     public VolatileStore(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("VolatileStore.currentState(Uid=" + u + ", typeName=" + tn + ")");
         }
 
         return getState(u);
     }

    

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

    
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
    {
        throw new ObjectStoreException("Operation not supported by this implementation");
    }

    
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("VolatileStore.read_committed(Uid=" + u + ", typeName=" + tn + ")");
        }
        return read(utn.);
    }

    
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.
    {
        throw new ObjectStoreException("Operation not supported by this implementation");
    }

    
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("VolatileStore.remove_committed(Uid=" + u + ", typeName=" + tn + ")");
        }
        return remove(utn.);
    }

    
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
    {
        throw new ObjectStoreException("Operation not supported by this implementation");
    }

    
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("VolatileStore.write_committed(Uid=" + u + ", typeName=" + tn + ")");
        }
        return write(utnbuff.);
    }

    
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
    {
        throw new ObjectStoreException("Operation not supported by this implementation");
    }

    
Suppress directories of the specified type from allTypes etc?
    protected boolean supressEntry(String name)
    {
        return false;
    }
    ///////////////////////////////////////////
    /*
        Implementation notes:
          We assume Uid is globally unique, so we don't store or key on type name at all
          - it's only needed during recovery, which we obviously don't support.
          This implementation is intended to be memory efficient, as we also want to use it on small footprint devices.
          Hence we map Uid to a byte array rather than e.g. some more complex value class containing the byte[] state plus
            fields for ObjectStore state (committed/hidden etc) and typeName.
          In recent times we have been using this more for performance testing than small footprint installs.
          We therefore prefer ConcurrentHashMap, even though it's not available in J2ME. Fork from previous version
          that used synchronized Map if you want a build for small footprint environments.
          The byte[] array is simply the contents of the Object's state buffer.
    */
    private ConcurrentMap<Uidbyte[]> stateMap = new ConcurrentHashMap<Uidbyte[]>();
    private boolean remove(Uid uString tnint statethrows ObjectStoreException
    {
        Object oldValue = .remove(u);
        return (oldValue != null);
    }
    private InputObjectState read(Uid uString tnint statethrows ObjectStoreException
    {
        byte[] data = .get(u);
        if(data != null) {
            InputObjectState new_image = new InputObjectState(utndata);
            return new_image;
        } else {
            return null;
        }
    }
    private boolean write(Uid uString tnOutputObjectState buffint statethrows ObjectStoreException
    {
        .put(ubuff.buffer());
        return true;
    }
    private int getState(Uid u)
    {
        if(.containsKey(u)) {
            return .;
        } else {
            return .;
        }
    }
New to GrepCode? Check out our FAQ X