activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r563982 [7/32] - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/ main/java/org/apache/activemq/advisory/ main/java/org/apache/activemq/blob/ main/java/org/apache/activemq/broker/ main/java/org/apache/activemq/broker/jmx...
Date Wed, 08 Aug 2007 18:58:13 GMT
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java?view=diff&rev=563982&r1=563981&r2=563982
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java Wed Aug  8 11:56:59 2007
@@ -40,15 +40,14 @@
  * 
  * @version $Revision: 1.2 $
  */
-public class ListContainerImpl extends BaseContainerImpl implements ListContainer{
+public class ListContainerImpl extends BaseContainerImpl implements ListContainer {
 
-    private static final Log log=LogFactory.getLog(ListContainerImpl.class);
-    protected Marshaller marshaller=Store.ObjectMarshaller;
-   
-
-    public ListContainerImpl(ContainerId id,IndexItem root,IndexManager indexManager,DataManager dataManager,
-            boolean persistentIndex) throws IOException{
-        super(id,root,indexManager,dataManager,persistentIndex);
+    private static final Log log = LogFactory.getLog(ListContainerImpl.class);
+    protected Marshaller marshaller = Store.ObjectMarshaller;
+
+    public ListContainerImpl(ContainerId id, IndexItem root, IndexManager indexManager,
+                             DataManager dataManager, boolean persistentIndex) throws IOException {
+        super(id, root, indexManager, dataManager, persistentIndex);
     }
 
     /*
@@ -56,22 +55,22 @@
      * 
      * @see org.apache.activemq.kaha.ListContainer#load()
      */
-    public synchronized void load(){
+    public synchronized void load() {
         checkClosed();
-        if(!loaded){
-            if(!loaded){
-                loaded=true;
-                try{
+        if (!loaded) {
+            if (!loaded) {
+                loaded = true;
+                try {
                     init();
-                    long nextItem=root.getNextItem();
-                    while(nextItem!=Item.POSITION_NOT_SET){
-                        IndexItem item=indexManager.getIndex(nextItem);
+                    long nextItem = root.getNextItem();
+                    while (nextItem != Item.POSITION_NOT_SET) {
+                        IndexItem item = indexManager.getIndex(nextItem);
                         indexList.add(item);
-                        itemAdded(item,indexList.size()-1,getValue(item));
-                        nextItem=item.getNextItem();
+                        itemAdded(item, indexList.size() - 1, getValue(item));
+                        nextItem = item.getNextItem();
                     }
-                }catch(IOException e){
-                    log.error("Failed to load container "+getId(),e);
+                } catch (IOException e) {
+                    log.error("Failed to load container " + getId(), e);
                     throw new RuntimeStoreException(e);
                 }
             }
@@ -83,12 +82,12 @@
      * 
      * @see org.apache.activemq.kaha.ListContainer#unload()
      */
-    public synchronized void unload(){
+    public synchronized void unload() {
         checkClosed();
-        if(loaded){
-            loaded=false;
+        if (loaded) {
+            loaded = false;
             indexList.clear();
-            
+
         }
     }
 
@@ -97,23 +96,23 @@
      * 
      * @see org.apache.activemq.kaha.ListContainer#setKeyMarshaller(org.apache.activemq.kaha.Marshaller)
      */
-    public synchronized void setMarshaller(Marshaller marshaller){
+    public synchronized void setMarshaller(Marshaller marshaller) {
         checkClosed();
-        this.marshaller=marshaller;
+        this.marshaller = marshaller;
     }
 
-    public synchronized boolean equals(Object obj){
+    public synchronized boolean equals(Object obj) {
         load();
-        boolean result=false;
-        if(obj!=null&&obj instanceof List){
-            List other=(List)obj;
-            result=other.size()==size();
-            if(result){
-                for(int i=0;i<indexList.size();i++){
-                    Object o1=other.get(i);
-                    Object o2=get(i);
-                    result=o1==o2||(o1!=null&&o2!=null&&o1.equals(o2));
-                    if(!result){
+        boolean result = false;
+        if (obj != null && obj instanceof List) {
+            List other = (List)obj;
+            result = other.size() == size();
+            if (result) {
+                for (int i = 0; i < indexList.size(); i++) {
+                    Object o1 = other.get(i);
+                    Object o2 = get(i);
+                    result = o1 == o2 || (o1 != null && o2 != null && o1.equals(o2));
+                    if (!result) {
                         break;
                     }
                 }
@@ -121,7 +120,7 @@
         }
         return result;
     }
-    
+
     public int hashCode() {
         return super.hashCode();
     }
@@ -131,7 +130,7 @@
      * 
      * @see org.apache.activemq.kaha.ListContainer#size()
      */
-    public synchronized int size(){
+    public synchronized int size() {
         load();
         return indexList.size();
     }
@@ -141,7 +140,7 @@
      * 
      * @see org.apache.activemq.kaha.ListContainer#addFirst(java.lang.Object)
      */
-    public synchronized void addFirst(Object o){
+    public synchronized void addFirst(Object o) {
         internalAddFirst(o);
     }
 
@@ -150,7 +149,7 @@
      * 
      * @see org.apache.activemq.kaha.ListContainer#addLast(java.lang.Object)
      */
-    public synchronized void addLast(Object o){
+    public synchronized void addLast(Object o) {
         internalAddLast(o);
     }
 
@@ -159,19 +158,19 @@
      * 
      * @see org.apache.activemq.kaha.ListContainer#removeFirst()
      */
-    public synchronized Object removeFirst(){
+    public synchronized Object removeFirst() {
         load();
-        Object result=null;
-        IndexItem item=indexList.getFirst();
-        if(item!=null){
+        Object result = null;
+        IndexItem item = indexList.getFirst();
+        if (item != null) {
             itemRemoved(0);
-            result=getValue(item);
-            IndexItem prev=root;
-            IndexItem next=indexList.size()>1?(IndexItem)indexList.get(1):null;
+            result = getValue(item);
+            IndexItem prev = root;
+            IndexItem next = indexList.size() > 1 ? (IndexItem)indexList.get(1) : null;
             indexList.removeFirst();
-            
-            delete(item,prev,next);
-            item=null;
+
+            delete(item, prev, next);
+            item = null;
         }
         return result;
     }
@@ -181,17 +180,17 @@
      * 
      * @see org.apache.activemq.kaha.ListContainer#removeLast()
      */
-    public synchronized Object removeLast(){
+    public synchronized Object removeLast() {
         load();
-        Object result=null;
-        IndexItem last=indexList.getLast();
-        if(last!=null){
-            itemRemoved(indexList.size()-1);
-            result=getValue(last);
-            IndexItem prev=indexList.getPrevEntry(last);
-            IndexItem next=null;
+        Object result = null;
+        IndexItem last = indexList.getLast();
+        if (last != null) {
+            itemRemoved(indexList.size() - 1);
+            result = getValue(last);
+            IndexItem prev = indexList.getPrevEntry(last);
+            IndexItem next = null;
             indexList.removeLast();
-            delete(last,prev,next);
+            delete(last, prev, next);
         }
         return result;
     }
@@ -201,7 +200,7 @@
      * 
      * @see java.util.List#isEmpty()
      */
-    public synchronized boolean isEmpty(){
+    public synchronized boolean isEmpty() {
         load();
         return indexList.isEmpty();
     }
@@ -211,18 +210,18 @@
      * 
      * @see java.util.List#contains(java.lang.Object)
      */
-    public synchronized boolean contains(Object o){
+    public synchronized boolean contains(Object o) {
         load();
-        boolean result=false;
-        if(o!=null){
-            IndexItem next=indexList.getFirst();
-            while(next!=null){
-                Object value=getValue(next);
-                if(value!=null&&value.equals(o)){
-                    result=true;
+        boolean result = false;
+        if (o != null) {
+            IndexItem next = indexList.getFirst();
+            while (next != null) {
+                Object value = getValue(next);
+                if (value != null && value.equals(o)) {
+                    result = true;
                     break;
                 }
-                next=indexList.getNextEntry(next);
+                next = indexList.getNextEntry(next);
             }
         }
         return result;
@@ -233,7 +232,7 @@
      * 
      * @see java.util.List#iterator()
      */
-    public synchronized Iterator iterator(){
+    public synchronized Iterator iterator() {
         load();
         return listIterator();
     }
@@ -243,14 +242,14 @@
      * 
      * @see java.util.List#toArray()
      */
-    public synchronized Object[] toArray(){
+    public synchronized Object[] toArray() {
         load();
-        List tmp=new ArrayList(indexList.size());
-        IndexItem next=indexList.getFirst();
-        while(next!=null){
-            Object value=getValue(next);
+        List tmp = new ArrayList(indexList.size());
+        IndexItem next = indexList.getFirst();
+        while (next != null) {
+            Object value = getValue(next);
             tmp.add(value);
-            next=indexList.getNextEntry(next);
+            next = indexList.getNextEntry(next);
         }
         return tmp.toArray();
     }
@@ -260,14 +259,14 @@
      * 
      * @see java.util.List#toArray(T[])
      */
-    public synchronized Object[] toArray(Object[] a){
+    public synchronized Object[] toArray(Object[] a) {
         load();
-        List tmp=new ArrayList(indexList.size());
-        IndexItem next=indexList.getFirst();
-        while(next!=null){
-            Object value=getValue(next);
+        List tmp = new ArrayList(indexList.size());
+        IndexItem next = indexList.getFirst();
+        while (next != null) {
+            Object value = getValue(next);
             tmp.add(value);
-            next=indexList.getNextEntry(next);
+            next = indexList.getNextEntry(next);
         }
         return tmp.toArray(a);
     }
@@ -277,7 +276,7 @@
      * 
      * @see java.util.List#add(E)
      */
-    public synchronized boolean add(Object o){
+    public synchronized boolean add(Object o) {
         load();
         addLast(o);
         return true;
@@ -288,31 +287,31 @@
      * 
      * @see java.util.List#remove(java.lang.Object)
      */
-    public synchronized boolean remove(Object o){
+    public synchronized boolean remove(Object o) {
         load();
-        boolean result=false;
-        int pos=0;
-        IndexItem next=indexList.getFirst();
-        while(next!=null){
-            Object value=getValue(next);
-            if(value!=null&&value.equals(o)){
+        boolean result = false;
+        int pos = 0;
+        IndexItem next = indexList.getFirst();
+        while (next != null) {
+            Object value = getValue(next);
+            if (value != null && value.equals(o)) {
                 remove(next);
                 itemRemoved(pos);
-                result=true;
+                result = true;
                 break;
             }
-            next=indexList.getNextEntry(next);
+            next = indexList.getNextEntry(next);
             pos++;
         }
         return result;
     }
 
-    protected synchronized void remove(IndexItem item){
-        IndexItem prev=indexList.getPrevEntry(item);
-        IndexItem next=indexList.getNextEntry(item);
+    protected synchronized void remove(IndexItem item) {
+        IndexItem prev = indexList.getPrevEntry(item);
+        IndexItem next = indexList.getNextEntry(item);
         indexList.remove(item);
-        
-        delete(item,prev,next);
+
+        delete(item, prev, next);
     }
 
     /*
@@ -320,13 +319,13 @@
      * 
      * @see java.util.List#containsAll(java.util.Collection)
      */
-    public synchronized boolean containsAll(Collection c){
+    public synchronized boolean containsAll(Collection c) {
         load();
-        boolean result=false;
-        for(Iterator i=c.iterator();i.hasNext();){
-            Object obj=i.next();
-            if(!(result=contains(obj))){
-                result=false;
+        boolean result = false;
+        for (Iterator i = c.iterator(); i.hasNext();) {
+            Object obj = i.next();
+            if (!(result = contains(obj))) {
+                result = false;
                 break;
             }
         }
@@ -338,9 +337,9 @@
      * 
      * @see java.util.List#addAll(java.util.Collection)
      */
-    public synchronized boolean addAll(Collection c){
+    public synchronized boolean addAll(Collection c) {
         load();
-        for(Iterator i=c.iterator();i.hasNext();){
+        for (Iterator i = c.iterator(); i.hasNext();) {
             add(i.next());
         }
         return true;
@@ -351,14 +350,14 @@
      * 
      * @see java.util.List#addAll(int, java.util.Collection)
      */
-    public synchronized boolean addAll(int index,Collection c){
+    public synchronized boolean addAll(int index, Collection c) {
         load();
-        boolean result=false;
-        ListIterator e1=listIterator(index);
-        Iterator e2=c.iterator();
-        while(e2.hasNext()){
+        boolean result = false;
+        ListIterator e1 = listIterator(index);
+        Iterator e2 = c.iterator();
+        while (e2.hasNext()) {
             e1.add(e2.next());
-            result=true;
+            result = true;
         }
         return result;
     }
@@ -368,12 +367,12 @@
      * 
      * @see java.util.List#removeAll(java.util.Collection)
      */
-    public synchronized boolean removeAll(Collection c){
+    public synchronized boolean removeAll(Collection c) {
         load();
-        boolean result=true;
-        for(Iterator i=c.iterator();i.hasNext();){
-            Object obj=i.next();
-            result&=remove(obj);
+        boolean result = true;
+        for (Iterator i = c.iterator(); i.hasNext();) {
+            Object obj = i.next();
+            result &= remove(obj);
         }
         return result;
     }
@@ -383,18 +382,18 @@
      * 
      * @see java.util.List#retainAll(java.util.Collection)
      */
-    public synchronized boolean retainAll(Collection c){
+    public synchronized boolean retainAll(Collection c) {
         load();
-        List tmpList=new ArrayList();
-        IndexItem next=indexList.getFirst();
-        while(next!=null){
-            Object o=getValue(next);
-            if(!c.contains(o)){
+        List tmpList = new ArrayList();
+        IndexItem next = indexList.getFirst();
+        while (next != null) {
+            Object o = getValue(next);
+            if (!c.contains(o)) {
                 tmpList.add(o);
             }
-            next=indexList.getNextEntry(next);
+            next = indexList.getNextEntry(next);
         }
-        for(Iterator i=tmpList.iterator();i.hasNext();){
+        for (Iterator i = tmpList.iterator(); i.hasNext();) {
             remove(i.next());
         }
         return !tmpList.isEmpty();
@@ -405,11 +404,11 @@
      * 
      * @see java.util.List#clear()
      */
-    public synchronized void clear(){
+    public synchronized void clear() {
         checkClosed();
         super.clear();
         doClear();
-        
+
     }
 
     /*
@@ -417,12 +416,12 @@
      * 
      * @see java.util.List#get(int)
      */
-    public synchronized Object get(int index){
+    public synchronized Object get(int index) {
         load();
         Object result = null;
-        IndexItem item=indexList.get(index);
-        if(item!=null){
-            result=getValue(item);
+        IndexItem item = indexList.get(index);
+        if (item != null) {
+            result = getValue(item);
         }
         return result;
     }
@@ -432,28 +431,32 @@
      * 
      * @see java.util.List#set(int, E)
      */
-    public synchronized Object set(int index,Object element){
+    public synchronized Object set(int index, Object element) {
         load();
-        Object result=null;
-        IndexItem replace=indexList.isEmpty()?null:(IndexItem)indexList.get(index);
-        IndexItem prev=(indexList.isEmpty()||(index-1)<0)?null:(IndexItem)indexList.get(index-1);
-        IndexItem next=(indexList.isEmpty()||(index+1)>=size())?null:(IndexItem)indexList.get(index+1);
-        result=getValue(replace);
+        Object result = null;
+        IndexItem replace = indexList.isEmpty() ? null : (IndexItem)indexList.get(index);
+        IndexItem prev = (indexList.isEmpty() || (index - 1) < 0) ? null : (IndexItem)indexList
+            .get(index - 1);
+        IndexItem next = (indexList.isEmpty() || (index + 1) >= size()) ? null : (IndexItem)indexList
+            .get(index + 1);
+        result = getValue(replace);
         indexList.remove(index);
-        delete(replace,prev,next);
+        delete(replace, prev, next);
         itemRemoved(index);
-        add(index,element);
+        add(index, element);
         return result;
     }
 
-    protected synchronized IndexItem internalSet(int index,Object element){
-        IndexItem replace=indexList.isEmpty()?null:(IndexItem)indexList.get(index);
-        IndexItem prev=(indexList.isEmpty()||(index-1)<0)?null:(IndexItem)indexList.get(index-1);
-        IndexItem next=(indexList.isEmpty()||(index+1)>=size())?null:(IndexItem)indexList.get(index+1);
+    protected synchronized IndexItem internalSet(int index, Object element) {
+        IndexItem replace = indexList.isEmpty() ? null : (IndexItem)indexList.get(index);
+        IndexItem prev = (indexList.isEmpty() || (index - 1) < 0) ? null : (IndexItem)indexList
+            .get(index - 1);
+        IndexItem next = (indexList.isEmpty() || (index + 1) >= size()) ? null : (IndexItem)indexList
+            .get(index + 1);
         indexList.remove(index);
-        delete(replace,prev,next);
+        delete(replace, prev, next);
         itemRemoved(index);
-        return internalAdd(index,element);
+        return internalAdd(index, element);
     }
 
     /*
@@ -461,40 +464,40 @@
      * 
      * @see java.util.List#add(int, E)
      */
-    public synchronized void add(int index,Object element){
+    public synchronized void add(int index, Object element) {
         load();
-        IndexItem item=insert(index,element);
-        indexList.add(index,item);
-        itemAdded(item,index,element);
+        IndexItem item = insert(index, element);
+        indexList.add(index, item);
+        itemAdded(item, index, element);
     }
 
-    protected synchronized StoreEntry internalAddLast(Object o){
+    protected synchronized StoreEntry internalAddLast(Object o) {
         load();
-        IndexItem item=writeLast(o);
+        IndexItem item = writeLast(o);
         indexList.addLast(item);
-        itemAdded(item,indexList.size()-1,o);
+        itemAdded(item, indexList.size() - 1, o);
         return item;
     }
 
-    protected synchronized StoreEntry internalAddFirst(Object o){
+    protected synchronized StoreEntry internalAddFirst(Object o) {
         load();
-        IndexItem item=writeFirst(o);
+        IndexItem item = writeFirst(o);
         indexList.addFirst(item);
-        itemAdded(item,0,o);
+        itemAdded(item, 0, o);
         return item;
     }
 
-    protected synchronized IndexItem internalAdd(int index,Object element){
+    protected synchronized IndexItem internalAdd(int index, Object element) {
         load();
-        IndexItem item=insert(index,element);
-        indexList.add(index,item);
-        itemAdded(item,index,element);
+        IndexItem item = insert(index, element);
+        indexList.add(index, item);
+        itemAdded(item, index, element);
         return item;
     }
 
-    protected synchronized StoreEntry internalGet(int index){
+    protected synchronized StoreEntry internalGet(int index) {
         load();
-        if(index>=0&&index<indexList.size()){
+        if (index >= 0 && index < indexList.size()) {
             return indexList.get(index);
         }
         return null;
@@ -505,18 +508,18 @@
      * 
      * @see org.apache.activemq.kaha.ListContainer#doRemove(int)
      */
-    public synchronized boolean doRemove(int index){
+    public synchronized boolean doRemove(int index) {
         load();
-        boolean result=false;
-        IndexItem item=indexList.get(index);
-        if(item!=null){
-            result=true;
-            IndexItem prev=indexList.getPrevEntry(item);
-            prev=prev!=null?prev:root;
-            IndexItem next=indexList.getNextEntry(prev);
+        boolean result = false;
+        IndexItem item = indexList.get(index);
+        if (item != null) {
+            result = true;
+            IndexItem prev = indexList.getPrevEntry(item);
+            prev = prev != null ? prev : root;
+            IndexItem next = indexList.getNextEntry(prev);
             indexList.remove(index);
             itemRemoved(index);
-            delete(item,prev,next);
+            delete(item, prev, next);
         }
         return result;
     }
@@ -526,18 +529,18 @@
      * 
      * @see java.util.List#remove(int)
      */
-    public synchronized Object remove(int index){
+    public synchronized Object remove(int index) {
         load();
-        Object result=null;
-        IndexItem item=indexList.get(index);
-        if(item!=null){
+        Object result = null;
+        IndexItem item = indexList.get(index);
+        if (item != null) {
             itemRemoved(index);
-            result=getValue(item);
-            IndexItem prev=indexList.getPrevEntry(item);
-            prev=prev!=null?prev:root;
-            IndexItem next=indexList.getNextEntry(item);
+            result = getValue(item);
+            IndexItem prev = indexList.getPrevEntry(item);
+            prev = prev != null ? prev : root;
+            IndexItem next = indexList.getNextEntry(item);
             indexList.remove(index);
-            delete(item,prev,next);
+            delete(item, prev, next);
         }
         return result;
     }
@@ -547,20 +550,20 @@
      * 
      * @see java.util.List#indexOf(java.lang.Object)
      */
-    public synchronized int indexOf(Object o){
+    public synchronized int indexOf(Object o) {
         load();
-        int result=-1;
-        if(o!=null){
-            int count=0;
-            IndexItem next=indexList.getFirst();
-            while(next!=null){
-                Object value=getValue(next);
-                if(value!=null&&value.equals(o)){
-                    result=count;
+        int result = -1;
+        if (o != null) {
+            int count = 0;
+            IndexItem next = indexList.getFirst();
+            while (next != null) {
+                Object value = getValue(next);
+                if (value != null && value.equals(o)) {
+                    result = count;
                     break;
                 }
                 count++;
-                next=indexList.getNextEntry(next);
+                next = indexList.getNextEntry(next);
             }
         }
         return result;
@@ -571,20 +574,20 @@
      * 
      * @see java.util.List#lastIndexOf(java.lang.Object)
      */
-    public synchronized int lastIndexOf(Object o){
+    public synchronized int lastIndexOf(Object o) {
         load();
-        int result=-1;
-        if(o!=null){
-            int count=indexList.size()-1;
-            IndexItem next=indexList.getLast();
-            while(next!=null){
-                Object value=getValue(next);
-                if(value!=null&&value.equals(o)){
-                    result=count;
+        int result = -1;
+        if (o != null) {
+            int count = indexList.size() - 1;
+            IndexItem next = indexList.getLast();
+            while (next != null) {
+                Object value = getValue(next);
+                if (value != null && value.equals(o)) {
+                    result = count;
                     break;
                 }
                 count--;
-                next=indexList.getPrevEntry(next);
+                next = indexList.getPrevEntry(next);
             }
         }
         return result;
@@ -595,9 +598,9 @@
      * 
      * @see java.util.List#listIterator()
      */
-    public synchronized ListIterator listIterator(){
+    public synchronized ListIterator listIterator() {
         load();
-        return new ContainerListIterator(this,indexList,indexList.getRoot());
+        return new ContainerListIterator(this, indexList, indexList.getRoot());
     }
 
     /*
@@ -605,10 +608,10 @@
      * 
      * @see java.util.List#listIterator(int)
      */
-    public synchronized ListIterator listIterator(int index){
+    public synchronized ListIterator listIterator(int index) {
         load();
-        IndexItem start = (index-1) >0 ?indexList.get(index-1):indexList.getRoot();
-        return new ContainerListIterator(this,indexList,start);
+        IndexItem start = (index - 1) > 0 ? indexList.get(index - 1) : indexList.getRoot();
+        return new ContainerListIterator(this, indexList, start);
     }
 
     /*
@@ -616,14 +619,14 @@
      * 
      * @see java.util.List#subList(int, int)
      */
-    public synchronized List subList(int fromIndex,int toIndex){
+    public synchronized List subList(int fromIndex, int toIndex) {
         load();
-        List result=new ArrayList();
-        int count=fromIndex;
-        IndexItem next=indexList.get(fromIndex);
-        while(next!=null&&count++<toIndex){
+        List result = new ArrayList();
+        int count = fromIndex;
+        IndexItem next = indexList.get(fromIndex);
+        while (next != null && count++ < toIndex) {
             result.add(getValue(next));
-            next=indexList.getNextEntry(next);
+            next = indexList.getNextEntry(next);
         }
         return result;
     }
@@ -634,31 +637,33 @@
      * @param object
      * @return the entry in the Store
      */
-    public synchronized StoreEntry placeLast(Object object){
-        StoreEntry item=internalAddLast(object);
+    public synchronized StoreEntry placeLast(Object object) {
+        StoreEntry item = internalAddLast(object);
         return item;
     }
 
     /**
-     * insert an Object in first position int the list but get a StoreEntry of its position
+     * insert an Object in first position int the list but get a StoreEntry of
+     * its position
      * 
      * @param object
      * @return the location in the Store
      */
-    public synchronized StoreEntry placeFirst(Object object){
-        StoreEntry item=internalAddFirst(object);
+    public synchronized StoreEntry placeFirst(Object object) {
+        StoreEntry item = internalAddFirst(object);
         return item;
     }
 
     /**
      * @param entry
      * @param object
-     * @see org.apache.activemq.kaha.ListContainer#update(org.apache.activemq.kaha.StoreEntry, java.lang.Object)
+     * @see org.apache.activemq.kaha.ListContainer#update(org.apache.activemq.kaha.StoreEntry,
+     *      java.lang.Object)
      */
-    public synchronized void update(StoreEntry entry,Object object){
-        try{
-            dataManager.updateItem(entry.getValueDataItem(),marshaller,object);
-        }catch(IOException e){
+    public synchronized void update(StoreEntry entry, Object object) {
+        try {
+            dataManager.updateItem(entry.getValueDataItem(), marshaller, object);
+        } catch (IOException e) {
             throw new RuntimeException(e);
         }
     }
@@ -669,7 +674,7 @@
      * @param entry
      * @return the Object at that entry
      */
-    public synchronized Object get(final StoreEntry entry){
+    public synchronized Object get(final StoreEntry entry) {
         load();
         StoreEntry entryToUse = refresh(entry);
         return getValue(entryToUse);
@@ -681,12 +686,12 @@
      * @param entry
      * @return true if successful
      */
-    public synchronized boolean remove(StoreEntry entry){
-        IndexItem item=(IndexItem)entry;
+    public synchronized boolean remove(StoreEntry entry) {
+        IndexItem item = (IndexItem)entry;
         load();
-        boolean result=false;
-        if(item!=null){
-           
+        boolean result = false;
+        if (item != null) {
+
             remove(item);
             result = true;
         }
@@ -698,7 +703,7 @@
      * 
      * @return the first StoreEntry or null if the list is empty
      */
-    public synchronized StoreEntry getFirst(){
+    public synchronized StoreEntry getFirst() {
         load();
         return indexList.getFirst();
     }
@@ -708,7 +713,7 @@
      * 
      * @return the last StoreEntry or null if the list is empty
      */
-    public synchronized StoreEntry getLast(){
+    public synchronized StoreEntry getLast() {
         load();
         return indexList.getLast();
     }
@@ -719,9 +724,9 @@
      * @param entry
      * @return the next StoreEntry or null
      */
-    public synchronized StoreEntry getNext(StoreEntry entry){
+    public synchronized StoreEntry getNext(StoreEntry entry) {
         load();
-        IndexItem item=(IndexItem)entry;
+        IndexItem item = (IndexItem)entry;
         return indexList.getNextEntry(item);
     }
 
@@ -731,15 +736,16 @@
      * @param entry
      * @return the previous store entry or null
      */
-    public synchronized StoreEntry getPrevious(StoreEntry entry){
+    public synchronized StoreEntry getPrevious(StoreEntry entry) {
         load();
-        IndexItem item=(IndexItem)entry;
+        IndexItem item = (IndexItem)entry;
         return indexList.getPrevEntry(item);
     }
-    
+
     /**
-     * It's possible that a StoreEntry could be come stale
-     * this will return an upto date entry for the StoreEntry position
+     * It's possible that a StoreEntry could be come stale this will return an
+     * upto date entry for the StoreEntry position
+     * 
      * @param entry old entry
      * @return a refreshed StoreEntry
      */
@@ -748,104 +754,104 @@
         return indexList.getEntry(entry);
     }
 
-    protected synchronized IndexItem writeLast(Object value){
-        IndexItem index=null;
-        try{
-            if(value!=null){
-                StoreLocation data=dataManager.storeDataItem(marshaller,value);
-                index=indexManager.createNewIndex();
+    protected synchronized IndexItem writeLast(Object value) {
+        IndexItem index = null;
+        try {
+            if (value != null) {
+                StoreLocation data = dataManager.storeDataItem(marshaller, value);
+                index = indexManager.createNewIndex();
                 index.setValueData(data);
-                IndexItem prev=indexList.getLast();
-                prev=prev!=null?prev:root;
-                IndexItem next=indexList.getNextEntry(prev);
+                IndexItem prev = indexList.getLast();
+                prev = prev != null ? prev : root;
+                IndexItem next = indexList.getNextEntry(prev);
                 prev.setNextItem(index.getOffset());
                 index.setPreviousItem(prev.getOffset());
                 updateIndexes(prev);
-                if(next!=null){
+                if (next != null) {
                     next.setPreviousItem(index.getOffset());
                     index.setNextItem(next.getOffset());
                     updateIndexes(next);
                 }
                 storeIndex(index);
             }
-        }catch(IOException e){
-            log.error("Failed to write "+value,e);
+        } catch (IOException e) {
+            log.error("Failed to write " + value, e);
             throw new RuntimeStoreException(e);
         }
         return index;
     }
 
-    protected synchronized IndexItem writeFirst(Object value){
-        IndexItem index=null;
-        try{
-            if(value!=null){
-                StoreLocation data=dataManager.storeDataItem(marshaller,value);
-                index=indexManager.createNewIndex();
+    protected synchronized IndexItem writeFirst(Object value) {
+        IndexItem index = null;
+        try {
+            if (value != null) {
+                StoreLocation data = dataManager.storeDataItem(marshaller, value);
+                index = indexManager.createNewIndex();
                 index.setValueData(data);
-                IndexItem prev=root;
-                IndexItem next=indexList.getNextEntry(prev);
+                IndexItem prev = root;
+                IndexItem next = indexList.getNextEntry(prev);
                 prev.setNextItem(index.getOffset());
                 index.setPreviousItem(prev.getOffset());
                 updateIndexes(prev);
-                if(next!=null){
+                if (next != null) {
                     next.setPreviousItem(index.getOffset());
                     index.setNextItem(next.getOffset());
                     updateIndexes(next);
                 }
                 storeIndex(index);
             }
-        }catch(IOException e){
-            log.error("Failed to write "+value,e);
+        } catch (IOException e) {
+            log.error("Failed to write " + value, e);
             throw new RuntimeStoreException(e);
         }
         return index;
     }
 
-    protected synchronized IndexItem insert(int insertPos,Object value){
-        IndexItem index=null;
-        try{
-            if(value!=null){
-                StoreLocation data=dataManager.storeDataItem(marshaller,value);
-                index=indexManager.createNewIndex();
+    protected synchronized IndexItem insert(int insertPos, Object value) {
+        IndexItem index = null;
+        try {
+            if (value != null) {
+                StoreLocation data = dataManager.storeDataItem(marshaller, value);
+                index = indexManager.createNewIndex();
                 index.setValueData(data);
-                IndexItem prev=null;
-                IndexItem next=null;
-                if(insertPos<=0){
-                    prev=root;
-                    next=indexList.getNextEntry(root);
-                }else if(insertPos>=indexList.size()){
-                    prev=indexList.getLast();
-                    next=null;
-                }else{
-                    prev=indexList.get(insertPos);
-                    prev=prev!=null?prev:root;
-                    next=indexList.getNextEntry(prev);
+                IndexItem prev = null;
+                IndexItem next = null;
+                if (insertPos <= 0) {
+                    prev = root;
+                    next = indexList.getNextEntry(root);
+                } else if (insertPos >= indexList.size()) {
+                    prev = indexList.getLast();
+                    next = null;
+                } else {
+                    prev = indexList.get(insertPos);
+                    prev = prev != null ? prev : root;
+                    next = indexList.getNextEntry(prev);
                 }
                 prev.setNextItem(index.getOffset());
                 index.setPreviousItem(prev.getOffset());
                 updateIndexes(prev);
-                if(next!=null){
+                if (next != null) {
                     next.setPreviousItem(index.getOffset());
                     index.setNextItem(next.getOffset());
                     updateIndexes(next);
                 }
                 storeIndex(index);
             }
-        }catch(IOException e){
-            log.error("Failed to insert "+value,e);
+        } catch (IOException e) {
+            log.error("Failed to insert " + value, e);
             throw new RuntimeStoreException(e);
         }
         return index;
     }
 
-    protected synchronized Object getValue(StoreEntry item){
-        Object result=null;
-        if(item!=null){
-            try{
-                StoreLocation data=item.getValueDataItem();
-                result=dataManager.readItem(marshaller,data);
-            }catch(IOException e){
-                log.error("Failed to get value for "+item,e);
+    protected synchronized Object getValue(StoreEntry item) {
+        Object result = null;
+        if (item != null) {
+            try {
+                StoreLocation data = item.getValueDataItem();
+                result = dataManager.readItem(marshaller, data);
+            } catch (IOException e) {
+                log.error("Failed to get value for " + item, e);
                 throw new RuntimeStoreException(e);
             }
         }
@@ -855,27 +861,27 @@
     /**
      * @return a string representation of this collection.
      */
-    public synchronized String toString(){
-        StringBuffer result=new StringBuffer();
+    public synchronized String toString() {
+        StringBuffer result = new StringBuffer();
         result.append("[");
-        Iterator i=iterator();
-        boolean hasNext=i.hasNext();
-        while(hasNext){
-            Object o=i.next();
+        Iterator i = iterator();
+        boolean hasNext = i.hasNext();
+        while (hasNext) {
+            Object o = i.next();
             result.append(String.valueOf(o));
-            hasNext=i.hasNext();
-            if(hasNext)
+            hasNext = i.hasNext();
+            if (hasNext)
                 result.append(", ");
         }
         result.append("]");
         return result.toString();
     }
 
-    protected synchronized void itemAdded(IndexItem item,int pos,Object value){
-        
+    protected synchronized void itemAdded(IndexItem item, int pos, Object value) {
+
     }
 
-    protected synchronized void itemRemoved(int pos){
-        
+    protected synchronized void itemRemoved(int pos) {
+
     }
 }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/MapContainerImpl.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/MapContainerImpl.java?view=diff&rev=563982&r1=563981&r2=563982
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/MapContainerImpl.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/MapContainerImpl.java Wed Aug  8 11:56:59 2007
@@ -43,34 +43,34 @@
  * 
  * @version $Revision: 1.2 $
  */
-public final class MapContainerImpl extends BaseContainerImpl implements MapContainer{
+public final class MapContainerImpl extends BaseContainerImpl implements MapContainer {
 
-    private static final Log log=LogFactory.getLog(MapContainerImpl.class);
+    private static final Log log = LogFactory.getLog(MapContainerImpl.class);
     protected Index index;
-    protected Marshaller keyMarshaller=Store.ObjectMarshaller;
-    protected Marshaller valueMarshaller=Store.ObjectMarshaller;
+    protected Marshaller keyMarshaller = Store.ObjectMarshaller;
+    protected Marshaller valueMarshaller = Store.ObjectMarshaller;
     protected File directory;
 
-    public MapContainerImpl(File directory,ContainerId id,IndexItem root,IndexManager indexManager,
-            DataManager dataManager,boolean persistentIndex){
-        super(id,root,indexManager,dataManager,persistentIndex);
-        this.directory=directory;
+    public MapContainerImpl(File directory, ContainerId id, IndexItem root, IndexManager indexManager,
+                            DataManager dataManager, boolean persistentIndex) {
+        super(id, root, indexManager, dataManager, persistentIndex);
+        this.directory = directory;
     }
 
-    public synchronized void init(){
+    public synchronized void init() {
         super.init();
-        if(index==null){
-            if(persistentIndex){
-                String name=containerId.getDataContainerName()+"_"+containerId.getKey();
-                name=name.replaceAll("[^a-zA-Z0-9\\.\\_\\-]", "_");
-                try{
-                    this.index=new HashIndex(directory,name,indexManager);
-                }catch(IOException e){
-                    log.error("Failed to create HashIndex",e);
+        if (index == null) {
+            if (persistentIndex) {
+                String name = containerId.getDataContainerName() + "_" + containerId.getKey();
+                name = name.replaceAll("[^a-zA-Z0-9\\.\\_\\-]", "_");
+                try {
+                    this.index = new HashIndex(directory, name, indexManager);
+                } catch (IOException e) {
+                    log.error("Failed to create HashIndex", e);
                     throw new RuntimeException(e);
                 }
-            }else{
-                this.index=new VMIndex(indexManager);
+            } else {
+                this.index = new VMIndex(indexManager);
             }
         }
         index.setKeyMarshaller(keyMarshaller);
@@ -81,27 +81,27 @@
      * 
      * @see org.apache.activemq.kaha.MapContainer#load()
      */
-    public synchronized void load(){
+    public synchronized void load() {
         checkClosed();
-        if(!loaded){
-            if(!loaded){
-                loaded=true;
-                try{
+        if (!loaded) {
+            if (!loaded) {
+                loaded = true;
+                try {
                     init();
                     index.load();
-                    long nextItem=root.getNextItem();
-                    while(nextItem!=Item.POSITION_NOT_SET){
-                        IndexItem item=indexManager.getIndex(nextItem);
-                        StoreLocation data=item.getKeyDataItem();
-                        Object key=dataManager.readItem(keyMarshaller,data);
-                        if(index.isTransient()){
-                            index.store(key,item);
+                    long nextItem = root.getNextItem();
+                    while (nextItem != Item.POSITION_NOT_SET) {
+                        IndexItem item = indexManager.getIndex(nextItem);
+                        StoreLocation data = item.getKeyDataItem();
+                        Object key = dataManager.readItem(keyMarshaller, data);
+                        if (index.isTransient()) {
+                            index.store(key, item);
                         }
                         indexList.add(item);
-                        nextItem=item.getNextItem();
+                        nextItem = item.getNextItem();
                     }
-                }catch(IOException e){
-                    log.error("Failed to load container "+getId(),e);
+                } catch (IOException e) {
+                    log.error("Failed to load container " + getId(), e);
                     throw new RuntimeStoreException(e);
                 }
             }
@@ -113,30 +113,30 @@
      * 
      * @see org.apache.activemq.kaha.MapContainer#unload()
      */
-    public synchronized void unload(){
+    public synchronized void unload() {
         checkClosed();
-        if(loaded){
-            loaded=false;
-            try{
+        if (loaded) {
+            loaded = false;
+            try {
                 index.unload();
-            }catch(IOException e){
-                log.warn("Failed to unload the index",e);
+            } catch (IOException e) {
+                log.warn("Failed to unload the index", e);
             }
             indexList.clear();
         }
     }
 
-    public synchronized void setKeyMarshaller(Marshaller keyMarshaller){
+    public synchronized void setKeyMarshaller(Marshaller keyMarshaller) {
         checkClosed();
-        this.keyMarshaller=keyMarshaller;
-        if(index!=null){
+        this.keyMarshaller = keyMarshaller;
+        if (index != null) {
             index.setKeyMarshaller(keyMarshaller);
         }
     }
 
-    public synchronized void setValueMarshaller(Marshaller valueMarshaller){
+    public synchronized void setValueMarshaller(Marshaller valueMarshaller) {
         checkClosed();
-        this.valueMarshaller=valueMarshaller;
+        this.valueMarshaller = valueMarshaller;
     }
 
     /*
@@ -144,7 +144,7 @@
      * 
      * @see org.apache.activemq.kaha.MapContainer#size()
      */
-    public synchronized int size(){
+    public synchronized int size() {
         load();
         return indexList.size();
     }
@@ -154,7 +154,7 @@
      * 
      * @see org.apache.activemq.kaha.MapContainer#isEmpty()
      */
-    public synchronized boolean isEmpty(){
+    public synchronized boolean isEmpty() {
         load();
         return indexList.isEmpty();
     }
@@ -164,12 +164,12 @@
      * 
      * @see org.apache.activemq.kaha.MapContainer#containsKey(java.lang.Object)
      */
-    public synchronized boolean containsKey(Object key){
+    public synchronized boolean containsKey(Object key) {
         load();
-        try{
+        try {
             return index.containsKey(key);
-        }catch(IOException e){
-            log.error("Failed trying to find key: "+key,e);
+        } catch (IOException e) {
+            log.error("Failed trying to find key: " + key, e);
             throw new RuntimeException(e);
         }
     }
@@ -179,34 +179,35 @@
      * 
      * @see org.apache.activemq.kaha.MapContainer#get(java.lang.Object)
      */
-    public synchronized Object get(Object key){
+    public synchronized Object get(Object key) {
         load();
-        Object result=null;
-        StoreEntry item=null;
-        try{
-            item=index.get(key);
-        }catch(IOException e){
-            log.error("Failed trying to get key: "+key,e);
+        Object result = null;
+        StoreEntry item = null;
+        try {
+            item = index.get(key);
+        } catch (IOException e) {
+            log.error("Failed trying to get key: " + key, e);
             throw new RuntimeException(e);
         }
-        if(item!=null){
-            result=getValue(item);
+        if (item != null) {
+            result = getValue(item);
         }
         return result;
     }
-    
+
     /**
      * Get the StoreEntry associated with the key
+     * 
      * @param key
      * @return the StoreEntry
      */
     public synchronized StoreEntry getEntry(Object key) {
         load();
-        StoreEntry item=null;
-        try{
-            item=index.get(key);
-        }catch(IOException e){
-            log.error("Failed trying to get key: "+key,e);
+        StoreEntry item = null;
+        try {
+            item = index.get(key);
+        } catch (IOException e) {
+            log.error("Failed trying to get key: " + key, e);
             throw new RuntimeException(e);
         }
         return item;
@@ -217,18 +218,18 @@
      * 
      * @see org.apache.activemq.kaha.MapContainer#containsValue(java.lang.Object)
      */
-    public synchronized boolean containsValue(Object o){
+    public synchronized boolean containsValue(Object o) {
         load();
-        boolean result=false;
-        if(o!=null){
-            IndexItem item=indexList.getFirst();
-            while(item!=null){
-                Object value=getValue(item);
-                if(value!=null&&value.equals(o)){
-                    result=true;
+        boolean result = false;
+        if (o != null) {
+            IndexItem item = indexList.getFirst();
+            while (item != null) {
+                Object value = getValue(item);
+                if (value != null && value.equals(o)) {
+                    result = true;
                     break;
                 }
-                item=indexList.getNextEntry(item);
+                item = indexList.getNextEntry(item);
             }
         }
         return result;
@@ -239,12 +240,12 @@
      * 
      * @see org.apache.activemq.kaha.MapContainer#putAll(java.util.Map)
      */
-    public synchronized void putAll(Map t){
+    public synchronized void putAll(Map t) {
         load();
-        if(t!=null){
-            for(Iterator i=t.entrySet().iterator();i.hasNext();){
-                Map.Entry entry=(Map.Entry)i.next();
-                put(entry.getKey(),entry.getValue());
+        if (t != null) {
+            for (Iterator i = t.entrySet().iterator(); i.hasNext();) {
+                Map.Entry entry = (Map.Entry)i.next();
+                put(entry.getKey(), entry.getValue());
             }
         }
     }
@@ -254,7 +255,7 @@
      * 
      * @see org.apache.activemq.kaha.MapContainer#keySet()
      */
-    public synchronized Set keySet(){
+    public synchronized Set keySet() {
         load();
         return new ContainerKeySet(this);
     }
@@ -264,7 +265,7 @@
      * 
      * @see org.apache.activemq.kaha.MapContainer#values()
      */
-    public synchronized Collection values(){
+    public synchronized Collection values() {
         load();
         return new ContainerValueCollection(this);
     }
@@ -274,7 +275,7 @@
      * 
      * @see org.apache.activemq.kaha.MapContainer#entrySet()
      */
-    public synchronized Set entrySet(){
+    public synchronized Set entrySet() {
         load();
         return new ContainerEntrySet(this);
     }
@@ -282,16 +283,17 @@
     /*
      * (non-Javadoc)
      * 
-     * @see org.apache.activemq.kaha.MapContainer#put(java.lang.Object, java.lang.Object)
+     * @see org.apache.activemq.kaha.MapContainer#put(java.lang.Object,
+     *      java.lang.Object)
      */
-    public synchronized Object put(Object key,Object value){
+    public synchronized Object put(Object key, Object value) {
         load();
-        Object result=remove(key);
-        IndexItem item=write(key,value);
-        try{
-            index.store(key,item);
-        }catch(IOException e){
-            log.error("Failed trying to insert key: "+key,e);
+        Object result = remove(key);
+        IndexItem item = write(key, value);
+        try {
+            index.store(key, item);
+        } catch (IOException e) {
+            log.error("Failed trying to insert key: " + key, e);
             throw new RuntimeException(e);
         }
         indexList.add(item);
@@ -303,52 +305,52 @@
      * 
      * @see org.apache.activemq.kaha.MapContainer#remove(java.lang.Object)
      */
-    public synchronized Object remove(Object key){
+    public synchronized Object remove(Object key) {
         load();
-        try{
-            Object result=null;
-            IndexItem item=(IndexItem)index.remove(key);
-            if(item!=null){
+        try {
+            Object result = null;
+            IndexItem item = (IndexItem)index.remove(key);
+            if (item != null) {
                 // refresh the index
-                item=(IndexItem)indexList.refreshEntry(item);
-                result=getValue(item);
-                IndexItem prev=indexList.getPrevEntry(item);
-                IndexItem next=indexList.getNextEntry(item);
+                item = (IndexItem)indexList.refreshEntry(item);
+                result = getValue(item);
+                IndexItem prev = indexList.getPrevEntry(item);
+                IndexItem next = indexList.getNextEntry(item);
                 indexList.remove(item);
-                delete(item,prev,next);
+                delete(item, prev, next);
             }
             return result;
-        }catch(IOException e){
-            log.error("Failed trying to remove key: "+key,e);
+        } catch (IOException e) {
+            log.error("Failed trying to remove key: " + key, e);
             throw new RuntimeException(e);
         }
     }
 
-    public synchronized boolean removeValue(Object o){
+    public synchronized boolean removeValue(Object o) {
         load();
-        boolean result=false;
-        if(o!=null){
-            IndexItem item=indexList.getFirst();
-            while(item!=null){
-                Object value=getValue(item);
-                if(value!=null&&value.equals(o)){
-                    result=true;
+        boolean result = false;
+        if (o != null) {
+            IndexItem item = indexList.getFirst();
+            while (item != null) {
+                Object value = getValue(item);
+                if (value != null && value.equals(o)) {
+                    result = true;
                     // find the key
-                    Object key=getKey(item);
-                    if(key!=null){
+                    Object key = getKey(item);
+                    if (key != null) {
                         remove(key);
                     }
                     break;
                 }
-                item=indexList.getNextEntry(item);
+                item = indexList.getNextEntry(item);
             }
         }
         return result;
     }
 
-    protected synchronized void remove(IndexItem item){
-        Object key=getKey(item);
-        if(key!=null){
+    protected synchronized void remove(IndexItem item) {
+        Object key = getKey(item);
+        if (key != null) {
             remove(key);
         }
     }
@@ -358,15 +360,15 @@
      * 
      * @see org.apache.activemq.kaha.MapContainer#clear()
      */
-    public synchronized void clear(){
+    public synchronized void clear() {
         checkClosed();
-        loaded=true;
+        loaded = true;
         init();
-        if(index!=null){
-            try{
+        if (index != null) {
+            try {
                 index.clear();
-            }catch(IOException e){
-                log.error("Failed trying clear index",e);
+            } catch (IOException e) {
+                log.error("Failed trying clear index", e);
                 throw new RuntimeException(e);
             }
         }
@@ -381,16 +383,16 @@
      * @param value
      * @return the StoreEntry associated with the entry
      */
-    public synchronized StoreEntry place(Object key,Object value){
+    public synchronized StoreEntry place(Object key, Object value) {
         load();
-        try{
+        try {
             remove(key);
-            IndexItem item=write(key,value);
-            index.store(key,item);
+            IndexItem item = write(key, value);
+            index.store(key, item);
             indexList.add(item);
             return item;
-        }catch(IOException e){
-            log.error("Failed trying to place key: "+key,e);
+        } catch (IOException e) {
+            log.error("Failed trying to place key: " + key, e);
             throw new RuntimeException(e);
         }
     }
@@ -401,47 +403,47 @@
      * @param entry
      * @throws IOException
      */
-    public synchronized void remove(StoreEntry entry){
+    public synchronized void remove(StoreEntry entry) {
         load();
-        IndexItem item=(IndexItem)entry;
-        if(item!=null){
-            Object key=getKey(item);
-            try{
+        IndexItem item = (IndexItem)entry;
+        if (item != null) {
+            Object key = getKey(item);
+            try {
                 index.remove(key);
-            }catch(IOException e){
-                log.error("Failed trying to remove entry: "+entry,e);
+            } catch (IOException e) {
+                log.error("Failed trying to remove entry: " + entry, e);
                 throw new RuntimeException(e);
             }
-            IndexItem prev=indexList.getPrevEntry(item);
-            IndexItem next=indexList.getNextEntry(item);
+            IndexItem prev = indexList.getPrevEntry(item);
+            IndexItem next = indexList.getNextEntry(item);
             indexList.remove(item);
-            delete(item,prev,next);
+            delete(item, prev, next);
         }
     }
 
-    public synchronized StoreEntry getFirst(){
+    public synchronized StoreEntry getFirst() {
         load();
         return indexList.getFirst();
     }
 
-    public synchronized StoreEntry getLast(){
+    public synchronized StoreEntry getLast() {
         load();
         return indexList.getLast();
     }
 
-    public synchronized StoreEntry getNext(StoreEntry entry){
+    public synchronized StoreEntry getNext(StoreEntry entry) {
         load();
-        IndexItem item=(IndexItem)entry;
+        IndexItem item = (IndexItem)entry;
         return indexList.getNextEntry(item);
     }
 
-    public synchronized StoreEntry getPrevious(StoreEntry entry){
+    public synchronized StoreEntry getPrevious(StoreEntry entry) {
         load();
-        IndexItem item=(IndexItem)entry;
+        IndexItem item = (IndexItem)entry;
         return indexList.getPrevEntry(item);
     }
 
-    public synchronized StoreEntry refresh(StoreEntry entry){
+    public synchronized StoreEntry refresh(StoreEntry entry) {
         load();
         return indexList.getEntry(entry);
     }
@@ -452,17 +454,17 @@
      * @param item
      * @return the value associated with the store entry
      */
-    public synchronized Object getValue(StoreEntry item){
+    public synchronized Object getValue(StoreEntry item) {
         load();
-        Object result=null;
-        if(item!=null){
-            try{
+        Object result = null;
+        if (item != null) {
+            try {
                 // ensure this value is up to date
                 // item=indexList.getEntry(item);
-                StoreLocation data=item.getValueDataItem();
-                result=dataManager.readItem(valueMarshaller,data);
-            }catch(IOException e){
-                log.error("Failed to get value for "+item,e);
+                StoreLocation data = item.getValueDataItem();
+                result = dataManager.readItem(valueMarshaller, data);
+            } catch (IOException e) {
+                log.error("Failed to get value for " + item, e);
                 throw new RuntimeStoreException(e);
             }
         }
@@ -475,50 +477,50 @@
      * @param item
      * @return the Key Object associated with the StoreEntry
      */
-    public synchronized Object getKey(StoreEntry item){
+    public synchronized Object getKey(StoreEntry item) {
         load();
-        Object result=null;
-        if(item!=null){
-            try{
-                StoreLocation data=item.getKeyDataItem();
-                result=dataManager.readItem(keyMarshaller,data);
-            }catch(IOException e){
-                log.error("Failed to get key for "+item,e);
+        Object result = null;
+        if (item != null) {
+            try {
+                StoreLocation data = item.getKeyDataItem();
+                result = dataManager.readItem(keyMarshaller, data);
+            } catch (IOException e) {
+                log.error("Failed to get key for " + item, e);
                 throw new RuntimeStoreException(e);
             }
         }
         return result;
     }
 
-    protected IndexLinkedList getItemList(){
+    protected IndexLinkedList getItemList() {
         return indexList;
     }
 
-    protected synchronized IndexItem write(Object key,Object value){
-        IndexItem index=null;
-        try{
-            index=indexManager.createNewIndex();
-            StoreLocation data=dataManager.storeDataItem(keyMarshaller,key);
+    protected synchronized IndexItem write(Object key, Object value) {
+        IndexItem index = null;
+        try {
+            index = indexManager.createNewIndex();
+            StoreLocation data = dataManager.storeDataItem(keyMarshaller, key);
             index.setKeyData(data);
-            
-            if(value!=null){
-                data=dataManager.storeDataItem(valueMarshaller,value);
+
+            if (value != null) {
+                data = dataManager.storeDataItem(valueMarshaller, value);
                 index.setValueData(data);
             }
-            IndexItem prev=indexList.getLast();           
-            prev=prev!=null?prev:indexList.getRoot();
-            IndexItem next=indexList.getNextEntry(prev);
+            IndexItem prev = indexList.getLast();
+            prev = prev != null ? prev : indexList.getRoot();
+            IndexItem next = indexList.getNextEntry(prev);
             prev.setNextItem(index.getOffset());
             index.setPreviousItem(prev.getOffset());
             updateIndexes(prev);
-            if(next!=null){
+            if (next != null) {
                 next.setPreviousItem(index.getOffset());
                 index.setNextItem(next.getOffset());
                 updateIndexes(next);
             }
             storeIndex(index);
-        }catch(IOException e){
-            log.error("Failed to write "+key+" , "+value,e);
+        } catch (IOException e) {
+            log.error("Failed to write " + key + " , " + value, e);
             throw new RuntimeStoreException(e);
         }
         return index;

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/DataItem.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/DataItem.java?view=diff&rev=563982&r1=563981&r2=563982
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/DataItem.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/DataItem.java Wed Aug  8 11:56:59 2007
@@ -18,27 +18,27 @@
 
 import org.apache.activemq.kaha.StoreLocation;
 
-
 /**
  * A a wrapper for a data in the store
  * 
  * @version $Revision: 1.2 $
  */
-public final class DataItem implements Item, StoreLocation{
-    
-    private int file=(int) POSITION_NOT_SET;
-    private long offset=POSITION_NOT_SET;
+public final class DataItem implements Item, StoreLocation {
+
+    private int file = (int)POSITION_NOT_SET;
+    private long offset = POSITION_NOT_SET;
     private int size;
 
-    public DataItem(){}
-    
+    public DataItem() {
+    }
+
     DataItem(DataItem item) {
         this.file = item.file;
         this.offset = item.offset;
         this.size = item.size;
     }
-    
-    boolean isValid(){
+
+    boolean isValid() {
         return file != POSITION_NOT_SET;
     }
 
@@ -46,52 +46,52 @@
      * @return
      * @see org.apache.activemq.kaha.StoreLocation#getSize()
      */
-    public int getSize(){
+    public int getSize() {
         return size;
     }
 
     /**
      * @param size The size to set.
      */
-    public void setSize(int size){
-        this.size=size;
+    public void setSize(int size) {
+        this.size = size;
     }
 
     /**
      * @return
      * @see org.apache.activemq.kaha.StoreLocation#getOffset()
      */
-    public long getOffset(){
+    public long getOffset() {
         return offset;
     }
 
     /**
      * @param offset The offset to set.
      */
-    public void setOffset(long offset){
-        this.offset=offset;
+    public void setOffset(long offset) {
+        this.offset = offset;
     }
 
     /**
      * @return
      * @see org.apache.activemq.kaha.StoreLocation#getFile()
      */
-    public int getFile(){
+    public int getFile() {
         return file;
     }
 
     /**
      * @param file The file to set.
      */
-    public void setFile(int file){
-        this.file=file;
+    public void setFile(int file) {
+        this.file = file;
     }
 
     /**
      * @return a pretty print
      */
-    public String toString(){
-        String result="offset = "+offset+", file = " + file + ", size = "+size;
+    public String toString() {
+        String result = "offset = " + offset + ", file = " + file + ", size = " + size;
         return result;
     }
 

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/DataManagerImpl.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/DataManagerImpl.java?view=diff&rev=563982&r1=563981&r2=563982
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/DataManagerImpl.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/DataManagerImpl.java Wed Aug  8 11:56:59 2007
@@ -32,284 +32,316 @@
 import org.apache.activemq.util.IOExceptionSupport;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 /**
  * Manages DataFiles
  * 
  * @version $Revision: 1.1.1.1 $
  */
 public final class DataManagerImpl implements DataManager {
-    
-    private static final Log log=LogFactory.getLog(DataManagerImpl.class);
-    public static final long MAX_FILE_LENGTH=1024*1024*32;
-    private static final String NAME_PREFIX="data-";
+
+    private static final Log log = LogFactory.getLog(DataManagerImpl.class);
+    public static final long MAX_FILE_LENGTH = 1024 * 1024 * 32;
+    private static final String NAME_PREFIX = "data-";
     private final File directory;
     private final String name;
     private SyncDataFileReader reader;
     private SyncDataFileWriter writer;
     private DataFile currentWriteFile;
     private long maxFileLength = MAX_FILE_LENGTH;
-    Map fileMap=new HashMap();
-    
-    public static final int ITEM_HEAD_SIZE=5; // type + length
-    public static final byte DATA_ITEM_TYPE=1;
-    public static final byte REDO_ITEM_TYPE=2;
-    
+    Map fileMap = new HashMap();
+
+    public static final int ITEM_HEAD_SIZE = 5; // type + length
+    public static final byte DATA_ITEM_TYPE = 1;
+    public static final byte REDO_ITEM_TYPE = 2;
+
     Marshaller redoMarshaller = RedoStoreIndexItem.MARSHALLER;
     private String dataFilePrefix;
-   
-    public DataManagerImpl(File dir, final String name){
-        this.directory=dir;
-        this.name=name;
-        
-        dataFilePrefix = NAME_PREFIX+name+"-";
+
+    public DataManagerImpl(File dir, final String name) {
+        this.directory = dir;
+        this.name = name;
+
+        dataFilePrefix = NAME_PREFIX + name + "-";
         // build up list of current dataFiles
-        File[] files=dir.listFiles(new FilenameFilter(){
-            public boolean accept(File dir,String n){
-                return dir.equals(directory)&&n.startsWith(dataFilePrefix);
+        File[] files = dir.listFiles(new FilenameFilter() {
+            public boolean accept(File dir, String n) {
+                return dir.equals(directory) && n.startsWith(dataFilePrefix);
             }
         });
-        if(files!=null){
-            for(int i=0;i<files.length;i++){
-                File file=files[i];
-                String n=file.getName();
-                String numStr=n.substring(dataFilePrefix.length(),n.length());
-                int num=Integer.parseInt(numStr);
-                DataFile dataFile=new DataFile(file,num);
-                fileMap.put(dataFile.getNumber(),dataFile);
-                if(currentWriteFile==null||currentWriteFile.getNumber().intValue()<num){
-                    currentWriteFile=dataFile;
+        if (files != null) {
+            for (int i = 0; i < files.length; i++) {
+                File file = files[i];
+                String n = file.getName();
+                String numStr = n.substring(dataFilePrefix.length(), n.length());
+                int num = Integer.parseInt(numStr);
+                DataFile dataFile = new DataFile(file, num);
+                fileMap.put(dataFile.getNumber(), dataFile);
+                if (currentWriteFile == null || currentWriteFile.getNumber().intValue() < num) {
+                    currentWriteFile = dataFile;
                 }
             }
         }
     }
-    
-    private DataFile createAndAddDataFile(int num){
-        String fileName=dataFilePrefix+num;
-        File file=new File(directory,fileName);
-        DataFile result=new DataFile(file,num);
-        fileMap.put(result.getNumber(),result);
+
+    private DataFile createAndAddDataFile(int num) {
+        String fileName = dataFilePrefix + num;
+        File file = new File(directory, fileName);
+        DataFile result = new DataFile(file, num);
+        fileMap.put(result.getNumber(), result);
         return result;
     }
 
-    /* (non-Javadoc)
-	 * @see org.apache.activemq.kaha.impl.data.IDataManager#getName()
-	 */
-    public String getName(){
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.activemq.kaha.impl.data.IDataManager#getName()
+     */
+    public String getName() {
         return name;
     }
 
-    synchronized DataFile  findSpaceForData(DataItem item) throws IOException{
-        if(currentWriteFile==null||((currentWriteFile.getLength()+item.getSize())>maxFileLength)){
-            int nextNum=currentWriteFile!=null?currentWriteFile.getNumber().intValue()+1:1;
-            if(currentWriteFile!=null&&currentWriteFile.isUnused()){
+    synchronized DataFile findSpaceForData(DataItem item) throws IOException {
+        if (currentWriteFile == null || ((currentWriteFile.getLength() + item.getSize()) > maxFileLength)) {
+            int nextNum = currentWriteFile != null ? currentWriteFile.getNumber().intValue() + 1 : 1;
+            if (currentWriteFile != null && currentWriteFile.isUnused()) {
                 removeDataFile(currentWriteFile);
             }
-            currentWriteFile=createAndAddDataFile(nextNum);
+            currentWriteFile = createAndAddDataFile(nextNum);
         }
         item.setOffset(currentWriteFile.getLength());
-        item.setFile(currentWriteFile.getNumber().intValue());        
-        currentWriteFile.incrementLength(item.getSize()+ITEM_HEAD_SIZE);
+        item.setFile(currentWriteFile.getNumber().intValue());
+        currentWriteFile.incrementLength(item.getSize() + ITEM_HEAD_SIZE);
         return currentWriteFile;
     }
 
-    DataFile getDataFile(StoreLocation item) throws IOException{
-        Integer key=Integer.valueOf(item.getFile());
-        DataFile dataFile=(DataFile) fileMap.get(key);
-        if(dataFile==null){
+    DataFile getDataFile(StoreLocation item) throws IOException {
+        Integer key = Integer.valueOf(item.getFile());
+        DataFile dataFile = (DataFile)fileMap.get(key);
+        if (dataFile == null) {
             log.error("Looking for key " + key + " but not found in fileMap: " + fileMap);
-            throw new IOException("Could not locate data file "+NAME_PREFIX+name+"-"+item.getFile());
+            throw new IOException("Could not locate data file " + NAME_PREFIX + name + "-" + item.getFile());
         }
         return dataFile;
     }
-    
-    /* (non-Javadoc)
-	 * @see org.apache.activemq.kaha.impl.data.IDataManager#readItem(org.apache.activemq.kaha.Marshaller, org.apache.activemq.kaha.StoreLocation)
-	 */
-    public synchronized Object readItem(Marshaller marshaller, StoreLocation item) throws IOException{
-        return getReader().readItem(marshaller,item);
-    }
-
-    /* (non-Javadoc)
-	 * @see org.apache.activemq.kaha.impl.data.IDataManager#storeDataItem(org.apache.activemq.kaha.Marshaller, java.lang.Object)
-	 */
-    public synchronized StoreLocation storeDataItem(Marshaller marshaller, Object payload) throws IOException{
-        return getWriter().storeItem(marshaller,payload, DATA_ITEM_TYPE);
-    }
-    
-    /* (non-Javadoc)
-	 * @see org.apache.activemq.kaha.impl.data.IDataManager#storeRedoItem(java.lang.Object)
-	 */
-    public synchronized StoreLocation storeRedoItem(Object payload) throws IOException{
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.activemq.kaha.impl.data.IDataManager#readItem(org.apache.activemq.kaha.Marshaller,
+     *      org.apache.activemq.kaha.StoreLocation)
+     */
+    public synchronized Object readItem(Marshaller marshaller, StoreLocation item) throws IOException {
+        return getReader().readItem(marshaller, item);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.activemq.kaha.impl.data.IDataManager#storeDataItem(org.apache.activemq.kaha.Marshaller,
+     *      java.lang.Object)
+     */
+    public synchronized StoreLocation storeDataItem(Marshaller marshaller, Object payload) throws IOException {
+        return getWriter().storeItem(marshaller, payload, DATA_ITEM_TYPE);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.activemq.kaha.impl.data.IDataManager#storeRedoItem(java.lang.Object)
+     */
+    public synchronized StoreLocation storeRedoItem(Object payload) throws IOException {
         return getWriter().storeItem(redoMarshaller, payload, REDO_ITEM_TYPE);
     }
-    
-    /* (non-Javadoc)
-	 * @see org.apache.activemq.kaha.impl.data.IDataManager#updateItem(org.apache.activemq.kaha.StoreLocation, org.apache.activemq.kaha.Marshaller, java.lang.Object)
-	 */
-    public synchronized void updateItem(StoreLocation location,Marshaller marshaller, Object payload) throws IOException {
-        getWriter().updateItem((DataItem)location,marshaller,payload,DATA_ITEM_TYPE);
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.activemq.kaha.impl.data.IDataManager#updateItem(org.apache.activemq.kaha.StoreLocation,
+     *      org.apache.activemq.kaha.Marshaller, java.lang.Object)
+     */
+    public synchronized void updateItem(StoreLocation location, Marshaller marshaller, Object payload)
+        throws IOException {
+        getWriter().updateItem((DataItem)location, marshaller, payload, DATA_ITEM_TYPE);
     }
 
-    /* (non-Javadoc)
-	 * @see org.apache.activemq.kaha.impl.data.IDataManager#recoverRedoItems(org.apache.activemq.kaha.impl.data.RedoListener)
-	 */
-    public synchronized void recoverRedoItems(RedoListener listener) throws IOException{
-        
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.activemq.kaha.impl.data.IDataManager#recoverRedoItems(org.apache.activemq.kaha.impl.data.RedoListener)
+     */
+    public synchronized void recoverRedoItems(RedoListener listener) throws IOException {
+
         // Nothing to recover if there is no current file.
-        if( currentWriteFile == null )
+        if (currentWriteFile == null)
             return;
-        
+
         DataItem item = new DataItem();
         item.setFile(currentWriteFile.getNumber().intValue());
         item.setOffset(0);
-        while( true ) {
+        while (true) {
             byte type;
             try {
                 type = getReader().readDataItemSize(item);
             } catch (IOException ignore) {
-                log.trace("End of data file reached at (header was invalid): "+item);
+                log.trace("End of data file reached at (header was invalid): " + item);
                 return;
             }
-            if( type == REDO_ITEM_TYPE ) {
+            if (type == REDO_ITEM_TYPE) {
                 // Un-marshal the redo item
                 Object object;
                 try {
                     object = readItem(redoMarshaller, item);
                 } catch (IOException e1) {
-                    log.trace("End of data file reached at (payload was invalid): "+item);
+                    log.trace("End of data file reached at (payload was invalid): " + item);
                     return;
                 }
                 try {
-                    
+
                     listener.onRedoItem(item, object);
-                    // in case the listener is holding on to item references, copy it
+                    // in case the listener is holding on to item references,
+                    // copy it
                     // so we don't change it behind the listener's back.
                     item = item.copy();
-                    
+
                 } catch (Exception e) {
-                    throw IOExceptionSupport.create("Recovery handler failed: "+e,e);
+                    throw IOExceptionSupport.create("Recovery handler failed: " + e, e);
                 }
             }
             // Move to the next item.
-            item.setOffset(item.getOffset()+ITEM_HEAD_SIZE+item.getSize());
+            item.setOffset(item.getOffset() + ITEM_HEAD_SIZE + item.getSize());
         }
     }
-    
-    /* (non-Javadoc)
-	 * @see org.apache.activemq.kaha.impl.data.IDataManager#close()
-	 */
-    public synchronized void close() throws IOException{
-    	getWriter().close();
-        for(Iterator i=fileMap.values().iterator();i.hasNext();){
-            DataFile dataFile=(DataFile) i.next();
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.activemq.kaha.impl.data.IDataManager#close()
+     */
+    public synchronized void close() throws IOException {
+        getWriter().close();
+        for (Iterator i = fileMap.values().iterator(); i.hasNext();) {
+            DataFile dataFile = (DataFile)i.next();
             getWriter().force(dataFile);
             dataFile.close();
         }
         fileMap.clear();
     }
 
-    /* (non-Javadoc)
-	 * @see org.apache.activemq.kaha.impl.data.IDataManager#force()
-	 */
-    public synchronized void force() throws IOException{
-        for(Iterator i=fileMap.values().iterator();i.hasNext();){
-            DataFile dataFile=(DataFile) i.next();
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.activemq.kaha.impl.data.IDataManager#force()
+     */
+    public synchronized void force() throws IOException {
+        for (Iterator i = fileMap.values().iterator(); i.hasNext();) {
+            DataFile dataFile = (DataFile)i.next();
             getWriter().force(dataFile);
         }
     }
 
-        
-    /* (non-Javadoc)
-	 * @see org.apache.activemq.kaha.impl.data.IDataManager#delete()
-	 */
-    public synchronized boolean delete() throws IOException{
-        boolean result=true;
-        for(Iterator i=fileMap.values().iterator();i.hasNext();){
-            DataFile dataFile=(DataFile) i.next();
-            result&=dataFile.delete();
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.activemq.kaha.impl.data.IDataManager#delete()
+     */
+    public synchronized boolean delete() throws IOException {
+        boolean result = true;
+        for (Iterator i = fileMap.values().iterator(); i.hasNext();) {
+            DataFile dataFile = (DataFile)i.next();
+            result &= dataFile.delete();
         }
         fileMap.clear();
         return result;
     }
-    
 
-    /* (non-Javadoc)
-	 * @see org.apache.activemq.kaha.impl.data.IDataManager#addInterestInFile(int)
-	 */
-    public synchronized void addInterestInFile(int file) throws IOException{
-        if(file>=0){
-            Integer key=Integer.valueOf(file);
-            DataFile dataFile=(DataFile) fileMap.get(key);
-            if(dataFile==null){
-                dataFile=createAndAddDataFile(file);
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.activemq.kaha.impl.data.IDataManager#addInterestInFile(int)
+     */
+    public synchronized void addInterestInFile(int file) throws IOException {
+        if (file >= 0) {
+            Integer key = Integer.valueOf(file);
+            DataFile dataFile = (DataFile)fileMap.get(key);
+            if (dataFile == null) {
+                dataFile = createAndAddDataFile(file);
             }
             addInterestInFile(dataFile);
         }
     }
 
-    synchronized void addInterestInFile(DataFile dataFile){
-        if(dataFile!=null){
+    synchronized void addInterestInFile(DataFile dataFile) {
+        if (dataFile != null) {
             dataFile.increment();
         }
     }
 
-    /* (non-Javadoc)
-	 * @see org.apache.activemq.kaha.impl.data.IDataManager#removeInterestInFile(int)
-	 */
-    public synchronized void removeInterestInFile(int file) throws IOException{
-        if(file>=0){
-            Integer key=Integer.valueOf(file);
-            DataFile dataFile=(DataFile) fileMap.get(key);
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.activemq.kaha.impl.data.IDataManager#removeInterestInFile(int)
+     */
+    public synchronized void removeInterestInFile(int file) throws IOException {
+        if (file >= 0) {
+            Integer key = Integer.valueOf(file);
+            DataFile dataFile = (DataFile)fileMap.get(key);
             removeInterestInFile(dataFile);
         }
     }
 
-    synchronized void removeInterestInFile(DataFile dataFile) throws IOException{
-        if(dataFile!=null){
-            if(dataFile.decrement()<=0){
-                if(dataFile!=currentWriteFile){
+    synchronized void removeInterestInFile(DataFile dataFile) throws IOException {
+        if (dataFile != null) {
+            if (dataFile.decrement() <= 0) {
+                if (dataFile != currentWriteFile) {
                     removeDataFile(dataFile);
                 }
             }
         }
     }
 
-    /* (non-Javadoc)
-	 * @see org.apache.activemq.kaha.impl.data.IDataManager#consolidateDataFiles()
-	 */
-    public synchronized void consolidateDataFiles() throws IOException{
-        List purgeList=new ArrayList();
-        for(Iterator i=fileMap.values().iterator();i.hasNext();){
-            DataFile dataFile=(DataFile) i.next();
-            if(dataFile.isUnused() && dataFile != currentWriteFile){
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.activemq.kaha.impl.data.IDataManager#consolidateDataFiles()
+     */
+    public synchronized void consolidateDataFiles() throws IOException {
+        List purgeList = new ArrayList();
+        for (Iterator i = fileMap.values().iterator(); i.hasNext();) {
+            DataFile dataFile = (DataFile)i.next();
+            if (dataFile.isUnused() && dataFile != currentWriteFile) {
                 purgeList.add(dataFile);
             }
         }
-        for(int i=0;i<purgeList.size();i++){
-            DataFile dataFile=(DataFile) purgeList.get(i);
+        for (int i = 0; i < purgeList.size(); i++) {
+            DataFile dataFile = (DataFile)purgeList.get(i);
             removeDataFile(dataFile);
         }
     }
 
-    private void removeDataFile(DataFile dataFile) throws IOException{
+    private void removeDataFile(DataFile dataFile) throws IOException {
         fileMap.remove(dataFile.getNumber());
-        if(writer!=null){
+        if (writer != null) {
             writer.force(dataFile);
         }
-        boolean result=dataFile.delete();
-        log.debug("discarding data file "+dataFile+(result?"successful ":"failed"));
+        boolean result = dataFile.delete();
+        log.debug("discarding data file " + dataFile + (result ? "successful " : "failed"));
     }
 
-    /* (non-Javadoc)
-	 * @see org.apache.activemq.kaha.impl.data.IDataManager#getRedoMarshaller()
-	 */
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.activemq.kaha.impl.data.IDataManager#getRedoMarshaller()
+     */
     public Marshaller getRedoMarshaller() {
         return redoMarshaller;
     }
 
-    /* (non-Javadoc)
-	 * @see org.apache.activemq.kaha.impl.data.IDataManager#setRedoMarshaller(org.apache.activemq.kaha.Marshaller)
-	 */
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.activemq.kaha.impl.data.IDataManager#setRedoMarshaller(org.apache.activemq.kaha.Marshaller)
+     */
     public void setRedoMarshaller(Marshaller redoMarshaller) {
         this.redoMarshaller = redoMarshaller;
     }
@@ -317,45 +349,49 @@
     /**
      * @return the maxFileLength
      */
-    public long getMaxFileLength(){
+    public long getMaxFileLength() {
         return maxFileLength;
     }
 
     /**
      * @param maxFileLength the maxFileLength to set
      */
-    public void setMaxFileLength(long maxFileLength){
-        this.maxFileLength=maxFileLength;
+    public void setMaxFileLength(long maxFileLength) {
+        this.maxFileLength = maxFileLength;
+    }
+
+    public String toString() {
+        return "DataManager:(" + NAME_PREFIX + name + ")";
+    }
+
+    public synchronized SyncDataFileReader getReader() {
+        if (reader == null) {
+            reader = createReader();
+        }
+        return reader;
+    }
+
+    protected synchronized SyncDataFileReader createReader() {
+        return new SyncDataFileReader(this);
+    }
+
+    public synchronized void setReader(SyncDataFileReader reader) {
+        this.reader = reader;
+    }
+
+    public synchronized SyncDataFileWriter getWriter() {
+        if (writer == null) {
+            writer = createWriter();
+        }
+        return writer;
+    }
+
+    private SyncDataFileWriter createWriter() {
+        return new SyncDataFileWriter(this);
+    }
+
+    public synchronized void setWriter(SyncDataFileWriter writer) {
+        this.writer = writer;
     }
-    
-    public String toString(){
-        return "DataManager:("+NAME_PREFIX+name+")";
-    }
-
-	public synchronized SyncDataFileReader getReader() {
-		if( reader == null ) {
-			reader = createReader();
-		}
-		return reader;
-	}
-	protected synchronized SyncDataFileReader createReader() {
-		return new SyncDataFileReader(this);
-	}
-	public synchronized void setReader(SyncDataFileReader reader) {
-		this.reader = reader;
-	}
-
-	public synchronized SyncDataFileWriter getWriter() {
-		if( writer==null ) {
-			writer = createWriter();
-		}
-		return writer;
-	}
-	private SyncDataFileWriter createWriter() {
-		return new SyncDataFileWriter(this);
-	}
-	public synchronized void setWriter(SyncDataFileWriter writer) {
-		this.writer = writer;
-	}
 
 }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/Item.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/Item.java?view=diff&rev=563982&r1=563981&r2=563982
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/Item.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/Item.java Wed Aug  8 11:56:59 2007
@@ -21,10 +21,10 @@
  * 
  * @version $Revision: 1.2 $
  */
-public interface Item{
-    static final long POSITION_NOT_SET=-1;
-    static final short MAGIC=31317;
-    static final int ACTIVE=22;
-    static final int FREE=33;
-    static final int LOCATION_SIZE=24;
+public interface Item {
+    static final long POSITION_NOT_SET = -1;
+    static final short MAGIC = 31317;
+    static final int ACTIVE = 22;
+    static final int FREE = 33;
+    static final int LOCATION_SIZE = 24;
 }



Mime
View raw message