Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2010, Red Hat, Inc. and/or its affiliates,
   * 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) 2010,
  * @author JBoss, by Red Hat.
  */
 package com.arjuna.ats.internal.arjuna.objectstore.hornetq;
 
 import java.util.Set;
 
 
 /* transaction-jboss-beans.xml:
 
     <bean name="HornetqJournalEnvironmentBean" class="com.arjuna.ats.internal.arjuna.objectstore.hornetq.HornetqJournalEnvironmentBean">
         <property name="storeDir">${jboss.server.data.dir}/tx-object-store/HornetqJournalStore</property>
     </bean>
     <bean name="HornetqJournalStore" class="com.arjuna.ats.internal.arjuna.objectstore.hornetq.HornetqJournalStore">
         <constructor>
             <parameter><inject bean="HornetqJournalEnvironmentBean"/></parameter>
         </constructor>
     </bean>
     <bean name="HornetqObjectStoreAdaptor" class="com.arjuna.ats.internal.arjuna.objectstore.hornetq.HornetqObjectStoreAdaptor">
         <constructor>
             <parameter><inject bean="HornetqJournalStore"/></parameter>
         </constructor>
     </bean>
     <bean name="TxStoreManager" class="com.arjuna.ats.arjuna.objectstore.StoreManager">
         <constructor>
             <parameter><inject bean="HornetqObjectStoreAdaptor"/></parameter>
             <parameter><null/></parameter>
         </constructor>
     </bean>
 
     plus RecMgr/TxMgr lifecycle deps
 
 */

Adaptor class that wraps the store to make it look like an ObjectStore.

