You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by cz...@apache.org on 2003/07/14 20:17:24 UTC
cvs commit: avalon-excalibur/store/src/java/org/apache/excalibur/store/impl JispFilesystemStore.java JispKey.java AbstractJispFilesystemStore.java
cziegeler 2003/07/14 11:17:23
Modified: store/src/java/org/apache/excalibur/store/impl JispKey.java
AbstractJispFilesystemStore.java
Added: store/src/java/org/apache/excalibur/store/impl
JispFilesystemStore.java
Log:
Switching from string based keys to object based
Adding default store implementation
Revision Changes Path
1.3 +13 -2 avalon-excalibur/store/src/java/org/apache/excalibur/store/impl/JispKey.java
Index: JispKey.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/store/src/java/org/apache/excalibur/store/impl/JispKey.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JispKey.java 14 Jul 2003 17:16:27 -0000 1.2
+++ JispKey.java 14 Jul 2003 18:17:23 -0000 1.3
@@ -67,12 +67,16 @@
*/
public final class JispKey extends KeyObject
{
- final static long serialVersionUID = 798806649359364728L;
+ final static long serialVersionUID = -1216913992804571313L;
protected Object m_Key;
static protected JispKey NULL_KEY = new JispKey("");
+ public JispKey() {
+ this("");
+ }
+
/**
* Constructor for the JispStringKey object
*
@@ -169,6 +173,13 @@
m_Key = in.readObject();
}
+ /**
+ * Return the real key
+ */
+ public Object getKey()
+ {
+ return m_Key;
+ }
}
1.9 +111 -57 avalon-excalibur/store/src/java/org/apache/excalibur/store/impl/AbstractJispFilesystemStore.java
Index: AbstractJispFilesystemStore.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/store/src/java/org/apache/excalibur/store/impl/AbstractJispFilesystemStore.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- AbstractJispFilesystemStore.java 14 Jul 2003 13:58:19 -0000 1.8
+++ AbstractJispFilesystemStore.java 14 Jul 2003 18:17:23 -0000 1.9
@@ -79,23 +79,22 @@
extends AbstractLogEnabled
implements Store, ThreadSafe, Initializable {
- /**
- * The directory repository
- */
+ /** The directory repository */
protected File m_directoryFile;
+ /** The path to the directory */
protected volatile String m_directoryPath;
- /**
- * The database
- */
+ /** The database */
protected IndexedObjectDatabase m_Database;
+ /** And the index */
protected BTreeIndex m_Index;
/**
* Sets the repository's location
*/
public void setDirectory(final String directory)
- throws IOException {
+ throws IOException
+ {
this.setDirectory(new File(directory));
}
@@ -115,7 +114,7 @@
if (!this.m_directoryFile.exists())
{
/* Create it anew */
- if (!this.m_directoryFile.mkdir())
+ if (!this.m_directoryFile.mkdirs())
{
throw new IOException(
"Error creating store directory '" + this.m_directoryPath + "': ");
@@ -123,12 +122,14 @@
}
/* Is given file actually a directory? */
- if (!this.m_directoryFile.isDirectory()) {
+ if (!this.m_directoryFile.isDirectory())
+ {
throw new IOException("'" + this.m_directoryPath + "' is not a directory");
}
/* Is directory readable and writable? */
- if (!(this.m_directoryFile.canRead() && this.m_directoryFile.canWrite())) {
+ if (!(this.m_directoryFile.canRead() && this.m_directoryFile.canWrite()))
+ {
throw new IOException(
"Directory '" + this.m_directoryPath + "' is not readable/writable"
);
@@ -140,7 +141,8 @@
*
* @return the directory as String
*/
- public String getDirectoryPath() {
+ public String getDirectoryPath()
+ {
return this.m_directoryPath;
}
@@ -150,18 +152,26 @@
* @param key the Key object
* @return the Object associated with Key Object
*/
- public synchronized Object get(Object key) {
+ public synchronized Object get(Object key)
+ {
Object value = null;
- try {
+ try
+ {
value = m_Database.read(this.wrapKeyObject(key), m_Index);
- if (getLogger().isDebugEnabled()) {
- if (value != null) {
+ if (getLogger().isDebugEnabled())
+ {
+ if (value != null)
+ {
getLogger().debug("Found key: " + key);
- } else {
+ }
+ else
+ {
getLogger().debug("NOT Found key: " + key);
}
}
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
getLogger().error("get(..): Exception", e);
}
return value;
@@ -175,24 +185,32 @@
* @exception IOException
*/
public synchronized void store(Object key, Object value)
- throws IOException {
+ throws IOException
+ {
- if (getLogger().isDebugEnabled()) {
+ if (getLogger().isDebugEnabled())
+ {
this.getLogger().debug("store(): Store file with key: "
+ key.toString());
this.getLogger().debug("store(): Store file with value: "
+ value.toString());
}
- if (value instanceof Serializable) {
- try {
+ if (value instanceof Serializable)
+ {
+ try
+ {
KeyObject[] keyArray = new KeyObject[1];
keyArray[0] = this.wrapKeyObject(key);
m_Database.write(keyArray, (Serializable) value);
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
this.getLogger().error("store(..): Exception", e);
}
- } else {
+ }
+ else
+ {
throw new IOException("Object not Serializable");
}
}
@@ -205,7 +223,8 @@
* @exception IOException
*/
public synchronized void hold(Object key, Object value)
- throws IOException {
+ throws IOException
+ {
this.store(key, value);
}
@@ -220,7 +239,8 @@
/**
* Clear the Store of all elements
*/
- public synchronized void clear() {
+ public synchronized void clear()
+ {
if (getLogger().isDebugEnabled())
{
@@ -257,17 +277,24 @@
*
* @param key the key object
*/
- public synchronized void remove(Object key) {
- if (getLogger().isDebugEnabled()) {
+ public synchronized void remove(Object key)
+ {
+ if (getLogger().isDebugEnabled())
+ {
this.getLogger().debug("remove(..) Remove item");
}
- try {
+ try
+ {
KeyObject[] keyArray = new KeyObject[1];
keyArray[0] = this.wrapKeyObject(key);
m_Database.remove(keyArray);
- } catch (KeyNotFound ignore) {
- } catch (Exception e) {
+ }
+ catch (KeyNotFound ignore)
+ {
+ }
+ catch (Exception e)
+ {
this.getLogger().error("remove(..): Exception", e);
}
}
@@ -278,22 +305,32 @@
* @param key the key object
* @return true if Key exists and false if not
*/
- public synchronized boolean containsKey(Object key) {
+ public synchronized boolean containsKey(Object key)
+ {
long res = -1;
- try {
+ try
+ {
res = m_Index.findKey(this.wrapKeyObject(key));
- if (getLogger().isDebugEnabled()) {
+ if (getLogger().isDebugEnabled())
+ {
this.getLogger().debug("containsKey(..): res=" + res);
}
- } catch (KeyNotFound ignore) {
- } catch (Exception e) {
+ }
+ catch (KeyNotFound ignore)
+ {
+ }
+ catch (Exception e)
+ {
this.getLogger().error("containsKey(..): Exception", e);
}
- if (res > 0) {
+ if (res > 0)
+ {
return true;
- } else {
+ }
+ else
+ {
return false;
}
}
@@ -303,16 +340,21 @@
*
* @return Enumeration Object with all existing keys
*/
- public Enumeration keys() {
- try {
+ public Enumeration keys()
+ {
+ try
+ {
BTreeObjectEnumeration enum = new BTreeObjectEnumeration(new BTreeIterator(m_Index), this);
return enum;
- } catch (Exception ignore) {
+ }
+ catch (Exception ignore)
+ {
return Collections.enumeration(Collections.EMPTY_LIST);
}
}
- public int size() {
+ public int size()
+ {
return m_Index.count();
}
@@ -324,9 +366,7 @@
*/
private KeyObject wrapKeyObject(Object key)
{
- // TODO: Implementation of Integer and Long keys
- String skey = String.valueOf(key);
- return new JispStringKey(key.toString());
+ return new JispKey( key );
}
/**
@@ -356,45 +396,59 @@
private BTreeIterator m_Iterator;
private AbstractJispFilesystemStore m_Store;
- public BTreeObjectEnumeration(BTreeIterator iterator, AbstractJispFilesystemStore store) {
+ public BTreeObjectEnumeration(BTreeIterator iterator, AbstractJispFilesystemStore store)
+ {
m_Iterator = iterator;
m_Store = store;
}
- public boolean hasMoreElements() {
+ public boolean hasMoreElements()
+ {
boolean hasMore = false;
Object tmp = null;
- try {
+ try
+ {
tmp = m_Iterator.getKey();
- if(m_Iterator.moveNext()) {
+ if(m_Iterator.moveNext())
+ {
hasMore = true;
}
/* resets iterator to the old state **/
m_Iterator.moveTo((KeyObject)tmp);
- } catch (IOException ioe) {
+ }
+ catch (IOException ioe)
+ {
m_Store.getLogger().error("store(..): Exception", ioe);
- } catch (ClassNotFoundException cnfe) {
+ }
+ catch (ClassNotFoundException cnfe)
+ {
m_Store.getLogger().error("store(..): Exception", cnfe);
}
return hasMore;
}
- public Object nextElement() {
+ public Object nextElement()
+ {
Object tmp = null;
- try {
+ try
+ {
tmp = m_Iterator.getKey();
m_Iterator.moveNext();
- } catch (IOException ioe) {
+ }
+ catch (IOException ioe)
+ {
m_Store.getLogger().error("store(..): Exception", ioe);
- } catch (ClassNotFoundException cnfe) {
+ }
+ catch (ClassNotFoundException cnfe)
+ {
m_Store.getLogger().error("store(..): Exception", cnfe);
}
- // make a string out of it (JispStringKey is not usefull here)
- return tmp.toString();
+ // return the real key
+ return ((JispKey) tmp).getKey();
}
}
}
1.1 avalon-excalibur/store/src/java/org/apache/excalibur/store/impl/JispFilesystemStore.java
Index: JispFilesystemStore.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
must not be used to endorse or promote products derived from this software
without prior written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.excalibur.store.impl;
import java.io.File;
import java.io.IOException;
import com.coyotegulch.jisp.BTreeIndex;
import com.coyotegulch.jisp.IndexedObjectDatabase;
import com.coyotegulch.jisp.KeyNotFound;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.parameters.ParameterException;
import org.apache.avalon.framework.parameters.Parameterizable;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.thread.ThreadSafe;
/**
* This store is based on the Jisp library
* (http://www.coyotegulch.com/jisp/index.html). This store uses B-Tree indexes
* to access variable-length serialized data stored in files.
*
* @author <a href="mailto:g-froehlich@gmx.de">Gerhard Froehlich</a>
* @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
* @version CVS $Id: JispFilesystemStore.java,v 1.1 2003/07/14 18:17:23 cziegeler Exp $
*/
public class JispFilesystemStore extends AbstractJispFilesystemStore
implements org.apache.excalibur.store.Store,
ThreadSafe,
Initializable,
Parameterizable {
/** The database file */
protected File m_databaseFile;
/** The index file */
protected File m_indexFile;
/** The page size of the B-Tree */
protected int m_Order;
/**
* Configure the Component.<br>
* A few options can be used
* <UL>
* <LI> The directory to store the two files belowe</LI>
* <LI> data-file = the name of the data file (Default: store.dat)
* </LI>
* <LI> index-file = the name of the index file (Default: store.idx)
* </LI>
* <LI> order = The page size of the B-Tree</LI>
* </UL>
*
* @param params the configuration paramters
* @exception ParameterException
*/
public void parameterize(Parameters params) throws ParameterException
{
try
{
final String dir = params.getParameter("directory");
this.setDirectory(new File(dir));
}
catch (IOException e)
{
throw new ParameterException("Unable to set directory", e);
}
final String databaseName = params.getParameter("data-file", "store.dat");
final String indexName = params.getParameter("index-file", "store.idx");
m_Order = params.getParameterAsInteger("order", 301);
if (getLogger().isDebugEnabled())
{
getLogger().debug("Database file name = " + databaseName);
getLogger().debug("Index file name = " + indexName);
getLogger().debug("Order=" + m_Order);
}
this.m_databaseFile = new File(m_directoryFile, databaseName);
m_indexFile = new File(m_directoryFile, indexName);
}
/**
* Initialize the Component
*/
public void initialize()
{
if (getLogger().isDebugEnabled())
{
getLogger().debug("initialize() JispFilesystemStore");
}
try {
JispKey nullKey = (JispKey)new JispKey("").makeNullKey();
m_Index = new BTreeIndex(m_indexFile.toString(),
m_Order, nullKey, false);
final boolean isOld = m_databaseFile.exists();
if (getLogger().isDebugEnabled())
{
getLogger().debug("initialize(): Datafile exists: " + isOld);
}
m_Database = new IndexedObjectDatabase(m_databaseFile.toString(), !isOld);
m_Database.attachIndex(m_Index);
}
catch (KeyNotFound ignore)
{
}
catch (Exception e)
{
getLogger().error("initialize(..) Exception", e);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org