git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@440342 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hiram R. Chirino 2006-09-05 13:51:13 +00:00
parent 3fe77a2cf8
commit 86d006ab28
36 changed files with 168 additions and 98 deletions

View File

@ -21,11 +21,17 @@ import java.io.IOException;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.activemq.kaha.Marshaller; import org.apache.activemq.kaha.Marshaller;
import org.apache.activemq.kaha.ObjectMarshaller;
import org.apache.activemq.kaha.Store; import org.apache.activemq.kaha.Store;
import org.apache.activemq.kaha.impl.data.DataItem;
import org.apache.activemq.kaha.impl.data.DataManager;
import org.apache.activemq.kaha.impl.data.Item;
import org.apache.activemq.kaha.impl.index.IndexItem;
import org.apache.activemq.kaha.impl.index.IndexManager;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap; import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
/** /**

View File

@ -26,6 +26,16 @@ import org.apache.activemq.kaha.ListContainer;
import org.apache.activemq.kaha.MapContainer; import org.apache.activemq.kaha.MapContainer;
import org.apache.activemq.kaha.RuntimeStoreException; import org.apache.activemq.kaha.RuntimeStoreException;
import org.apache.activemq.kaha.Store; import org.apache.activemq.kaha.Store;
import org.apache.activemq.kaha.impl.container.BaseContainerImpl;
import org.apache.activemq.kaha.impl.container.ContainerId;
import org.apache.activemq.kaha.impl.container.ListContainerImpl;
import org.apache.activemq.kaha.impl.container.MapContainerImpl;
import org.apache.activemq.kaha.impl.data.DataItem;
import org.apache.activemq.kaha.impl.data.DataManager;
import org.apache.activemq.kaha.impl.data.RedoListener;
import org.apache.activemq.kaha.impl.index.IndexItem;
import org.apache.activemq.kaha.impl.index.IndexManager;
import org.apache.activemq.kaha.impl.index.RedoStoreIndexItem;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap; import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
@ -41,7 +51,7 @@ public class KahaStore implements Store{
private File directory; private File directory;
protected IndexRootContainer mapsContainer; protected IndexRootContainer mapsContainer;
protected IndexRootContainer listsContainer; public IndexRootContainer listsContainer;
private Map lists=new ConcurrentHashMap(); private Map lists=new ConcurrentHashMap();
private Map maps=new ConcurrentHashMap(); private Map maps=new ConcurrentHashMap();
@ -244,7 +254,7 @@ public class KahaStore implements Store{
} }
} }
protected synchronized void initialize() throws IOException{ public synchronized void initialize() throws IOException{
if( closed ) if( closed )
throw new IOException("Store has been closed."); throw new IOException("Store has been closed.");
if(!initialized){ if(!initialized){
@ -276,7 +286,7 @@ public class KahaStore implements Store{
} }
} }
protected DataManager getDataManager(String name) throws IOException { public DataManager getDataManager(String name) throws IOException {
DataManager dm = (DataManager) dataManagers.get(name); DataManager dm = (DataManager) dataManagers.get(name);
if (dm == null){ if (dm == null){
dm = new DataManager(directory,name); dm = new DataManager(directory,name);
@ -287,7 +297,7 @@ public class KahaStore implements Store{
return dm; return dm;
} }
protected IndexManager getIndexManager(DataManager dm, String name) throws IOException { public IndexManager getIndexManager(DataManager dm, String name) throws IOException {
IndexManager im = (IndexManager) indexManagers.get(name); IndexManager im = (IndexManager) indexManagers.get(name);
if( im == null ) { if( im == null ) {
im = new IndexManager(directory,name,mode, logIndexChanges?dm:null); im = new IndexManager(directory,name,mode, logIndexChanges?dm:null);

View File

@ -15,12 +15,19 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.container;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.activemq.kaha.RuntimeStoreException; import org.apache.activemq.kaha.RuntimeStoreException;
import org.apache.activemq.kaha.impl.data.DataManager;
import org.apache.activemq.kaha.impl.data.Item;
import org.apache.activemq.kaha.impl.index.DiskIndexLinkedList;
import org.apache.activemq.kaha.impl.index.IndexItem;
import org.apache.activemq.kaha.impl.index.IndexLinkedList;
import org.apache.activemq.kaha.impl.index.IndexManager;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
/** /**
@ -50,7 +57,7 @@ public abstract class BaseContainerImpl{
} }
ContainerId getContainerId(){ public ContainerId getContainerId(){
return containerId; return containerId;
} }
@ -67,7 +74,7 @@ public abstract class BaseContainerImpl{
} }
} }
protected void clear(){ public void clear(){
if (indexList != null){ if (indexList != null){
indexList.clear(); indexList.clear();
} }
@ -127,7 +134,7 @@ public abstract class BaseContainerImpl{
return containerId.getKey(); return containerId.getKey();
} }
protected final void expressDataInterest() throws IOException{ public final void expressDataInterest() throws IOException{
long nextItem=root.getNextItem(); long nextItem=root.getNextItem();
while(nextItem!=Item.POSITION_NOT_SET){ while(nextItem!=Item.POSITION_NOT_SET){
IndexItem item=indexManager.getIndex(nextItem); IndexItem item=indexManager.getIndex(nextItem);

View File

@ -15,10 +15,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.container;
import java.util.ListIterator; import java.util.ListIterator;
import org.apache.activemq.kaha.impl.index.IndexItem;
import org.apache.activemq.kaha.impl.index.IndexLinkedList;
/** /**
* @version $Revision$ * @version $Revision$
*/ */

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.container;
/** /**

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.container;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.container;
import java.util.Iterator; import java.util.Iterator;

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.container;
import java.io.Externalizable; import java.io.Externalizable;
import java.io.IOException; import java.io.IOException;

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.container;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.container;
import java.util.Iterator; import java.util.Iterator;

View File

@ -15,10 +15,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.container;
import java.util.ListIterator; import java.util.ListIterator;
import org.apache.activemq.kaha.impl.index.IndexItem;
import org.apache.activemq.kaha.impl.index.IndexLinkedList;
/** /**
* @version $Revision: 1.2 $ * @version $Revision: 1.2 $
*/ */

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.container;
import java.util.Map; import java.util.Map;
import org.apache.activemq.kaha.MapContainer; import org.apache.activemq.kaha.MapContainer;

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.container;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -23,6 +23,9 @@ import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.apache.activemq.kaha.impl.index.IndexItem;
import org.apache.activemq.kaha.impl.index.IndexLinkedList;
/** /**
* Values collection for the MapContainer * Values collection for the MapContainer
* *

View File

@ -15,9 +15,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.container;
import java.util.Iterator; import java.util.Iterator;
import org.apache.activemq.kaha.impl.index.IndexItem;
import org.apache.activemq.kaha.impl.index.IndexLinkedList;
/** /**
* Values collection iterator for the MapContainer * Values collection iterator for the MapContainer
* *

View File

@ -11,7 +11,7 @@
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 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. * specific language governing permissions and limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.container;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -20,10 +20,16 @@ import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import org.apache.activemq.kaha.ListContainer; import org.apache.activemq.kaha.ListContainer;
import org.apache.activemq.kaha.Marshaller; import org.apache.activemq.kaha.Marshaller;
import org.apache.activemq.kaha.RuntimeStoreException; import org.apache.activemq.kaha.RuntimeStoreException;
import org.apache.activemq.kaha.Store; import org.apache.activemq.kaha.Store;
import org.apache.activemq.kaha.impl.data.DataItem;
import org.apache.activemq.kaha.impl.data.DataManager;
import org.apache.activemq.kaha.impl.data.Item;
import org.apache.activemq.kaha.impl.index.IndexItem;
import org.apache.activemq.kaha.impl.index.IndexManager;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
/** /**
@ -39,7 +45,7 @@ public class ListContainerImpl extends BaseContainerImpl implements ListContaine
protected int maximumCacheSize=100; protected int maximumCacheSize=100;
protected IndexItem lastCached; protected IndexItem lastCached;
protected ListContainerImpl(ContainerId id,IndexItem root,IndexManager rootIndexManager,IndexManager indexManager, public ListContainerImpl(ContainerId id,IndexItem root,IndexManager rootIndexManager,IndexManager indexManager,
DataManager dataManager) throws IOException{ DataManager dataManager) throws IOException{
super(id,root,rootIndexManager,indexManager,dataManager); super(id,root,rootIndexManager,indexManager,dataManager);
} }

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.container;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
@ -29,6 +29,12 @@ import org.apache.activemq.kaha.Marshaller;
import org.apache.activemq.kaha.ObjectMarshaller; import org.apache.activemq.kaha.ObjectMarshaller;
import org.apache.activemq.kaha.RuntimeStoreException; import org.apache.activemq.kaha.RuntimeStoreException;
import org.apache.activemq.kaha.Store; import org.apache.activemq.kaha.Store;
import org.apache.activemq.kaha.impl.data.DataItem;
import org.apache.activemq.kaha.impl.data.DataManager;
import org.apache.activemq.kaha.impl.data.Item;
import org.apache.activemq.kaha.impl.index.IndexItem;
import org.apache.activemq.kaha.impl.index.IndexLinkedList;
import org.apache.activemq.kaha.impl.index.IndexManager;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
/** /**
@ -36,14 +42,14 @@ import org.apache.commons.logging.LogFactory;
* *
* @version $Revision: 1.2 $ * @version $Revision: 1.2 $
*/ */
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 Map map=new HashMap(); protected Map map=new HashMap();
protected Map valueToKeyMap=new HashMap(); protected Map valueToKeyMap=new HashMap();
protected Marshaller keyMarshaller= Store.ObjectMarshaller; protected Marshaller keyMarshaller= Store.ObjectMarshaller;
protected Marshaller valueMarshaller=Store.ObjectMarshaller; protected Marshaller valueMarshaller=Store.ObjectMarshaller;
protected MapContainerImpl(ContainerId id,IndexItem root,IndexManager rootIndexManager,IndexManager indexManager,DataManager dataManager){ public MapContainerImpl(ContainerId id,IndexItem root,IndexManager rootIndexManager,IndexManager indexManager,DataManager dataManager){
super(id,root,rootIndexManager,indexManager,dataManager); super(id,root,rootIndexManager,indexManager,dataManager);
} }

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.data;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;

