activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r546559 - in /activemq/trunk/activemq-core/src/main/java/org/apache/activemq: kaha/impl/index/hash/HashBin.java kaha/impl/index/hash/HashPage.java kaha/impl/index/tree/TreePage.java proxy/ProxyConnector.java
Date Tue, 12 Jun 2007 16:23:03 GMT
Author: jstrachan
Date: Tue Jun 12 09:23:02 2007
New Revision: 546559

URL: http://svn.apache.org/viewvc?view=rev&rev=546559
Log:
removed System.out.println statements

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashBin.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashPage.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreePage.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/proxy/ProxyConnector.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashBin.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashBin.java?view=diff&rev=546559&r1=546558&r2=546559
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashBin.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashBin.java Tue Jun 12 09:23:02 2007
@@ -1,299 +1,312 @@
 /**
- * 
+ *
  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
  * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
  * to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
  * License. You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-
 package org.apache.activemq.kaha.impl.index.hash;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
 /**
  * Bin in a HashIndex
- * 
+ *
  * @version $Revision: 1.1.1.1 $
  */
-class HashBin{
-
+class HashBin {
+    private static final transient Log log = LogFactory.getLog(HashBin.class);
     private HashIndex hashIndex;
     private int id;
     private int maximumEntries;
-    private int size=0;
-    private List<HashPageInfo> hashPages=new ArrayList<HashPageInfo>();
+    private int size = 0;
+    private List<HashPageInfo> hashPages = new ArrayList<HashPageInfo>();
 
     /**
      * Constructor
-     * 
+     *
      * @param hashIndex
      * @param id
      * @param maximumEntries
      */
-    HashBin(HashIndex hashIndex,int id,int maximumEntries){
-        this.hashIndex=hashIndex;
-        this.id=id;
-        this.maximumEntries=maximumEntries;
+    HashBin(HashIndex hashIndex, int id, int maximumEntries) {
+        this.hashIndex = hashIndex;
+        this.id = id;
+        this.maximumEntries = maximumEntries;
     }
 
-    public String toString(){
-        return "HashBin["+getId()+"]";
+    public String toString() {
+        return "HashBin[" + getId() + "]";
     }
 
-    public boolean equals(Object o){
-        boolean result=false;
-        if(o instanceof HashBin){
-            HashBin other=(HashBin)o;
-            result=other.id==id;
+    public boolean equals(Object o) {
+        boolean result = false;
+        if (o instanceof HashBin) {
+            HashBin other = (HashBin) o;
+            result = other.id == id;
         }
         return result;
     }
 
-    public int hashCode(){
-        return (int)id;
+    public int hashCode() {
+        return (int) id;
     }
 
-    int getId(){
+    int getId() {
         return id;
     }
 
-    void setId(int id){
-        this.id=id;
+    void setId(int id) {
+        this.id = id;
     }
 
-    boolean isEmpty(){
+    boolean isEmpty() {
         return true;
     }
 
-    int getMaximumEntries(){
+    int getMaximumEntries() {
         return this.maximumEntries;
     }
 
-    void setMaximumEntries(int maximumEntries){
-        this.maximumEntries=maximumEntries;
+    void setMaximumEntries(int maximumEntries) {
+        this.maximumEntries = maximumEntries;
     }
 
-    int size(){
+    int size() {
         return size;
     }
 
-    HashPageInfo addHashPageInfo(long id,int size){
-        HashPageInfo info=new HashPageInfo(hashIndex);
+    HashPageInfo addHashPageInfo(long id, int size) {
+        HashPageInfo info = new HashPageInfo(hashIndex);
         info.setId(id);
         info.setSize(size);
         hashPages.add(info);
-        this.size+=size;
+        this.size += size;
         return info;
     }
 
-    public HashEntry find(HashEntry key) throws IOException{
-        HashEntry result=null;
-        try{
-            int low=0;
-            int high=size()-1;
-            while(low<=high){
-                int mid=(low+high)>>1;
-                HashEntry te=getHashEntry(mid);
-                int cmp=te.compareTo(key);
-                if(cmp==0){
-                    result=te;
+    public HashEntry find(HashEntry key) throws IOException {
+        HashEntry result = null;
+        try {
+            int low = 0;
+            int high = size() - 1;
+            while (low <= high) {
+                int mid = (low + high) >> 1;
+                HashEntry te = getHashEntry(mid);
+                int cmp = te.compareTo(key);
+                if (cmp == 0) {
+                    result = te;
                     break;
-                }else if(cmp<0){
-                    low=mid+1;
-                }else{
-                    high=mid-1;
+                }
+                else if (cmp < 0) {
+                    low = mid + 1;
+                }
+                else {
+                    high = mid - 1;
                 }
             }
-        }finally{
+        }
+        finally {
             end();
         }
         return result;
     }
 
-    void put(HashEntry newEntry) throws IOException{
-        try{
-            boolean replace=false;
-            int low=0;
-            int high=size()-1;
-            while(low<=high){
-                int mid=(low+high)>>1;
-                HashEntry midVal=getHashEntry(mid);
-                int cmp=midVal.compareTo(newEntry);
-                if(cmp<0){
-                    low=mid+1;
-                }else if(cmp>0){
-                    high=mid-1;
-                }else{
-                    replace=true;
+    void put(HashEntry newEntry) throws IOException {
+        try {
+            boolean replace = false;
+            int low = 0;
+            int high = size() - 1;
+            while (low <= high) {
+                int mid = (low + high) >> 1;
+                HashEntry midVal = getHashEntry(mid);
+                int cmp = midVal.compareTo(newEntry);
+                if (cmp < 0) {
+                    low = mid + 1;
+                }
+                else if (cmp > 0) {
+                    high = mid - 1;
+                }
+                else {
+                    replace = true;
                     midVal.setIndexOffset(newEntry.getIndexOffset());
                     break;
                 }
             }
-            if(!replace){
+            if (!replace) {
                 if (low > size()) {
-                   System.out.println("SIZE() " + size() + " low = " + low); 
+                    log.info("SIZE() " + size() + " low = " + low);
                 }
-                addHashEntry(low,newEntry);
+                addHashEntry(low, newEntry);
                 size++;
             }
-        }finally{
+        }
+        finally {
             end();
         }
     }
 
-    HashEntry remove(HashEntry entry) throws IOException{
+    HashEntry remove(HashEntry entry) throws IOException {
         HashEntry result = null;
-        try{
-            int low=0;
-            int high=size()-1;
-            while(low<=high){
-                int mid=(low+high)>>1;
-                HashEntry te=getHashEntry(mid);
-                int cmp=te.compareTo(entry);
-                if(cmp==0){
-                    result =te;
+        try {
+            int low = 0;
+            int high = size() - 1;
+            while (low <= high) {
+                int mid = (low + high) >> 1;
+                HashEntry te = getHashEntry(mid);
+                int cmp = te.compareTo(entry);
+                if (cmp == 0) {
+                    result = te;
                     removeHashEntry(mid);
                     size--;
                     break;
-                }else if(cmp<0){
-                    low=mid+1;
-                }else{
-                    high=mid-1;
+                }
+                else if (cmp < 0) {
+                    low = mid + 1;
+                }
+                else {
+                    high = mid - 1;
                 }
             }
-        }finally{
+        }
+        finally {
             end();
         }
         return result;
     }
 
-    private void addHashEntry(int index,HashEntry entry) throws IOException{
-        HashPageInfo page=getInsertPage(index);
-        int offset=index%maximumEntries;
-        page.addHashEntry(offset,entry);
+    private void addHashEntry(int index, HashEntry entry) throws IOException {
+        HashPageInfo page = getInsertPage(index);
+        int offset = index % maximumEntries;
+        page.addHashEntry(offset, entry);
         doOverFlow(index);
     }
 
-    private HashEntry removeHashEntry(int index) throws IOException{
-        HashPageInfo page=getRetrievePage(index);
-        int offset=getRetrieveOffset(index);
-        HashEntry result=page.removeHashEntry(offset);
+    private HashEntry removeHashEntry(int index) throws IOException {
+        HashPageInfo page = getRetrievePage(index);
+        int offset = getRetrieveOffset(index);
+        HashEntry result = page.removeHashEntry(offset);
         doUnderFlow(index);
         return result;
     }
 
-    private HashEntry getHashEntry(int index) throws IOException{
-        HashPageInfo page=getRetrievePage(index);
+    private HashEntry getHashEntry(int index) throws IOException {
+        HashPageInfo page = getRetrievePage(index);
         page.begin();
-        int offset=getRetrieveOffset(index);
-        HashEntry result=page.getHashEntry(offset);
+        int offset = getRetrieveOffset(index);
+        HashEntry result = page.getHashEntry(offset);
         return result;
     }
 
-    private int maximumBinSize(){
-        return maximumEntries*hashPages.size();
+    private int maximumBinSize() {
+        return maximumEntries * hashPages.size();
     }
 
-    private HashPageInfo getInsertPage(int index) throws IOException{
-        HashPageInfo result=null;
-        if(index>=maximumBinSize()){
-            HashPage page=hashIndex.createPage(id);
-            result=addHashPageInfo(page.getId(),0);
+    private HashPageInfo getInsertPage(int index) throws IOException {
+        HashPageInfo result = null;
+        if (index >= maximumBinSize()) {
+            HashPage page = hashIndex.createPage(id);
+            result = addHashPageInfo(page.getId(), 0);
             result.setPage(page);
-        }else{
-            int offset=index/maximumEntries;
-            result=hashPages.get(offset);
+        }
+        else {
+            int offset = index / maximumEntries;
+            result = hashPages.get(offset);
         }
         result.begin();
         return result;
     }
 
-    private HashPageInfo getRetrievePage(int index) throws IOException{
-        HashPageInfo result=null;
-        int count=0;
-        int pageNo=0;
-        for(HashPageInfo page:hashPages){
-            count+=page.size();
-            if(index<count){
+    private HashPageInfo getRetrievePage(int index) throws IOException {
+        HashPageInfo result = null;
+        int count = 0;
+        int pageNo = 0;
+        for (HashPageInfo page : hashPages) {
+            count += page.size();
+            if (index < count) {
                 break;
             }
             pageNo++;
         }
-        result=hashPages.get(pageNo);
+        result = hashPages.get(pageNo);
         result.begin();
         return result;
     }
 
-    private int getRetrieveOffset(int index) throws IOException{
-        int result=0;
-        int count=0;
-        for(HashPageInfo page:hashPages){
-            if((index+1)<=(count+page.size())){
+    private int getRetrieveOffset(int index) throws IOException {
+        int result = 0;
+        int count = 0;
+        for (HashPageInfo page : hashPages) {
+            if ((index + 1) <= (count + page.size())) {
                 // count=count==0?count:count+1;
-                result=index-count;
+                result = index - count;
                 break;
             }
-            count+=page.size();
+            count += page.size();
         }
         return result;
     }
 
-    private int getInsertPageNo(int index){
-        int result=index/maximumEntries;
+    private int getInsertPageNo(int index) {
+        int result = index / maximumEntries;
         return result;
     }
 
-    private int getOffset(int index){
-        int result=index%maximumEntries;
+    private int getOffset(int index) {
+        int result = index % maximumEntries;
         return result;
     }
 
-    private void doOverFlow(int index) throws IOException{
-        int pageNo=index/maximumEntries;
-        HashPageInfo info=hashPages.get(pageNo);
-        if(info.size()>maximumEntries){
+    private void doOverFlow(int index) throws IOException {
+        int pageNo = index / maximumEntries;
+        HashPageInfo info = hashPages.get(pageNo);
+        if (info.size() > maximumEntries) {
             // overflowed
-            HashEntry entry=info.removeHashEntry(info.size()-1);
-            doOverFlow(pageNo+1,entry);
+            HashEntry entry = info.removeHashEntry(info.size() - 1);
+            doOverFlow(pageNo + 1, entry);
         }
     }
 
-    private void doOverFlow(int pageNo,HashEntry entry) throws IOException{
-        HashPageInfo info=null;
-        if(pageNo>=hashPages.size()){
-            HashPage page=hashIndex.createPage(id);
-            info=addHashPageInfo(page.getId(),0);
+    private void doOverFlow(int pageNo, HashEntry entry) throws IOException {
+        HashPageInfo info = null;
+        if (pageNo >= hashPages.size()) {
+            HashPage page = hashIndex.createPage(id);
+            info = addHashPageInfo(page.getId(), 0);
             info.setPage(page);
-        }else{
-            info=hashPages.get(pageNo);
+        }
+        else {
+            info = hashPages.get(pageNo);
         }
         info.begin();
-        info.addHashEntry(0,entry);
-        if(info.size()>maximumEntries){
+        info.addHashEntry(0, entry);
+        if (info.size() > maximumEntries) {
             // overflowed
-            HashEntry overflowed=info.removeHashEntry(info.size()-1);
-            doOverFlow(pageNo+1,overflowed);
+            HashEntry overflowed = info.removeHashEntry(info.size() - 1);
+            doOverFlow(pageNo + 1, overflowed);
         }
     }
 
-    private void doUnderFlow(int index){
-        int pageNo=index/maximumEntries;
-        int nextPageNo=pageNo+1;
-        if(nextPageNo<hashPages.size()){
+    private void doUnderFlow(int index) {
+        int pageNo = index / maximumEntries;
+        int nextPageNo = pageNo + 1;
+        if (nextPageNo < hashPages.size()) {
         }
-        HashPageInfo info=hashPages.get(pageNo);
+        HashPageInfo info = hashPages.get(pageNo);
     }
 
-    private void end() throws IOException{
-        for(HashPageInfo info:hashPages){
+    private void end() throws IOException {
+        for (HashPageInfo info : hashPages) {
             info.end();
         }
     }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashPage.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashPage.java?view=diff&rev=546559&r1=546558&r2=546559
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashPage.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashPage.java Tue Jun 12 09:23:02 2007
@@ -1,39 +1,36 @@
 /**
- * 
+ *
  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
  * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
  * to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
  * License. You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-
 package org.apache.activemq.kaha.impl.index.hash;
 
+import org.apache.activemq.kaha.Marshaller;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
-import org.apache.activemq.kaha.Marshaller;
 
 /**
  * A Page within a HashPage
- * 
+ *
  * @version $Revision: 1.1.1.1 $
  */
-class HashPage{
-
-    static final int PAGE_HEADER_SIZE=17;
-
-    
-   
+class HashPage {
+    private static final transient Log log = LogFactory.getLog(HashPage.class);
+    static final int PAGE_HEADER_SIZE = 17;
     private int maximumEntries;
     private long id;
     private int binId;
@@ -42,206 +39,196 @@
     /*
      * for persistence only
      */
-    private long nextFreePageId=HashEntry.NOT_SET;
-    private boolean active=true;
+    private long nextFreePageId = HashEntry.NOT_SET;
+    private boolean active = true;
 
     /**
      * Constructor
-     * 
+     *
      * @param hashIndex
      * @param id
      * @param parentId
      * @param maximumEntries
      */
-    HashPage(long id,int maximumEntries){
+    HashPage(long id, int maximumEntries) {
         this(maximumEntries);
-       
-        this.id=id;
+
+        this.id = id;
     }
 
     /**
      * Constructor
-     * 
+     *
      * @param maximumEntries
      */
-    public HashPage(int maximumEntries){
-        this.maximumEntries=maximumEntries;
-        this.hashIndexEntries=new ArrayList<HashEntry>(maximumEntries);
+    public HashPage(int maximumEntries) {
+        this.maximumEntries = maximumEntries;
+        this.hashIndexEntries = new ArrayList<HashEntry>(maximumEntries);
     }
 
-    public String toString(){
-        return "HashPage["+getId()+":" + binId + "]";
+    public String toString() {
+        return "HashPage[" + getId() + ":" + binId + "]";
     }
 
-    public boolean equals(Object o){
-        boolean result=false;
-        if(o instanceof HashPage){
-            HashPage other=(HashPage)o;
-            result=other.id==id;
+    public boolean equals(Object o) {
+        boolean result = false;
+        if (o instanceof HashPage) {
+            HashPage other = (HashPage) o;
+            result = other.id == id;
         }
         return result;
     }
 
-    public int hashCode(){
-        return (int)id;
+    public int hashCode() {
+        return (int) id;
     }
 
-    boolean isActive(){
+    boolean isActive() {
         return this.active;
     }
 
-    void setActive(boolean active){
-        this.active=active;
+    void setActive(boolean active) {
+        this.active = active;
     }
 
-    long getNextFreePageId(){
+    long getNextFreePageId() {
         return this.nextFreePageId;
     }
 
-    void setNextFreePageId(long nextPageId){
-        this.nextFreePageId=nextPageId;
+    void setNextFreePageId(long nextPageId) {
+        this.nextFreePageId = nextPageId;
     }
 
-    long getId(){
+    long getId() {
         return id;
     }
 
-    void setId(long id){
-        this.id=id;
+    void setId(long id) {
+        this.id = id;
     }
-    
+
     int getPersistedSize() {
         return persistedSize;
     }
 
-    void write(Marshaller keyMarshaller,DataOutput dataOut) throws IOException{
+    void write(Marshaller keyMarshaller, DataOutput dataOut) throws IOException {
         writeHeader(dataOut);
         dataOut.writeInt(hashIndexEntries.size());
-        for(HashEntry entry:hashIndexEntries){
-            entry.write(keyMarshaller,dataOut);
+        for (HashEntry entry : hashIndexEntries) {
+            entry.write(keyMarshaller, dataOut);
         }
     }
 
-    void read(Marshaller keyMarshaller,DataInput dataIn) throws IOException{
+    void read(Marshaller keyMarshaller, DataInput dataIn) throws IOException {
         readHeader(dataIn);
-        int size=dataIn.readInt();
+        int size = dataIn.readInt();
         hashIndexEntries.clear();
-        for(int i=0;i<size;i++){
-            HashEntry entry=new HashEntry();
-            entry.read(keyMarshaller,dataIn);
+        for (int i = 0; i < size; i++) {
+            HashEntry entry = new HashEntry();
+            entry.read(keyMarshaller, dataIn);
             hashIndexEntries.add(entry);
         }
     }
 
-    void readHeader(DataInput dataIn) throws IOException{
-        active=dataIn.readBoolean();
-        nextFreePageId=dataIn.readLong();
-        binId=dataIn.readInt();
-        persistedSize=dataIn.readInt();
+    void readHeader(DataInput dataIn) throws IOException {
+        active = dataIn.readBoolean();
+        nextFreePageId = dataIn.readLong();
+        binId = dataIn.readInt();
+        persistedSize = dataIn.readInt();
     }
 
-    void writeHeader(DataOutput dataOut) throws IOException{
+    void writeHeader(DataOutput dataOut) throws IOException {
         dataOut.writeBoolean(isActive());
         dataOut.writeLong(nextFreePageId);
         dataOut.writeInt(binId);
         dataOut.writeInt(size());
     }
 
-    boolean isEmpty(){
+    boolean isEmpty() {
         return hashIndexEntries.isEmpty();
     }
 
-    boolean isFull(){
-        return(hashIndexEntries.size()>=maximumEntries);
+    boolean isFull() {
+        return (hashIndexEntries.size() >= maximumEntries);
     }
 
-    boolean isUnderflowed(){
-        return hashIndexEntries.size()<(maximumEntries/2);
+    boolean isUnderflowed() {
+        return hashIndexEntries.size() < (maximumEntries / 2);
     }
 
-    boolean isOverflowed(){
-        return hashIndexEntries.size()>maximumEntries;
+    boolean isOverflowed() {
+        return hashIndexEntries.size() > maximumEntries;
     }
 
-    List<HashEntry> getEntries(){
+    List<HashEntry> getEntries() {
         return hashIndexEntries;
     }
 
-    void setEntries(List<HashEntry> newEntries){
-        this.hashIndexEntries=newEntries;
+    void setEntries(List<HashEntry> newEntries) {
+        this.hashIndexEntries = newEntries;
     }
 
-    int getMaximumEntries(){
+    int getMaximumEntries() {
         return this.maximumEntries;
     }
 
-    void setMaximumEntries(int maximumEntries){
-        this.maximumEntries=maximumEntries;
+    void setMaximumEntries(int maximumEntries) {
+        this.maximumEntries = maximumEntries;
     }
 
-    int size(){
+    int size() {
         return hashIndexEntries.size();
     }
 
-    
-    void reset() throws IOException{
+    void reset() throws IOException {
         hashIndexEntries.clear();
         setNextFreePageId(HashEntry.NOT_SET);
     }
 
-        
-
-    void addHashEntry(int index,HashEntry entry) throws IOException{
+    void addHashEntry(int index, HashEntry entry) throws IOException {
         //index = index >= 0 ? index : 0;
         //index = (index == 0 || index< size()) ? index : size()-1;
-        hashIndexEntries.add(index,entry);
+        hashIndexEntries.add(index, entry);
     }
-    
 
-    HashEntry getHashEntry(int index){
-        HashEntry result=hashIndexEntries.get(index);
+    HashEntry getHashEntry(int index) {
+        HashEntry result = hashIndexEntries.get(index);
         return result;
     }
 
-    HashEntry removeHashEntry(int index) throws IOException{
-        HashEntry result=hashIndexEntries.remove(index);
+    HashEntry removeHashEntry(int index) throws IOException {
+        HashEntry result = hashIndexEntries.remove(index);
         return result;
     }
 
-    void removeAllTreeEntries(List<HashEntry> c){
+    void removeAllTreeEntries(List<HashEntry> c) {
         hashIndexEntries.removeAll(c);
     }
 
-    List<HashEntry> getSubList(int from,int to){
-        return new ArrayList<HashEntry>(hashIndexEntries.subList(from,to));
+    List<HashEntry> getSubList(int from, int to) {
+        return new ArrayList<HashEntry>(hashIndexEntries.subList(from, to));
     }
 
-
-    
     /**
      * @return the binId
      */
-    int getBinId(){
+    int getBinId() {
         return this.binId;
     }
 
-    
     /**
      * @param binId the binId to set
      */
-    void setBinId(int binId){
-        this.binId=binId;
+    void setBinId(int binId) {
+        this.binId = binId;
     }
-    
-    
+
     void dump() {
-        
+
         String str = this + ": ";
-        for(HashEntry entry: hashIndexEntries) {
+        for (HashEntry entry : hashIndexEntries) {
             str += entry + ",";
         }
-        System.out.println(str);
+        log.info(str);
     }
-
-    
 }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreePage.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreePage.java?view=diff&rev=546559&r1=546558&r2=546559
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreePage.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreePage.java Tue Jun 12 09:23:02 2007
@@ -1,19 +1,22 @@
 /**
- * 
+ *
  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
  * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
  * to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
  * License. You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-
 package org.apache.activemq.kaha.impl.index.tree;
 
+import org.apache.activemq.kaha.Marshaller;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
@@ -21,348 +24,361 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
-import org.apache.activemq.kaha.Marshaller;
 
 /**
  * Page in a BTree
- * 
+ *
  * @version $Revision: 1.1.1.1 $
  */
-class TreePage{
-
-    static final int PAGE_HEADER_SIZE=18;
+class TreePage {
+    private static final transient Log log = LogFactory.getLog(TreePage.class);
+    static final int PAGE_HEADER_SIZE = 18;
 
-    static enum Flavour{
-        LESS,MORE
+    static enum Flavour {
+        LESS, MORE
     }
+
     private TreeIndex tree;
     private int maximumEntries;
     private long id;
-    private long parentId=TreeEntry.NOT_SET;
-    private boolean leaf=true;
+    private long parentId = TreeEntry.NOT_SET;
+    private boolean leaf = true;
     private List<TreeEntry> treeEntries;
     /*
      * for persistence only
      */
-    private long nextFreePageId=TreeEntry.NOT_SET;
-    private boolean active=true;
+    private long nextFreePageId = TreeEntry.NOT_SET;
+    private boolean active = true;
 
     /**
      * Constructor
-     * 
+     *
      * @param tree
      * @param id
      * @param parentId
      * @param maximumEntries
      */
-    TreePage(TreeIndex tree,long id,long parentId,int maximumEntries){
+    TreePage(TreeIndex tree, long id, long parentId, int maximumEntries) {
         this(maximumEntries);
-        this.tree=tree;
-        this.id=id;
-        this.parentId=parentId;
+        this.tree = tree;
+        this.id = id;
+        this.parentId = parentId;
     }
 
     /**
      * Constructor
-     * 
+     *
      * @param maximumEntries
      */
-    public TreePage(int maximumEntries){
-        this.maximumEntries=maximumEntries;
-        this.treeEntries=new ArrayList<TreeEntry>(maximumEntries);
+    public TreePage(int maximumEntries) {
+        this.maximumEntries = maximumEntries;
+        this.treeEntries = new ArrayList<TreeEntry>(maximumEntries);
     }
 
-    public String toString(){
-        return "TreePage["+getId()+"]parent="+getParentId();
+    public String toString() {
+        return "TreePage[" + getId() + "]parent=" + getParentId();
     }
 
-    public boolean equals(Object o){
-        boolean result=false;
-        if(o instanceof TreePage){
-            TreePage other=(TreePage)o;
-            result=other.id==id;
+    public boolean equals(Object o) {
+        boolean result = false;
+        if (o instanceof TreePage) {
+            TreePage other = (TreePage) o;
+            result = other.id == id;
         }
         return result;
     }
 
-    public int hashCode(){
-        return (int)id;
+    public int hashCode() {
+        return (int) id;
     }
 
-    boolean isActive(){
+    boolean isActive() {
         return this.active;
     }
 
-    void setActive(boolean active){
-        this.active=active;
+    void setActive(boolean active) {
+        this.active = active;
     }
 
-    long getNextFreePageId(){
+    long getNextFreePageId() {
         return this.nextFreePageId;
     }
 
-    void setNextFreePageId(long nextPageId){
-        this.nextFreePageId=nextPageId;
+    void setNextFreePageId(long nextPageId) {
+        this.nextFreePageId = nextPageId;
     }
 
-    long getId(){
+    long getId() {
         return id;
     }
 
-    void setId(long id){
-        this.id=id;
+    void setId(long id) {
+        this.id = id;
     }
 
-    void write(Marshaller keyMarshaller,DataOutput dataOut) throws IOException{
+    void write(Marshaller keyMarshaller, DataOutput dataOut) throws IOException {
         writeHeader(dataOut);
         dataOut.writeInt(treeEntries.size());
-        for(TreeEntry entry:treeEntries){
-            entry.write(keyMarshaller,dataOut);
+        for (TreeEntry entry : treeEntries) {
+            entry.write(keyMarshaller, dataOut);
         }
     }
 
-    void read(Marshaller keyMarshaller,DataInput dataIn) throws IOException{
+    void read(Marshaller keyMarshaller, DataInput dataIn) throws IOException {
         readHeader(dataIn);
-        int size=dataIn.readInt();
+        int size = dataIn.readInt();
         treeEntries.clear();
-        for(int i=0;i<size;i++){
-            TreeEntry entry=new TreeEntry();
-            entry.read(keyMarshaller,dataIn);
+        for (int i = 0; i < size; i++) {
+            TreeEntry entry = new TreeEntry();
+            entry.read(keyMarshaller, dataIn);
             treeEntries.add(entry);
         }
     }
 
-    void readHeader(DataInput dataIn) throws IOException{
-        active=dataIn.readBoolean();
-        leaf=dataIn.readBoolean();
+    void readHeader(DataInput dataIn) throws IOException {
+        active = dataIn.readBoolean();
+        leaf = dataIn.readBoolean();
         setParentId(dataIn.readLong());
-        nextFreePageId=dataIn.readLong();
+        nextFreePageId = dataIn.readLong();
     }
 
-    void writeHeader(DataOutput dataOut) throws IOException{
+    void writeHeader(DataOutput dataOut) throws IOException {
         dataOut.writeBoolean(isActive());
         dataOut.writeBoolean(isLeaf());
         dataOut.writeLong(getParentId());
         dataOut.writeLong(nextFreePageId);
     }
 
-    boolean isEmpty(){
+    boolean isEmpty() {
         return treeEntries.isEmpty();
     }
 
-    boolean isFull(){
-        return(treeEntries.size()>=maximumEntries);
+    boolean isFull() {
+        return (treeEntries.size() >= maximumEntries);
     }
 
-    boolean isRoot(){
-        return getParentId()<0;
+    boolean isRoot() {
+        return getParentId() < 0;
     }
 
-    boolean isLeaf(){
-        if(treeEntries.isEmpty()){
-            leaf=true;
+    boolean isLeaf() {
+        if (treeEntries.isEmpty()) {
+            leaf = true;
         }
         return leaf;
     }
 
-    boolean isUnderflowed(){
-        return treeEntries.size()<(maximumEntries/2);
+    boolean isUnderflowed() {
+        return treeEntries.size() < (maximumEntries / 2);
     }
 
-    boolean isOverflowed(){
-        return treeEntries.size()>maximumEntries;
+    boolean isOverflowed() {
+        return treeEntries.size() > maximumEntries;
     }
 
-    void setLeaf(boolean newValue){
-        this.leaf=newValue;
+    void setLeaf(boolean newValue) {
+        this.leaf = newValue;
     }
 
-    TreePage getParent() throws IOException{
+    TreePage getParent() throws IOException {
         return tree.lookupPage(parentId);
     }
 
-    long getParentId(){
+    long getParentId() {
         return parentId;
     }
 
-    void setParentId(long newId) throws IOException{
-        if(newId==this.id){
-            throw new IllegalStateException("Cannot set page as a child of itself "+this+" trying to set parentId = "
-                    +newId);
+    void setParentId(long newId) throws IOException {
+        if (newId == this.id) {
+            throw new IllegalStateException("Cannot set page as a child of itself " + this + " trying to set parentId = "
+                    + newId);
         }
-        this.parentId=newId;
+        this.parentId = newId;
         tree.writePage(this);
     }
 
-    List<TreeEntry> getEntries(){
+    List<TreeEntry> getEntries() {
         return treeEntries;
     }
 
-    void setEntries(List<TreeEntry> newEntries){
-        this.treeEntries=newEntries;
+    void setEntries(List<TreeEntry> newEntries) {
+        this.treeEntries = newEntries;
     }
 
-    int getMaximumEntries(){
+    int getMaximumEntries() {
         return this.maximumEntries;
     }
 
-    void setMaximumEntries(int maximumEntries){
-        this.maximumEntries=maximumEntries;
+    void setMaximumEntries(int maximumEntries) {
+        this.maximumEntries = maximumEntries;
     }
 
-    int size(){
+    int size() {
         return treeEntries.size();
     }
 
-    TreeIndex getTree(){
+    TreeIndex getTree() {
         return this.tree;
     }
 
-    void setTree(TreeIndex tree){
-        this.tree=tree;
+    void setTree(TreeIndex tree) {
+        this.tree = tree;
     }
 
-    void reset() throws IOException{
+    void reset() throws IOException {
         treeEntries.clear();
         setParentId(TreeEntry.NOT_SET);
         setNextFreePageId(TreeEntry.NOT_SET);
         setLeaf(true);
     }
 
-    public TreeEntry find(TreeEntry key) throws IOException{
-        int low=0;
-        int high=size()-1;
-        long pageId=-1;
-        while(low<=high){
-            int mid=(low+high)>>1;
-            TreeEntry te=getTreeEntry(mid);
-            int cmp=te.compareTo(key);
-            if(cmp==0){
+    public TreeEntry find(TreeEntry key) throws IOException {
+        int low = 0;
+        int high = size() - 1;
+        long pageId = -1;
+        while (low <= high) {
+            int mid = (low + high) >> 1;
+            TreeEntry te = getTreeEntry(mid);
+            int cmp = te.compareTo(key);
+            if (cmp == 0) {
                 return te;
-            }else if(cmp<0){
-                low=mid+1;
-                pageId=te.getNextPageId();
-            }else{
-                high=mid-1;
-                pageId=te.getPrevPageId();
+            }
+            else if (cmp < 0) {
+                low = mid + 1;
+                pageId = te.getNextPageId();
+            }
+            else {
+                high = mid - 1;
+                pageId = te.getPrevPageId();
             }
         }
-        TreePage page=tree.lookupPage(pageId);
-        if(page!=null){
+        TreePage page = tree.lookupPage(pageId);
+        if (page != null) {
             return page.find(key);
         }
         return null;
     }
 
-    TreeEntry put(TreeEntry newEntry) throws IOException{
-        TreeEntry result=null;
-        if(isRoot()){
-            if(isEmpty()){
-                insertTreeEntry(0,newEntry);
-            }else{
-                result=doInsert(null,newEntry);
+    TreeEntry put(TreeEntry newEntry) throws IOException {
+        TreeEntry result = null;
+        if (isRoot()) {
+            if (isEmpty()) {
+                insertTreeEntry(0, newEntry);
             }
-        }else{
-            throw new IllegalStateException("insert() should not be called on non root page - "+this);
+            else {
+                result = doInsert(null, newEntry);
+            }
+        }
+        else {
+            throw new IllegalStateException("insert() should not be called on non root page - " + this);
         }
         return result;
     }
 
-    TreeEntry remove(TreeEntry entry) throws IOException{
+    TreeEntry remove(TreeEntry entry) throws IOException {
         TreeEntry result = null;
-        if(isRoot()){
-            if(!isEmpty()){
+        if (isRoot()) {
+            if (!isEmpty()) {
                 result = doRemove(entry);
             }
-        }else{
+        }
+        else {
             throw new IllegalStateException("remove() should not be called on non root page");
         }
         return result;
     }
 
-    private TreeEntry doInsert(Flavour flavour,TreeEntry newEntry) throws IOException{
-        TreeEntry result=null;
-        TreePageEntry closest=findClosestEntry(newEntry);
-        if(closest!=null){
-            TreeEntry closestEntry=closest.getTreeEntry();
-            TreePage closestPage=closest.getTreePage();
-            int cmp=closestEntry.compareTo(newEntry);
-            if(cmp==0){
+    private TreeEntry doInsert(Flavour flavour, TreeEntry newEntry) throws IOException {
+        TreeEntry result = null;
+        TreePageEntry closest = findClosestEntry(newEntry);
+        if (closest != null) {
+            TreeEntry closestEntry = closest.getTreeEntry();
+            TreePage closestPage = closest.getTreePage();
+            int cmp = closestEntry.compareTo(newEntry);
+            if (cmp == 0) {
                 // we actually just need to pass back the value
-                long oldValue=closestEntry.getIndexOffset();
+                long oldValue = closestEntry.getIndexOffset();
                 closestEntry.setIndexOffset(newEntry.getIndexOffset());
                 newEntry.setIndexOffset(oldValue);
-                result=newEntry;
+                result = newEntry;
                 save();
-            }else if(closestPage!=null){
-                result=closestPage.doInsert(closest.getFlavour(),newEntry);
-            }else{
-                if(!isFull()){
-                    insertTreeEntry(closest.getIndex(),newEntry);
+            }
+            else if (closestPage != null) {
+                result = closestPage.doInsert(closest.getFlavour(), newEntry);
+            }
+            else {
+                if (!isFull()) {
+                    insertTreeEntry(closest.getIndex(), newEntry);
                     save();
-                }else{
-                    doOverflow(flavour,newEntry);
+                }
+                else {
+                    doOverflow(flavour, newEntry);
                 }
             }
-        }else{
-            if(!isFull()){
+        }
+        else {
+            if (!isFull()) {
                 doInsertEntry(newEntry);
                 save();
-            }else{
+            }
+            else {
                 // need to insert the new entry and propogate up the hightest value
-                doOverflow(flavour,newEntry);
+                doOverflow(flavour, newEntry);
             }
         }
         return result;
     }
 
-    private TreePage doOverflow(Flavour flavour,TreeEntry newEntry) throws IOException{
-        TreePage result=this;
-        TreeEntry theEntry=newEntry;
-        if(!isFull()){
+    private TreePage doOverflow(Flavour flavour, TreeEntry newEntry) throws IOException {
+        TreePage result = this;
+        TreeEntry theEntry = newEntry;
+        if (!isFull()) {
             doInsertEntry(newEntry);
             save();
-        }else{
-            if(!isRoot()&&flavour!=null){
+        }
+        else {
+            if (!isRoot() && flavour != null) {
                 // we aren't the root, but to ensure the correct distribution we need to
                 // insert the new entry and take a node of the end of the page
                 // and pass that up the tree to find a home
                 doInsertEntry(newEntry);
-                if(flavour==Flavour.LESS){
-                    theEntry=removeTreeEntry(0);
+                if (flavour == Flavour.LESS) {
+                    theEntry = removeTreeEntry(0);
                     theEntry.reset();
                     theEntry.setNextPageId(getId());
-                }else{
-                    theEntry=removeTreeEntry(size()-1);
+                }
+                else {
+                    theEntry = removeTreeEntry(size() - 1);
                     theEntry.reset();
                     theEntry.setPrevPageId(getId());
                 }
                 save();
-                
-                result=getParent().doOverflow(flavour,theEntry);
+
+                result = getParent().doOverflow(flavour, theEntry);
                 if (!theEntry.equals(newEntry)) {
                     //the newEntry stayed here
                     result = this;
                 }
-            }else{
+            }
+            else {
                 // so we are the root and need to split
                 doInsertEntry(newEntry);
-                int midIndex=(size()/2);
-                TreeEntry midEntry=removeTreeEntry(midIndex);
-                List<TreeEntry> subList=getSubList(midIndex,size());
+                int midIndex = (size() / 2);
+                TreeEntry midEntry = removeTreeEntry(midIndex);
+                List<TreeEntry> subList = getSubList(midIndex, size());
                 removeAllTreeEntries(subList);
-                TreePage newRoot=tree.createRoot();
+                TreePage newRoot = tree.createRoot();
                 newRoot.setLeaf(false);
                 this.setParentId(newRoot.getId());
                 save(); // we are no longer root - need to save - we maybe looked up v. soon!
-                TreePage rightPage=tree.createPage(newRoot.getId());
+                TreePage rightPage = tree.createPage(newRoot.getId());
                 rightPage.setEntries(subList);
                 rightPage.checkLeaf();
-                resetParentId(rightPage.getId(),rightPage.getEntries());
+                resetParentId(rightPage.getId(), rightPage.getEntries());
                 midEntry.setNextPageId(rightPage.getId());
                 midEntry.setPrevPageId(this.getId());
-                newRoot.insertTreeEntry(0,midEntry);
-                resetParentId(newRoot.getId(),newRoot.getEntries());
+                newRoot.insertTreeEntry(0, midEntry);
+                resetParentId(newRoot.getId(), newRoot.getEntries());
                 save();
                 rightPage.save();
                 newRoot.save();
@@ -371,22 +387,23 @@
         return result;
     }
 
-    private TreeEntry doRemove(TreeEntry entry) throws IOException{
+    private TreeEntry doRemove(TreeEntry entry) throws IOException {
         TreeEntry result = null;
-        TreePageEntry closest=findClosestEntry(entry);
-        if(closest!=null){
-            TreeEntry closestEntry=closest.getTreeEntry();
-            if(closestEntry!=null){
-                TreePage closestPage=closest.getTreePage();
-                int cmp=closestEntry.compareTo(entry);
-                if(cmp==0){
-                    result=closest.getTreeEntry();
-                    int index=closest.getIndex();
+        TreePageEntry closest = findClosestEntry(entry);
+        if (closest != null) {
+            TreeEntry closestEntry = closest.getTreeEntry();
+            if (closestEntry != null) {
+                TreePage closestPage = closest.getTreePage();
+                int cmp = closestEntry.compareTo(entry);
+                if (cmp == 0) {
+                    result = closest.getTreeEntry();
+                    int index = closest.getIndex();
                     removeTreeEntry(index);
                     save();
                     // ensure we don't loose children
-                    doUnderflow(result,index);
-                }else if(closestPage!=null){
+                    doUnderflow(result, index);
+                }
+                else if (closestPage != null) {
                     closestPage.doRemove(entry);
                 }
             }
@@ -398,347 +415,357 @@
      * @return true if the page is removed
      * @throws IOException
      */
-    private boolean doUnderflow() throws IOException{
-        boolean result=false;
-        boolean working=true;
-        while(working&&isUnderflowed()&&!isEmpty()&&!isLeaf()){
-            int lastIndex=size()-1;
-            TreeEntry entry=getTreeEntry(lastIndex);
-            working=doUnderflow(entry,lastIndex);
+    private boolean doUnderflow() throws IOException {
+        boolean result = false;
+        boolean working = true;
+        while (working && isUnderflowed() && !isEmpty() && !isLeaf()) {
+            int lastIndex = size() - 1;
+            TreeEntry entry = getTreeEntry(lastIndex);
+            working = doUnderflow(entry, lastIndex);
         }
-        if(isUnderflowed()&&isLeaf()){
-            result=doUnderflowLeaf();
+        if (isUnderflowed() && isLeaf()) {
+            result = doUnderflowLeaf();
         }
         return result;
     }
 
-    private boolean doUnderflow(TreeEntry entry,int index) throws IOException{
-        boolean result=false;
+    private boolean doUnderflow(TreeEntry entry, int index) throws IOException {
+        boolean result = false;
         // pull an entry up from a leaf to fill the empty space
-        if(entry.getNextPageId()!=TreeEntry.NOT_SET){
-            TreePage page=tree.lookupPage(entry.getNextPageId());
-            if(page!=null&&!page.isEmpty()){
-                TreeEntry replacement=page.removeTreeEntry(0);
-                TreeEntry copy=replacement.copy();
-                checkParentIdForRemovedPageEntry(copy,page.getId(),getId());
-                if(!page.isEmpty()){
+        if (entry.getNextPageId() != TreeEntry.NOT_SET) {
+            TreePage page = tree.lookupPage(entry.getNextPageId());
+            if (page != null && !page.isEmpty()) {
+                TreeEntry replacement = page.removeTreeEntry(0);
+                TreeEntry copy = replacement.copy();
+                checkParentIdForRemovedPageEntry(copy, page.getId(), getId());
+                if (!page.isEmpty()) {
                     copy.setNextPageId(page.getId());
                     page.setParentId(this.id);
-                }else{
+                }
+                else {
                     page.setLeaf(true);
                 }
-                int replacementIndex=doInsertEntry(copy);
-                if(page.doUnderflow()){
+                int replacementIndex = doInsertEntry(copy);
+                if (page.doUnderflow()) {
                     // page removed so update our replacement
-                    resetPageReference(replacementIndex,copy.getNextPageId());
+                    resetPageReference(replacementIndex, copy.getNextPageId());
                     copy.setNextPageId(TreeEntry.NOT_SET);
-                }else{
+                }
+                else {
                     page.save();
                 }
                 save();
-                result=true;
+                result = true;
             }
         }
         // ensure we don't loose previous bit of the tree
-        if(entry.getPrevPageId()!=TreeEntry.NOT_SET){
-            TreeEntry prevEntry=(index>0)?getTreeEntry(index-1):null;
-            if(prevEntry==null||prevEntry.getNextPageId()!=entry.getPrevPageId()){
-                TreePage page=tree.lookupPage(entry.getPrevPageId());
-                if(page!=null&&!page.isEmpty()){
-                    TreeEntry replacement=page.removeTreeEntry(page.getEntries().size()-1);
-                    TreeEntry copy=replacement.copy();
+        if (entry.getPrevPageId() != TreeEntry.NOT_SET) {
+            TreeEntry prevEntry = (index > 0) ? getTreeEntry(index - 1) : null;
+            if (prevEntry == null || prevEntry.getNextPageId() != entry.getPrevPageId()) {
+                TreePage page = tree.lookupPage(entry.getPrevPageId());
+                if (page != null && !page.isEmpty()) {
+                    TreeEntry replacement = page.removeTreeEntry(page.getEntries().size() - 1);
+                    TreeEntry copy = replacement.copy();
                     // check children pages of the replacement point to the correct place
-                    checkParentIdForRemovedPageEntry(copy,page.getId(),getId());
-                    if(!page.isEmpty()){
+                    checkParentIdForRemovedPageEntry(copy, page.getId(), getId());
+                    if (!page.isEmpty()) {
                         copy.setPrevPageId(page.getId());
-                    }else{
+                    }
+                    else {
                         page.setLeaf(true);
                     }
-                    insertTreeEntry(index,copy);
-                    TreePage landed=null;// if we overflow - the page the replacement ends up on
-                    TreeEntry removed=null;
-                    if(isOverflowed()){
-                        TreePage parent=getParent();
-                        if(parent!=null){
-                            removed=getTreeEntry(0);
-                            Flavour flavour=getFlavour(parent,removed);
-                            if(flavour==Flavour.LESS){
-                                removed=removeTreeEntry(0);
-                                landed=parent.doOverflow(flavour,removed);
-                            }else{
-                                removed=removeTreeEntry(size()-1);
-                                landed=parent.doOverflow(Flavour.MORE,removed);
+                    insertTreeEntry(index, copy);
+                    TreePage landed = null;// if we overflow - the page the replacement ends up on
+                    TreeEntry removed = null;
+                    if (isOverflowed()) {
+                        TreePage parent = getParent();
+                        if (parent != null) {
+                            removed = getTreeEntry(0);
+                            Flavour flavour = getFlavour(parent, removed);
+                            if (flavour == Flavour.LESS) {
+                                removed = removeTreeEntry(0);
+                                landed = parent.doOverflow(flavour, removed);
+                            }
+                            else {
+                                removed = removeTreeEntry(size() - 1);
+                                landed = parent.doOverflow(Flavour.MORE, removed);
                             }
                         }
                     }
-                    if(page.doUnderflow()){
-                        if(landed==null||landed.equals(this)){
-                           landed=this;
+                    if (page.doUnderflow()) {
+                        if (landed == null || landed.equals(this)) {
+                            landed = this;
                         }
-                        
+
                         resetPageReference(copy.getNextPageId());
                         landed.resetPageReference(copy.getNextPageId());
                         copy.setPrevPageId(TreeEntry.NOT_SET);
                         landed.save();
-                    }else{
+                    }
+                    else {
                         page.save();
                     }
                     save();
-                    result=true;
+                    result = true;
                 }
                 // now we need to check we haven't overflowed this page
             }
         }
-        if(!result){
+        if (!result) {
             save();
         }
         // now see if we need to save this page
-        result|=doUnderflowLeaf();
+        result |= doUnderflowLeaf();
         save();
         return result;
     }
 
-    private boolean doUnderflowLeaf() throws IOException{
-        boolean result=false;
+    private boolean doUnderflowLeaf() throws IOException {
+        boolean result = false;
         // if we have unerflowed - and we are a leaf - push entries further up the tree
         // and delete ourselves
-        if(isUnderflowed()&&isLeaf()){
-            List<TreeEntry> list=new ArrayList<TreeEntry>(treeEntries);
+        if (isUnderflowed() && isLeaf()) {
+            List<TreeEntry> list = new ArrayList<TreeEntry>(treeEntries);
             treeEntries.clear();
-            for(TreeEntry entry:list){
+            for (TreeEntry entry : list) {
                 // need to check for each iteration - we might get promoted to root
-                TreePage parent=getParent();
-                if(parent!=null){
-                    Flavour flavour=getFlavour(parent,entry);
-                    TreePage landedOn=parent.doOverflow(flavour,entry);
-                    checkParentIdForRemovedPageEntry(entry,getId(),landedOn.getId());
+                TreePage parent = getParent();
+                if (parent != null) {
+                    Flavour flavour = getFlavour(parent, entry);
+                    TreePage landedOn = parent.doOverflow(flavour, entry);
+                    checkParentIdForRemovedPageEntry(entry, getId(), landedOn.getId());
                 }
             }
-            TreePage parent=getParent();
-            if(parent!=null){
+            TreePage parent = getParent();
+            if (parent != null) {
                 parent.checkLeaf();
                 parent.removePageId(getId());
                 parent.doUnderflow();
                 parent.save();
                 tree.releasePage(this);
-                result=true;
+                result = true;
             }
         }
         return result;
     }
 
-    private Flavour getFlavour(TreePage page,TreeEntry entry){
-        Flavour result=null;
-        if(page!=null&&!page.getEntries().isEmpty()){
-            TreeEntry last=page.getEntries().get(page.getEntries().size()-1);
-            if(last.compareTo(entry)>0){
-                result=Flavour.MORE;
-            }else{
-                result=Flavour.LESS;
+    private Flavour getFlavour(TreePage page, TreeEntry entry) {
+        Flavour result = null;
+        if (page != null && !page.getEntries().isEmpty()) {
+            TreeEntry last = page.getEntries().get(page.getEntries().size() - 1);
+            if (last.compareTo(entry) > 0) {
+                result = Flavour.MORE;
+            }
+            else {
+                result = Flavour.LESS;
             }
         }
         return result;
     }
 
-    private void checkLeaf(){
-        boolean result=false;
-        for(TreeEntry entry:treeEntries){
-            if(entry.hasChildPagesReferences()){
-                result=true;
+    private void checkLeaf() {
+        boolean result = false;
+        for (TreeEntry entry : treeEntries) {
+            if (entry.hasChildPagesReferences()) {
+                result = true;
                 break;
             }
         }
         setLeaf(!result);
     }
 
-    private void checkParentIdForRemovedPageEntry(TreeEntry entry,long oldPageId,long newPageId) throws IOException{
-        TreePage page=tree.lookupPage(entry.getPrevPageId());
-        if(page!=null&&page.getParentId()==oldPageId){
+    private void checkParentIdForRemovedPageEntry(TreeEntry entry, long oldPageId, long newPageId) throws IOException {
+        TreePage page = tree.lookupPage(entry.getPrevPageId());
+        if (page != null && page.getParentId() == oldPageId) {
             page.setParentId(newPageId);
             page.save();
         }
-        page=tree.lookupPage(entry.getNextPageId());
-        if(page!=null&&page.getParentId()==oldPageId){
+        page = tree.lookupPage(entry.getNextPageId());
+        if (page != null && page.getParentId() == oldPageId) {
             page.setParentId(newPageId);
             page.save();
         }
     }
 
-    private void removePageId(long pageId){
-        for(TreeEntry entry:treeEntries){
-            if(entry.getNextPageId()==pageId){
+    private void removePageId(long pageId) {
+        for (TreeEntry entry : treeEntries) {
+            if (entry.getNextPageId() == pageId) {
                 entry.setNextPageId(TreeEntry.NOT_SET);
             }
-            if(entry.getPrevPageId()==pageId){
+            if (entry.getPrevPageId() == pageId) {
                 entry.setPrevPageId(TreeEntry.NOT_SET);
             }
         }
     }
 
-    private TreePageEntry findClosestEntry(TreeEntry key) throws IOException{
-        TreePageEntry result=null;
-        TreeEntry treeEntry=null;
-        Flavour flavour=null;
-        long pageId=-1;
-        int low=0;
-        int high=size()-1;
-        int mid=low;
-        while(low<=high){
-            mid=(low+high)>>1;
-            treeEntry=getTreeEntry(mid);
-            int cmp=treeEntry.compareTo(key);
-            if(cmp<0){
-                low=mid+1;
-                pageId=treeEntry.getNextPageId();
-                flavour=Flavour.LESS;
-            }else if(cmp>0){
-                high=mid-1;
-                pageId=treeEntry.getPrevPageId();
-                flavour=Flavour.MORE;
-            }else{
+    private TreePageEntry findClosestEntry(TreeEntry key) throws IOException {
+        TreePageEntry result = null;
+        TreeEntry treeEntry = null;
+        Flavour flavour = null;
+        long pageId = -1;
+        int low = 0;
+        int high = size() - 1;
+        int mid = low;
+        while (low <= high) {
+            mid = (low + high) >> 1;
+            treeEntry = getTreeEntry(mid);
+            int cmp = treeEntry.compareTo(key);
+            if (cmp < 0) {
+                low = mid + 1;
+                pageId = treeEntry.getNextPageId();
+                flavour = Flavour.LESS;
+            }
+            else if (cmp > 0) {
+                high = mid - 1;
+                pageId = treeEntry.getPrevPageId();
+                flavour = Flavour.MORE;
+            }
+            else {
                 // got exact match
-                low=mid;
+                low = mid;
                 break;
             }
         }
-        if(treeEntry!=null){
-            TreePage treePage=tree.lookupPage(pageId);
-            result=new TreePageEntry(treeEntry,treePage,flavour,low);
+        if (treeEntry != null) {
+            TreePage treePage = tree.lookupPage(pageId);
+            result = new TreePageEntry(treeEntry, treePage, flavour, low);
         }
         return result;
     }
 
-    private int doInsertEntry(TreeEntry newEntry) throws IOException{
-        int low=0;
-        int high=size()-1;
-        while(low<=high){
-            int mid=(low+high)>>1;
-            TreeEntry midVal=getTreeEntry(mid);
-            int cmp=midVal.compareTo(newEntry);
-            if(cmp<0)
-                low=mid+1;
-            else if(cmp>0)
-                high=mid-1;
+    private int doInsertEntry(TreeEntry newEntry) throws IOException {
+        int low = 0;
+        int high = size() - 1;
+        while (low <= high) {
+            int mid = (low + high) >> 1;
+            TreeEntry midVal = getTreeEntry(mid);
+            int cmp = midVal.compareTo(newEntry);
+            if (cmp < 0) {
+                low = mid + 1;
+            }
+            else if (cmp > 0) {
+                high = mid - 1;
+            }
         }
-        insertTreeEntry(low,newEntry);
+        insertTreeEntry(low, newEntry);
         return low;
     }
 
-    private void insertTreeEntry(int index,TreeEntry entry) throws IOException{
-        int p=index-1;
-        int n=index;
-        TreeEntry prevEntry=(p>=0&&p<treeEntries.size())?treeEntries.get(p):null;
-        TreeEntry nextEntry=(n>=0&&n<treeEntries.size())?treeEntries.get(n):null;
-        if(prevEntry!=null){
-            if(prevEntry.getNextPageId()==entry.getNextPageId()){
+    private void insertTreeEntry(int index, TreeEntry entry) throws IOException {
+        int p = index - 1;
+        int n = index;
+        TreeEntry prevEntry = (p >= 0 && p < treeEntries.size()) ? treeEntries.get(p) : null;
+        TreeEntry nextEntry = (n >= 0 && n < treeEntries.size()) ? treeEntries.get(n) : null;
+        if (prevEntry != null) {
+            if (prevEntry.getNextPageId() == entry.getNextPageId()) {
                 prevEntry.setNextPageId(TreeEntry.NOT_SET);
             }
-            if(entry.getPrevPageId()==TreeEntry.NOT_SET){
+            if (entry.getPrevPageId() == TreeEntry.NOT_SET) {
                 entry.setPrevPageId(prevEntry.getNextPageId());
             }
         }
-        if(nextEntry!=null){
-            if(nextEntry.getPrevPageId()==entry.getPrevPageId()){
+        if (nextEntry != null) {
+            if (nextEntry.getPrevPageId() == entry.getPrevPageId()) {
                 nextEntry.setPrevPageId(TreeEntry.NOT_SET);
             }
-            if(entry.getNextPageId()==TreeEntry.NOT_SET){
+            if (entry.getNextPageId() == TreeEntry.NOT_SET) {
                 entry.setNextPageId(nextEntry.getPrevPageId());
             }
         }
-        addTreeEntry(index,entry);
+        addTreeEntry(index, entry);
     }
 
-    private void resetPageReference(int index,long pageId){
-        int p=index-1;
-        int n=index;
-        TreeEntry prevEntry=(p>=0&&p<treeEntries.size())?treeEntries.get(p):null;
-        TreeEntry nextEntry=(n>=0&&n<treeEntries.size())?treeEntries.get(n):null;
-        if(prevEntry!=null){
-            if(prevEntry.getNextPageId()==pageId){
+    private void resetPageReference(int index, long pageId) {
+        int p = index - 1;
+        int n = index;
+        TreeEntry prevEntry = (p >= 0 && p < treeEntries.size()) ? treeEntries.get(p) : null;
+        TreeEntry nextEntry = (n >= 0 && n < treeEntries.size()) ? treeEntries.get(n) : null;
+        if (prevEntry != null) {
+            if (prevEntry.getNextPageId() == pageId) {
                 prevEntry.setNextPageId(TreeEntry.NOT_SET);
             }
         }
-        if(nextEntry!=null){
-            if(nextEntry.getPrevPageId()==pageId){
+        if (nextEntry != null) {
+            if (nextEntry.getPrevPageId() == pageId) {
                 nextEntry.setPrevPageId(TreeEntry.NOT_SET);
             }
         }
     }
 
-    private boolean resetPageReference(long pageId){
-        boolean updated=false;
-        for(TreeEntry entry:treeEntries){
-            if(entry.getPrevPageId()==pageId){
+    private boolean resetPageReference(long pageId) {
+        boolean updated = false;
+        for (TreeEntry entry : treeEntries) {
+            if (entry.getPrevPageId() == pageId) {
                 entry.setPrevPageId(TreeEntry.NOT_SET);
-                updated=true;
+                updated = true;
             }
-            if(entry.getNextPageId()==pageId){
+            if (entry.getNextPageId() == pageId) {
                 entry.setNextPageId(TreeEntry.NOT_SET);
-                updated=true;
+                updated = true;
             }
         }
         return updated;
     }
 
-    private void resetParentId(long newParentId,List<TreeEntry> entries) throws IOException{
-        Set<Long> set=new HashSet<Long>();
-        for(TreeEntry entry:entries){
-            if(entry!=null){
+    private void resetParentId(long newParentId, List<TreeEntry> entries) throws IOException {
+        Set<Long> set = new HashSet<Long>();
+        for (TreeEntry entry : entries) {
+            if (entry != null) {
                 set.add(entry.getPrevPageId());
                 set.add(entry.getNextPageId());
             }
         }
-        for(Long pageId:set){
-            TreePage page=tree.lookupPage(pageId);
-            if(page!=null){
+        for (Long pageId : set) {
+            TreePage page = tree.lookupPage(pageId);
+            if (page != null) {
                 page.setParentId(newParentId);
             }
         }
     }
 
-    private void addTreeEntry(int index,TreeEntry entry) throws IOException{
-        treeEntries.add(index,entry);
+    private void addTreeEntry(int index, TreeEntry entry) throws IOException {
+        treeEntries.add(index, entry);
     }
 
-    private TreeEntry removeTreeEntry(int index) throws IOException{
-        TreeEntry result=treeEntries.remove(index);
+    private TreeEntry removeTreeEntry(int index) throws IOException {
+        TreeEntry result = treeEntries.remove(index);
         return result;
     }
 
-    private void removeAllTreeEntries(List<TreeEntry> c){
+    private void removeAllTreeEntries(List<TreeEntry> c) {
         treeEntries.removeAll(c);
     }
 
-    private List<TreeEntry> getSubList(int from,int to){
-        return new ArrayList<TreeEntry>(treeEntries.subList(from,to));
+    private List<TreeEntry> getSubList(int from, int to) {
+        return new ArrayList<TreeEntry>(treeEntries.subList(from, to));
     }
 
-    private TreeEntry getTreeEntry(int index){
-        TreeEntry result=treeEntries.get(index);
+    private TreeEntry getTreeEntry(int index) {
+        TreeEntry result = treeEntries.get(index);
         return result;
     }
 
-    void saveHeader() throws IOException{
+    void saveHeader() throws IOException {
         tree.writePage(this);
     }
 
-    void save() throws IOException{
+    void save() throws IOException {
         tree.writeFullPage(this);
     }
 
-    protected void dump() throws IOException{
-        System.out.println(this);
-        Set<Long> set=new HashSet<Long>();
-        for(TreeEntry entry:treeEntries){
-            if(entry!=null){
-                System.out.println(entry);
+    protected void dump() throws IOException {
+        log.info(this);
+        Set<Long> set = new HashSet<Long>();
+        for (TreeEntry entry : treeEntries) {
+            if (entry != null) {
+                log.info(entry);
                 set.add(entry.getPrevPageId());
                 set.add(entry.getNextPageId());
             }
         }
-        for(Long pageId:set){
-            TreePage page=tree.lookupPage(pageId);
-            if(page!=null){
+        for (Long pageId : set) {
+            TreePage page = tree.lookupPage(pageId);
+            if (page != null) {
                 page.dump();
             }
         }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/proxy/ProxyConnector.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/proxy/ProxyConnector.java?view=diff&rev=546559&r1=546558&r2=546559
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/proxy/ProxyConnector.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/proxy/ProxyConnector.java Tue Jun 12 09:23:02 2007
@@ -143,7 +143,7 @@
         // Add a transport filter so that can track the transport life cycle
         transport = new TransportFilter(transport) {
         	public void stop() throws Exception {
-        		System.out.println("Stopping proxy.");
+        		log.info("Stopping proxy.");
         		super.stop();
         		connections.remove(this);
         	}



Mime
View raw message