Author(s):
Jonathan Halliday (jonathan.halliday@redhat.com), 2010-03
 
 public class HornetqObjectStoreAdaptor implements ObjectStoreAPI
 {
     private final HornetqJournalStore store;
 
     // used for standalone bootstrap via StoreManager
     public HornetqObjectStoreAdaptor() throws IOException {
 
         HornetqJournalEnvironmentBean envBean = BeanPopulator.getDefaultInstance(HornetqJournalEnvironmentBean.class);
 
         this. = new HornetqJournalStore(envBean);
     }
 
     // used for beans wiring type bootstrap when running embedded.
         this. = store;
     }
 
     @Override
     public void start()
     {
         if(..isTraceEnabled()) {
             ..trace("HornetqObjectStore.start()");
         }
 
         try {
             .start();
         } catch(Exception e) {
             throw new RuntimeException(e);
         }
     }
 
    @Override
    public void stop()
    {
        if(..isTraceEnabled()) {
            ..trace("HornetqObjectStore.stop()");
        }
        try {
            .stop();
        } catch(Exception e) {
            throw new RuntimeException(e);
        }
    }

    
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.
    @Override
    {
    }

    
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.
    @Override
    public boolean remove_uncommitted(Uid uString tnthrows ObjectStoreException
    {
    }
    private String ensureTypenamePrefix(String typeName)
    {
        if(!typeName.startsWith("/")) {
            typeName = "/"+typeName;
        }
        return typeName;
    }

    
Read the object's committed state.

Parameters:
u The object to work on.
typeName The type of the object to work on.
Returns:
the state of the object.
    @Override
    public InputObjectState read_committed(Uid uString typeNamethrows ObjectStoreException
    {
        if(..isTraceEnabled()) {
            ..trace("HornetqObjectStore.read_committed("+u+", "+typeName+")");
        }
        typeName = ensureTypenamePrefix(typeName);
        return .read_committed(utypeName);
    }

    
Remove the object's committed state.

Parameters:
u The object to work on.
typeName The type of the object to work on.
Returns:
true if no errors occurred, false otherwise.
    @Override
    public boolean remove_committed(Uid uString typeNamethrows ObjectStoreException
    {
        if(..isTraceEnabled()) {
            ..trace("HornetqObjectStore.remove_committed("+u+", "+typeName+")");
        }
        typeName = ensureTypenamePrefix(typeName);
        return .remove_committed(utypeName);
    }

    
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.
    @Override
    public boolean hide_state(Uid uString tnthrows ObjectStoreException
    {
    }

    
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.
    @Override
    public boolean reveal_state(Uid uString tnthrows ObjectStoreException
    {
    }

    
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.
    @Override
    public boolean commit_state(Uid uString tnthrows ObjectStoreException
    {
    }

    

Parameters:
u The object to query.
typeName The type of the object to query.
Returns:
the current state of the object's state (e.g., shadowed, committed ...) [StateStatus]
    @Override
    public int currentState(Uid uString typeNamethrows ObjectStoreException
    {
        if(..isTraceEnabled()) {
            ..trace("HornetqObjectStore.currentState("+u+", "+typeName+")");
        }
        typeName = ensureTypenamePrefix(typeName);
        if.contains(utypeName)) {
            return .;
        } else {
            return .;
        }
    }


    
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.
    @Override
    public boolean write_uncommitted(Uid uString tnOutputObjectState buffthrows ObjectStoreException
    {
    }

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

Parameters:
u The object to work on.
typeName The type of the object to work on.
buff The state to write.
Returns:
true if no errors occurred, false otherwise.
    @Override
    public boolean write_committed(Uid uString typeNameOutputObjectState buffthrows ObjectStoreException
    {
        if(..isTraceEnabled()) {
            ..trace("HornetqObjectStore.write_committed("+u+", "+typeName+")");
        }
        typeName = ensureTypenamePrefix(typeName);
        return .write_committed(utypeNamebuff);
    }
    @Override
    public boolean allObjUids(String typeNameInputObjectState foundInstancesthrows ObjectStoreException
    {
        if(..isTraceEnabled()) {
            ..trace("HornetqObjectStore.allObjUids("+typeName+")");
        }
        typeName = ensureTypenamePrefix(typeName);
        return allObjUids(typeNamefoundInstances.);
    }

    
Obtain all of the Uids for a specified type.

Parameters:
typeName The type to scan for.
foundInstances The object state in which to store the Uids
matchState The file type to look for (e.g., committed, shadowed). [StateStatus]
Returns:
true if no errors occurred, false otherwise.
    @Override
    public boolean allObjUids(String typeNameInputObjectState foundInstancesint matchStatethrows ObjectStoreException
    {
        if(..isTraceEnabled()) {
            ..trace("HornetqObjectStore.allObjUids("+typeName+", "+matchState+")");
        }
        boolean result = true;
        typeName = ensureTypenamePrefix(typeName);
        Uid[] uids = .getUidsForType(typeName); // may contain trailing null elements
        OutputObjectState buffer = new OutputObjectState();
        try
        {
            if(uids != null && (matchState == . || matchState == .))
            {
                for (Uid uiduids)
                {
                    if(uid != null) {
                        UidHelper.packInto(uidbuffer);
                    }
                }
            }
            UidHelper.packInto(Uid.nullUid(), buffer);
        }
        catch (IOException e)
        {
            throw new ObjectStoreException(e);
        }
        foundInstances.setBuffer(buffer.buffer());
        return result;
    }


    
Obtain all types of objects stored in the object store.

Parameters:
foundTypes The state in which to store the types.
Returns:
true if no errors occurred, false otherwise.
    @Override
    public boolean allTypes(InputObjectState foundTypesthrows ObjectStoreException
    {
        if(..isTraceEnabled()) {
            ..trace("HornetqObjectStore.allTypes()");
        }
        boolean result = true;
        String[] knownTypes = .getKnownTypes(); // may contain trailing null elements
        Set<StringtypeSet = new HashSet<String>();
        if (knownTypes == null || knownTypes.length == 0)
            return true;
        OutputObjectState buffer = new OutputObjectState();
        try
        {
            for (String typeNameknownTypes)
            {
                if(typeName == null) {
                    continue;
                }
                if(typeName.startsWith("/")) {
                    typeName = typeName.substring(1);
                }
                if(typeName.contains("/")) {
                    String value = "";
                    String[] parents = typeName.split("/");
                    for(String parent : parents) {
                        if(parent.length() == 0) {
                            continue;
                        }
                        if(value.length() > 0) {
                            value = value+"/";
                        }
                        value = value+parent;
                        if(!typeSet.contains(value)) {
                            typeSet.add(value);
                            buffer.packString(value);
                        }
                    }
                } else {
                    buffer.packString(typeName);
                }
            }
            buffer.packString("");
        }
        catch (IOException e)
        {
            throw new ObjectStoreException(e);
        }
        foundTypes.setBuffer(buffer.buffer());
        return result;
    }

    
Some object store implementations may be running with automatic sync disabled. Calling this method will ensure that any states are flushed to disk.
    @Override
    public void sync() throws SyncFailedExceptionObjectStoreException
    {
        // null-op in this impl.
    }

    

Returns:
the "name" of the object store. Where in the hierarchy it appears, e.g., /ObjectStore/MyName/...
    @Override
    public String getStoreName()
    {
        return .getStoreName();
    }
    @Override
    public boolean fullCommitNeeded()
    {
        return false;
    }

    
Is the current state of the object the same as that provided as the last parameter?

Parameters:
u The object to work on.
tn The type of the object.
st The expected type of the object. [StateType]
Returns:
true if the current state is as expected, false otherwise.
    @Override
    public boolean isType(Uid uString tnint stthrows ObjectStoreException
    {
        return false;
    }
New to GrepCode? Check out our FAQ X