View File

@ -15,20 +15,21 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.data;
/** /**
* A a wrapper for a data in the store * A a wrapper for a data in the store
* *
* @version $Revision: 1.2 $ * @version $Revision: 1.2 $
*/ */
final class DataItem implements Item{ public final class DataItem implements Item{
private int file=(int) POSITION_NOT_SET; private int file=(int) POSITION_NOT_SET;
private long offset=POSITION_NOT_SET; private long offset=POSITION_NOT_SET;
private int size; private int size;
DataItem(){} public DataItem(){}
DataItem(DataItem item) { DataItem(DataItem item) {
this.file = item.file; this.file = item.file;
@ -43,42 +44,42 @@ final class DataItem implements Item{
/** /**
* @return Returns the size. * @return Returns the size.
*/ */
int getSize(){ public int getSize(){
return size; return size;
} }
/** /**
* @param size The size to set. * @param size The size to set.
*/ */
void setSize(int size){ public void setSize(int size){
this.size=size; this.size=size;
} }
/** /**
* @return Returns the offset. * @return Returns the offset.
*/ */
long getOffset(){ public long getOffset(){
return offset; return offset;
} }
/** /**
* @param offset The offset to set. * @param offset The offset to set.
*/ */
void setOffset(long offset){ public void setOffset(long offset){
this.offset=offset; this.offset=offset;
} }
/** /**
* @return Returns the file. * @return Returns the file.
*/ */
int getFile(){ public int getFile(){
return file; return file;
} }
/** /**
* @param file The file to set. * @param file The file to set.
*/ */
void setFile(int file){ public void setFile(int file){
this.file=file; this.file=file;
} }

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.data;
import java.io.File; import java.io.File;
import java.io.FilenameFilter; import java.io.FilenameFilter;
@ -28,6 +28,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.activemq.kaha.Marshaller; import org.apache.activemq.kaha.Marshaller;
import org.apache.activemq.kaha.impl.index.RedoStoreIndexItem;
import org.apache.activemq.util.IOExceptionSupport; import org.apache.activemq.util.IOExceptionSupport;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -36,10 +37,10 @@ import org.apache.commons.logging.LogFactory;
* *
* @version $Revision: 1.1.1.1 $ * @version $Revision: 1.1.1.1 $
*/ */
final class DataManager{ public final class DataManager{
private static final Log log=LogFactory.getLog(DataManager.class); private static final Log log=LogFactory.getLog(DataManager.class);
protected static long MAX_FILE_LENGTH=1024*1024*32; public static long MAX_FILE_LENGTH=1024*1024*32;
private final File dir; private final File dir;
private final String name; private final String name;
private StoreDataReader reader; private StoreDataReader reader;
@ -55,7 +56,7 @@ final class DataManager{
Marshaller redoMarshaller = RedoStoreIndexItem.MARSHALLER; Marshaller redoMarshaller = RedoStoreIndexItem.MARSHALLER;
private String dataFilePrefix; private String dataFilePrefix;
DataManager(File dir, final String name){ public DataManager(File dir, final String name){
this.dir=dir; this.dir=dir;
this.name=name; this.name=name;
this.reader=new StoreDataReader(this); this.reader=new StoreDataReader(this);
@ -117,19 +118,19 @@ final class DataManager{
throw new IOException("Could not locate data file "+name+item.getFile()); throw new IOException("Could not locate data file "+name+item.getFile());
} }
synchronized Object readItem(Marshaller marshaller, DataItem item) throws IOException{ public synchronized Object readItem(Marshaller marshaller, DataItem item) throws IOException{
return reader.readItem(marshaller,item); return reader.readItem(marshaller,item);
} }
synchronized DataItem storeDataItem(Marshaller marshaller, Object payload) throws IOException{ public synchronized DataItem storeDataItem(Marshaller marshaller, Object payload) throws IOException{
return writer.storeItem(marshaller,payload, DATA_ITEM_TYPE); return writer.storeItem(marshaller,payload, DATA_ITEM_TYPE);
} }
synchronized DataItem storeRedoItem(Object payload) throws IOException{ public synchronized DataItem storeRedoItem(Object payload) throws IOException{
return writer.storeItem(redoMarshaller, payload, REDO_ITEM_TYPE); return writer.storeItem(redoMarshaller, payload, REDO_ITEM_TYPE);
} }
synchronized void recoverRedoItems(RedoListener listener) throws IOException{ public synchronized void recoverRedoItems(RedoListener listener) throws IOException{
// Nothing to recover if there is no current file. // Nothing to recover if there is no current file.
if( currentWriteFile == null ) if( currentWriteFile == null )
@ -171,7 +172,7 @@ final class DataManager{
} }
} }
synchronized void close() throws IOException{ public synchronized void close() throws IOException{
for(Iterator i=fileMap.values().iterator();i.hasNext();){ for(Iterator i=fileMap.values().iterator();i.hasNext();){
DataFile dataFile=(DataFile) i.next(); DataFile dataFile=(DataFile) i.next();
dataFile.force(); dataFile.force();
@ -180,14 +181,14 @@ final class DataManager{
fileMap.clear(); fileMap.clear();
} }
synchronized void force() throws IOException{ public synchronized void force() throws IOException{
for(Iterator i=fileMap.values().iterator();i.hasNext();){ for(Iterator i=fileMap.values().iterator();i.hasNext();){
DataFile dataFile=(DataFile) i.next(); DataFile dataFile=(DataFile) i.next();
dataFile.force(); dataFile.force();
} }
} }
synchronized boolean delete() throws IOException{ public synchronized boolean delete() throws IOException{
boolean result=true; boolean result=true;
for(Iterator i=fileMap.values().iterator();i.hasNext();){ for(Iterator i=fileMap.values().iterator();i.hasNext();){
DataFile dataFile=(DataFile) i.next(); DataFile dataFile=(DataFile) i.next();
@ -197,7 +198,7 @@ final class DataManager{
return result; return result;
} }
synchronized void addInterestInFile(int file) throws IOException{ public synchronized void addInterestInFile(int file) throws IOException{
if(file>=0){ if(file>=0){
Integer key=new Integer(file); Integer key=new Integer(file);
DataFile dataFile=(DataFile) fileMap.get(key); DataFile dataFile=(DataFile) fileMap.get(key);
@ -214,7 +215,7 @@ final class DataManager{
} }
} }
synchronized void removeInterestInFile(int file) throws IOException{ public synchronized void removeInterestInFile(int file) throws IOException{
if(file>=0){ if(file>=0){
Integer key=new Integer(file); Integer key=new Integer(file);
DataFile dataFile=(DataFile) fileMap.get(key); DataFile dataFile=(DataFile) fileMap.get(key);
@ -232,7 +233,7 @@ final class DataManager{
} }
} }
synchronized void consolidateDataFiles() throws IOException{ public synchronized void consolidateDataFiles() throws IOException{
List purgeList=new ArrayList(); List purgeList=new ArrayList();
for(Iterator i=fileMap.values().iterator();i.hasNext();){ for(Iterator i=fileMap.values().iterator();i.hasNext();){
DataFile dataFile=(DataFile) i.next(); DataFile dataFile=(DataFile) i.next();

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.data;
/** /**
* A a wrapper for a data in the store * A a wrapper for a data in the store

View File

@ -15,7 +15,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.data;
public interface RedoListener { public interface RedoListener {

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.data;
import java.io.DataInput; import java.io.DataInput;
import java.io.IOException; import java.io.IOException;
@ -26,7 +26,7 @@ import java.io.UTFDataFormatException;
* *
* @version $Revision: 1.1.1.1 $ * @version $Revision: 1.1.1.1 $
*/ */
final class StoreByteArrayInputStream extends InputStream implements DataInput{ public final class StoreByteArrayInputStream extends InputStream implements DataInput{
private byte[] buf; private byte[] buf;
private int pos; private int pos;

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.data;
import java.io.DataOutput; import java.io.DataOutput;
import java.io.IOException; import java.io.IOException;
@ -26,7 +26,7 @@ import java.io.UTFDataFormatException;
* *
* @version $Revision: 1.1.1.1 $ * @version $Revision: 1.1.1.1 $
*/ */
final class StoreByteArrayOutputStream extends OutputStream implements DataOutput{ public final class StoreByteArrayOutputStream extends OutputStream implements DataOutput{
private byte buf[]; private byte buf[];
private int pos; private int pos;

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.data;
import java.io.IOException; import java.io.IOException;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.data;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.index;
import java.io.IOException; import java.io.IOException;

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.index;
import java.io.IOException; import java.io.IOException;
/** /**
@ -23,7 +23,7 @@ import java.io.IOException;
* *
* @version $Revision$ * @version $Revision$
*/ */
class DiskIndexLinkedList implements IndexLinkedList{ public class DiskIndexLinkedList implements IndexLinkedList{
protected IndexManager indexManager; protected IndexManager indexManager;
protected transient IndexItem root; protected transient IndexItem root;
protected transient IndexItem last; protected transient IndexItem last;
@ -32,7 +32,7 @@ class DiskIndexLinkedList implements IndexLinkedList{
/** /**
* Constructs an empty list. * Constructs an empty list.
*/ */
DiskIndexLinkedList(IndexManager im,IndexItem header){ public DiskIndexLinkedList(IndexManager im,IndexItem header){
this.indexManager=im; this.indexManager=im;
this.root=header; this.root=header;
} }

View File

@ -15,19 +15,22 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.index;
import java.io.DataInput; import java.io.DataInput;
import java.io.DataOutput; import java.io.DataOutput;
import java.io.IOException; import java.io.IOException;
import org.apache.activemq.kaha.impl.data.DataItem;
import org.apache.activemq.kaha.impl.data.Item;
/** /**
* A an Item with a relative position and location to other Items in the Store * A an Item with a relative position and location to other Items in the Store
* *
* @version $Revision: 1.2 $ * @version $Revision: 1.2 $
*/ */
class IndexItem implements Item{ public class IndexItem implements Item{
static final int INDEX_SIZE=51; public static final int INDEX_SIZE=51;
//used by linked list //used by linked list
IndexItem next; IndexItem next;
IndexItem prev; IndexItem prev;
@ -49,7 +52,7 @@ import java.io.IOException;
/** /**
* Default Constructor * Default Constructor
*/ */
IndexItem(){} public IndexItem(){}
void reset(){ void reset(){
previousItem=POSITION_NOT_SET; previousItem=POSITION_NOT_SET;
@ -63,7 +66,7 @@ import java.io.IOException;
active=true; active=true;
} }
DataItem getKeyDataItem(){ public DataItem getKeyDataItem(){
DataItem result=new DataItem(); DataItem result=new DataItem();
result.setOffset(keyOffset); result.setOffset(keyOffset);
result.setFile(keyFile); result.setFile(keyFile);
@ -71,7 +74,7 @@ import java.io.IOException;
return result; return result;
} }
DataItem getValueDataItem(){ public DataItem getValueDataItem(){
DataItem result=new DataItem(); DataItem result=new DataItem();
result.setOffset(valueOffset); result.setOffset(valueOffset);
result.setFile(valueFile); result.setFile(valueFile);
@ -79,13 +82,13 @@ import java.io.IOException;
return result; return result;
} }
void setValueData(DataItem item){ public void setValueData(DataItem item){
valueOffset=item.getOffset(); valueOffset=item.getOffset();
valueFile=item.getFile(); valueFile=item.getFile();
valueSize=item.getSize(); valueSize=item.getSize();
} }
void setKeyData(DataItem item){ public void setKeyData(DataItem item){
keyOffset=item.getOffset(); keyOffset=item.getOffset();
keyFile=item.getFile(); keyFile=item.getFile();
keySize=item.getSize(); keySize=item.getSize();
@ -130,7 +133,7 @@ import java.io.IOException;
/** /**
* @param newPrevEntry * @param newPrevEntry
*/ */
void setPreviousItem(long newPrevEntry){ public void setPreviousItem(long newPrevEntry){
previousItem=newPrevEntry; previousItem=newPrevEntry;
} }
@ -144,14 +147,14 @@ import java.io.IOException;
/** /**
* @param newNextEntry * @param newNextEntry
*/ */
void setNextItem(long newNextEntry){ public void setNextItem(long newNextEntry){
nextItem=newNextEntry; nextItem=newNextEntry;
} }
/** /**
* @return next item * @return next item
*/ */
long getNextItem(){ public long getNextItem(){
return nextItem; return nextItem;
} }
@ -172,7 +175,7 @@ import java.io.IOException;
/** /**
* @return Returns the keyFile. * @return Returns the keyFile.
*/ */
int getKeyFile(){ public int getKeyFile(){
return keyFile; return keyFile;
} }
@ -186,7 +189,7 @@ import java.io.IOException;
/** /**
* @return Returns the valueFile. * @return Returns the valueFile.
*/ */
int getValueFile(){ public int getValueFile(){
return valueFile; return valueFile;
} }
@ -200,14 +203,14 @@ import java.io.IOException;
/** /**
* @return Returns the valueOffset. * @return Returns the valueOffset.
*/ */
long getValueOffset(){ public long getValueOffset(){
return valueOffset; return valueOffset;
} }
/** /**
* @param valueOffset The valueOffset to set. * @param valueOffset The valueOffset to set.
*/ */
void setValueOffset(long valueOffset){ public void setValueOffset(long valueOffset){
this.valueOffset=valueOffset; this.valueOffset=valueOffset;
} }
@ -228,14 +231,14 @@ import java.io.IOException;
/** /**
* @return Returns the offset. * @return Returns the offset.
*/ */
long getOffset(){ public long getOffset(){
return offset; return offset;
} }
/** /**
* @param offset The offset to set. * @param offset The offset to set.
*/ */
void setOffset(long offset){ public void setOffset(long offset){
this.offset=offset; this.offset=offset;
} }

View File

@ -15,9 +15,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.index;
interface IndexLinkedList{ public interface IndexLinkedList{
/** /**
* @return the root used by the List * @return the root used by the List

View File

@ -15,12 +15,14 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.index;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.util.LinkedList; import java.util.LinkedList;
import org.apache.activemq.kaha.impl.data.DataManager;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
/** /**
@ -28,7 +30,7 @@ import org.apache.commons.logging.LogFactory;
* *
* @version $Revision: 1.1.1.1 $ * @version $Revision: 1.1.1.1 $
*/ */
final class IndexManager{ public final class IndexManager{
private static final Log log=LogFactory.getLog(IndexManager.class); private static final Log log=LogFactory.getLog(IndexManager.class);
private static final String NAME_PREFIX="index-"; private static final String NAME_PREFIX="index-";
private final String name; private final String name;
@ -39,7 +41,7 @@ final class IndexManager{
private LinkedList freeList=new LinkedList(); private LinkedList freeList=new LinkedList();
private long length=0; private long length=0;
IndexManager(File directory,String name,String mode,DataManager redoLog) throws IOException{ public IndexManager(File directory,String name,String mode,DataManager redoLog) throws IOException{
this.name=name; this.name=name;
file=new File(directory,NAME_PREFIX+name); file=new File(directory,NAME_PREFIX+name);
indexFile=new RandomAccessFile(file,mode); indexFile=new RandomAccessFile(file,mode);
@ -57,22 +59,22 @@ final class IndexManager{
length=offset; length=offset;
} }
synchronized boolean isEmpty(){ public synchronized boolean isEmpty(){
return freeList.isEmpty()&&length==0; return freeList.isEmpty()&&length==0;
} }
synchronized IndexItem getIndex(long offset) throws IOException{ public synchronized IndexItem getIndex(long offset) throws IOException{
return reader.readItem(offset); return reader.readItem(offset);
} }
synchronized void freeIndex(IndexItem item) throws IOException{ public synchronized void freeIndex(IndexItem item) throws IOException{
item.reset(); item.reset();
item.setActive(false); item.setActive(false);
writer.storeItem(item); writer.storeItem(item);
freeList.add(item); freeList.add(item);
} }
synchronized void updateIndex(IndexItem index) throws IOException{ public synchronized void updateIndex(IndexItem index) throws IOException{
writer.storeItem(index); writer.storeItem(index);
} }
@ -80,7 +82,7 @@ final class IndexManager{
writer.redoStoreItem(redo); writer.redoStoreItem(redo);
} }
synchronized IndexItem createNewIndex(){ public synchronized IndexItem createNewIndex(){
IndexItem result=getNextFreeIndex(); IndexItem result=getNextFreeIndex();
if(result==null){ if(result==null){
// allocate one // allocate one
@ -91,20 +93,20 @@ final class IndexManager{
return result; return result;
} }
synchronized void close() throws IOException{ public synchronized void close() throws IOException{
if(indexFile!=null){ if(indexFile!=null){
indexFile.close(); indexFile.close();
indexFile=null; indexFile=null;
} }
} }
synchronized void force() throws IOException{ public synchronized void force() throws IOException{
if(indexFile!=null){ if(indexFile!=null){
indexFile.getFD().sync(); indexFile.getFD().sync();
} }
} }
synchronized boolean delete() throws IOException{ public synchronized boolean delete() throws IOException{
freeList.clear(); freeList.clear();
if(indexFile!=null){ if(indexFile!=null){
indexFile.close(); indexFile.close();
@ -126,7 +128,7 @@ final class IndexManager{
return length; return length;
} }
void setLength(long value){ public void setLength(long value){
this.length=value; this.length=value;
} }

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.index;
import java.io.DataInput; import java.io.DataInput;
import java.io.DataOutput; import java.io.DataOutput;

View File

@ -15,10 +15,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.index;
import java.io.IOException; import java.io.IOException;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import org.apache.activemq.kaha.impl.data.StoreByteArrayInputStream;
/** /**
* Optimized Store reader * Optimized Store reader
* *

View File

@ -15,10 +15,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.index;
import java.io.IOException; import java.io.IOException;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import org.apache.activemq.kaha.impl.data.DataManager;
import org.apache.activemq.kaha.impl.data.StoreByteArrayOutputStream;
/** /**
* Optimized Store writer * Optimized Store writer
* *

View File

@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.index;
/** /**
* A linked list used by IndexItems * A linked list used by IndexItems

View File

@ -20,10 +20,16 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.activemq.kaha.StoreFactory; import org.apache.activemq.kaha.StoreFactory;
import org.apache.activemq.kaha.impl.KahaStore;
import org.apache.activemq.kaha.impl.container.ContainerId;
import org.apache.activemq.kaha.impl.container.ListContainerImpl;
import org.apache.activemq.kaha.impl.data.DataManager;
import org.apache.activemq.kaha.impl.index.IndexItem;
import org.apache.activemq.kaha.impl.index.IndexManager;
/** /**
* Junit tests for CachedListContainerImpl * Junit tests for CachedListContainerImpl
* *
* @version $Revision$ * @version $Revision: 439552 $
*/ */
public class CachedListContainerImplTest extends TestCase{ public class CachedListContainerImplTest extends TestCase{
protected String name; protected String name;

View File

@ -15,12 +15,16 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.activemq.kaha.impl; package org.apache.activemq.kaha.impl.index;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.activemq.kaha.impl.index.IndexItem;
import org.apache.activemq.kaha.impl.index.IndexLinkedList;
/** /**
* @version $Revision: 1.2 $ * @version $Revision: 1.2 $
*/ */