Skip to Content.
Sympa Menu

notify-dpml - svn commit: r1872 - in development/laboratory/planet/components/space: . api/src/main/org/jpos/space/api interceptor jdbm/src/main/org/jpos/space persistent/src/main/org/jpos/space/persistent proxy tiny/src/main/org/jpos/space/tiny transient/src/main/org/jpos/space/transiient tspace util/src/main/org/jpos/space/util

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: niclas AT netcompartner.com
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r1872 - in development/laboratory/planet/components/space: . api/src/main/org/jpos/space/api interceptor jdbm/src/main/org/jpos/space persistent/src/main/org/jpos/space/persistent proxy tiny/src/main/org/jpos/space/tiny transient/src/main/org/jpos/space/transiient tspace util/src/main/org/jpos/space/util
  • Date: Tue, 22 Feb 2005 09:22:24 +0100

Author: niclas
Date: Tue Feb 22 09:22:23 2005
New Revision: 1872

Added:

development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/LeaseCallback.java
(contents, props changed)
Removed:
development/laboratory/planet/components/space/interceptor/
development/laboratory/planet/components/space/proxy/
development/laboratory/planet/components/space/tspace/

development/laboratory/planet/components/space/util/src/main/org/jpos/space/util/DefaultTimer.java
Modified:

development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/LeasedReference.java

development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/LocalSpace.java

development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/RemoteSpace.java

development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/Space.java

development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/SpaceException.java

development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/SpaceListener.java

development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/Template.java
development/laboratory/planet/components/space/index.xml

development/laboratory/planet/components/space/jdbm/src/main/org/jpos/space/Head.java

development/laboratory/planet/components/space/jdbm/src/main/org/jpos/space/JDBMSpace.java

development/laboratory/planet/components/space/jdbm/src/main/org/jpos/space/MD5Template.java

development/laboratory/planet/components/space/jdbm/src/main/org/jpos/space/Ref.java

development/laboratory/planet/components/space/jdbm/src/main/org/jpos/space/RefSerializer.java

development/laboratory/planet/components/space/persistent/src/main/org/jpos/space/persistent/Data.java

development/laboratory/planet/components/space/persistent/src/main/org/jpos/space/persistent/PersistentSpace.java

development/laboratory/planet/components/space/tiny/src/main/org/jpos/space/tiny/Data.java

development/laboratory/planet/components/space/tiny/src/main/org/jpos/space/tiny/TinySpace.java

development/laboratory/planet/components/space/transient/src/main/org/jpos/space/transiient/Data.java

development/laboratory/planet/components/space/transient/src/main/org/jpos/space/transiient/TransientSpace.java

development/laboratory/planet/components/space/util/src/main/org/jpos/space/util/Connector.java

development/laboratory/planet/components/space/util/src/main/org/jpos/space/util/ObjectTemplate.java

development/laboratory/planet/components/space/util/src/main/org/jpos/space/util/SpaceUtil.java
Log:
o Cleaning up the Space API and implementations. Need to focus on
implementations that makes sense.
o Introduced a proper callback for LeasedReferences that expires.

Added:
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/LeaseCallback.java
==============================================================================
--- (empty file)
+++
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/LeaseCallback.java
Tue Feb 22 09:22:23 2005
@@ -0,0 +1,18 @@
+
+package org.jpos.space.api;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+/**
+ * @author Niclas Hedhman
+ * @version $Id$
+ * @since 2.0
+ */
+public interface LeaseCallback
+{
+ /** Called when the leased reference has expired.
+ */
+ void expired( LeasedReference ref );
+}
+

Modified:
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/LeasedReference.java
==============================================================================
---
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/LeasedReference.java
(original)
+++
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/LeasedReference.java
Tue Feb 22 09:22:23 2005
@@ -55,12 +55,14 @@
/**
* LeasedReference references an object for a limited amount of time
* @author Alejandro Revilla
- * @version $Revision: 1.5 $ $Date: 2003/10/13 10:46:15 $
+ * @version $Id$
+ * @since 2.0
*/
public class LeasedReference extends TimerTask
{
- private Object referent;
- private long expiration;
+ private Object m_referent;
+ private LeaseCallback m_callback;
+ private long m_expiration;

private static Timer timer = new Timer( true );

@@ -68,68 +70,89 @@
{
}

- public LeasedReference( Object referent, long duration )
+ public LeasedReference( Object referent, LeaseCallback callback, long
duration )
{
super();
- this.referent = referent;
- this.expiration = System.currentTimeMillis() + duration;
+ m_referent = referent;
+ m_callback = callback;
+ m_expiration = System.currentTimeMillis() + duration;
timer.schedule( this, duration );
}

- public synchronized Object get()
+ public Object get()
{
- if( isValid() )
+ synchronized( this )
{
- return this.referent;
+ if( isValid() )
+ {
+ return m_referent;
+ }
+ m_referent = null;
+ m_expiration = 0;
+ super.cancel();
+ return null;
}
- this.referent = null;
- this.expiration = 0;
- super.cancel();
- return null;
}

- public synchronized long getExpiration()
+ public long getExpiration()
{
- return expiration;
+ synchronized( this )
+ {
+ return m_expiration;
+ }
}

- public synchronized boolean discard()
+ public boolean discard()
{
- if( isValid() )
+ synchronized( this )
{
- this.referent = null;
- this.expiration = 0;
- super.cancel();
- return true;
+ if( isValid() )
+ {
+ m_referent = null;
+ m_expiration = 0;
+ super.cancel();
+ return true;
+ }
}
return false;
}

- public synchronized long renew( long duration )
+ public long renew( long duration )
{
- if( isExpired () )
+ synchronized( this )
{
- return -1;
+ if( isExpired () )
+ {
+ return -1;
+ }
+ m_expiration = System.currentTimeMillis() + duration;
+ return m_expiration;
}
- expiration = System.currentTimeMillis() + duration;
- return( expiration );
}

- public synchronized boolean isExpired()
+ public boolean isExpired()
{
- return expiration <= System.currentTimeMillis();
+ synchronized( this )
+ {
+ return m_expiration <= System.currentTimeMillis();
+ }
}

- public synchronized boolean isValid()
+ public boolean isValid()
{
- return expiration > System.currentTimeMillis();
+ synchronized( this )
+ {
+ return m_expiration > System.currentTimeMillis();
+ }
}

public void run()
{
- long duration = expiration - System.currentTimeMillis();
+ long duration = m_expiration - System.currentTimeMillis();
if( duration < 0 )
{
+ if( m_callback != null )
+ m_callback.expired( this );
discard();
}
}

Modified:
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/LocalSpace.java
==============================================================================
---
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/LocalSpace.java
(original)
+++
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/LocalSpace.java
Tue Feb 22 09:22:23 2005
@@ -53,8 +53,8 @@

/**
* @author Kris, Bharavi, Alejandro
- * @version $Revision: 1.2 $ $Date: 2003/10/01 13:15:15 $
- *
+ * @version $Id$
+ * @since 2.0
* @metro.service type="org.jpos.space.api.LocalSpace" version="1.0"
*/
public interface LocalSpace extends Space

Modified:
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/RemoteSpace.java
==============================================================================
---
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/RemoteSpace.java
(original)
+++
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/RemoteSpace.java
Tue Feb 22 09:22:23 2005
@@ -57,7 +57,7 @@
* RMI based Space interface
*
* @author Alejandro Revilla
- * @version $Revision: 1.2 $ $Date: 2002/08/06 14:26:32 $
+ * @version $Id$
* @since 2.0
* @see Space
*

Modified:
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/Space.java
==============================================================================
---
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/Space.java
(original)
+++
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/Space.java
Tue Feb 22 09:22:23 2005
@@ -63,7 +63,7 @@
* by calling Space.in and read (without taking) by calling Space.rd</p>
*
* @author Alejandro Revilla
- * @version $Revision: 1.6 $ $Date: 2003/10/01 13:17:49 $
+ * @version $Id$
* @since 2.0
* @see LeasedReference
* @see TransientSpace

Modified:
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/SpaceException.java
==============================================================================
---
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/SpaceException.java
(original)
+++
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/SpaceException.java
Tue Feb 22 09:22:23 2005
@@ -56,8 +56,8 @@
* catch.
*
* @author Alejandro Revilla
- * @version $Revision: 1.3 $ $Date: 2003/10/13 10:46:16 $
- * @since 1.4.7
+ * @version $Id$
+ * @since 2.0
*/
public class SpaceException extends RuntimeException
{

Modified:
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/SpaceListener.java
==============================================================================
---
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/SpaceListener.java
(original)
+++
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/SpaceListener.java
Tue Feb 22 09:22:23 2005
@@ -51,7 +51,7 @@

/**
* @author Alejandro Revilla
- * @version $Revision: 1.2 $ $Date: 2002/08/06 14:26:32 $
+ * @version $Id$
* @since 2.0
* @see Space
*/

Modified:
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/Template.java
==============================================================================
---
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/Template.java
(original)
+++
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/Template.java
Tue Feb 22 09:22:23 2005
@@ -49,6 +49,11 @@

package org.jpos.space.api;

+/**
+ * @author Alejandro Revilla
+ * @version $Id$
+ * @since 2.0
+ */
public interface Template
{
Object getKey();

Modified: development/laboratory/planet/components/space/index.xml
==============================================================================
--- development/laboratory/planet/components/space/index.xml (original)
+++ development/laboratory/planet/components/space/index.xml Tue Feb 22
09:22:23 2005
@@ -22,20 +22,6 @@
</plugins>
</project>

- <project basedir="interceptor" >
- <info>
- <name>jpos-space-interceptor</name>
- <group>jpos/space</group>
- <version>2.0.0</version>
- </info>
- <dependencies>
- <include key="jpos-space-api" />
- </dependencies>
- <plugins>
- <include key="dpml-meta-tools" />
- </plugins>
- </project>
-
<project basedir="jdbm" >
<info>
<name>jpos-space-jdbm</name>
@@ -67,24 +53,6 @@
</plugins>
</project>

- <project basedir="proxy" >
- <info>
- <name>jpos-space-proxy</name>
- <group>jpos/space</group>
- <version>2.0.0</version>
- </info>
- <dependencies>
- <include key="dpml-activity-api" />
- <include key="dpml-logging-api" />
- <include key="dpml-parameters-api" />
- <include key="dpml-service-api" />
- <include key="jpos-space-api" />
- </dependencies>
- <plugins>
- <include key="dpml-meta-tools" />
- </plugins>
- </project>
-
<project basedir="tiny" >
<info>
<name>jpos-space-tiny</name>

Modified:
development/laboratory/planet/components/space/jdbm/src/main/org/jpos/space/Head.java
==============================================================================
---
development/laboratory/planet/components/space/jdbm/src/main/org/jpos/space/Head.java
(original)
+++
development/laboratory/planet/components/space/jdbm/src/main/org/jpos/space/Head.java
Tue Feb 22 09:22:23 2005
@@ -15,14 +15,14 @@
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
- * "This product includes software developed by the jPOS project
- * (http://www.jpos.org/)". Alternately, this acknowledgment may
- * appear in the software itself, if and wherever such third-party
+ * "This product includes software developed by the jPOS project
+ * (http://www.jpos.org/)". Alternately, this acknowledgment may
+ * appear in the software itself, if and wherever such third-party
* acknowledgments normally appear.
*
- * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
- * or promote products derived from this software without prior
- * written permission. For written permission, please contact
+ * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
+ * or promote products derived from this software without prior
+ * written permission. For written permission, please contact
* license AT jpos.org.
*
* 5. Products derived from this software may not be called "jPOS",
@@ -31,14 +31,14 @@
*
* 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 JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, 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
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, 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.
* ====================================================================
*
@@ -54,42 +54,47 @@
import java.io.ObjectOutput;
import java.io.ObjectInput;

-final class Head
- implements Externalizable
+/**
+ * @author Alejandro Revilla
+ * @version $Id$
+ * @since 2.0
+ */
+final class Head
+ implements Externalizable
{
static final long serialVersionUID = 3L;
-
+
long first;
long last;
long count;

- Head()
+ Head()
{
first = -1;
last = -1;
}
-
+
public void writeExternal( ObjectOutput out )
- throws IOException
+ throws IOException
{
out.writeLong( first );
out.writeLong( last );
out.writeLong( count );
}
-
+
public void readExternal( ObjectInput in )
- throws IOException
+ throws IOException
{
first = in.readLong();
last = in.readLong();
count = in.readLong();
}
-
- public String toString()
+
+ public String toString()
{
- return getClass().getName()
+ return getClass().getName()
+ "@" + Integer.toHexString( hashCode() )
- + ":[first=" + first
+ + ":[first=" + first
+ ",last=" + last
+ "]";
}

Modified:
development/laboratory/planet/components/space/jdbm/src/main/org/jpos/space/JDBMSpace.java
==============================================================================
---
development/laboratory/planet/components/space/jdbm/src/main/org/jpos/space/JDBMSpace.java
(original)
+++
development/laboratory/planet/components/space/jdbm/src/main/org/jpos/space/JDBMSpace.java
Tue Feb 22 09:22:23 2005
@@ -15,14 +15,14 @@
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
- * "This product includes software developed by the jPOS project
- * (http://www.jpos.org/)". Alternately, this acknowledgment may
- * appear in the software itself, if and wherever such third-party
+ * "This product includes software developed by the jPOS project
+ * (http://www.jpos.org/)". Alternately, this acknowledgment may
+ * appear in the software itself, if and wherever such third-party
* acknowledgments normally appear.
*
- * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
- * or promote products derived from this software without prior
- * written permission. For written permission, please contact
+ * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
+ * or promote products derived from this software without prior
+ * written permission. For written permission, please contact
* license AT jpos.org.
*
* 5. Products derived from this software may not be called "jPOS",
@@ -31,14 +31,14 @@
*
* 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 JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, 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
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, 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.
* ====================================================================
*
@@ -73,29 +73,29 @@
*
* @author Alejandro Revilla
* @author Kris Leite
- * @version $Revision: 1.6 $ $Date: 2004/04/18 15:39:12 $
- * @since 1.4.7
+ * @version $Id$
+ * @since 2.0
*
* @metro.component name="jdbm-space" lifestyle="singleton"
* @metro.service type="org.jpos.space.api.Space"
*/
-final public class JDBMSpace
- implements Space
+final public class JDBMSpace
+ implements Space
{
private HTree m_HTree;
private RecordManager m_RecordManager;
-
+
private boolean m_AutoCommit;
private Serializer m_RefSerializer;
-
- public JDBMSpace( Parameters params )
+
+ public JDBMSpace( Parameters params )
throws ParameterException
{
m_AutoCommit = params.getParameterAsBoolean( "auto-commit" );
String filename = params.getParameter( "store-filename" );
int cachesize = params.getParameterAsInteger( "cache-size" );
m_RefSerializer = new RefSerializer();
- try
+ try
{
Properties props = new Properties();
props.put( RecordManagerOptions.CACHE_SIZE, Integer.toString(
cachesize ) );
@@ -104,19 +104,19 @@
if( recid != 0 )
{
m_HTree = HTree.load( m_RecordManager, recid );
- }
+ }
else
{
m_HTree = HTree.createInstance( m_RecordManager );
m_RecordManager.setNamedObject( "space", m_HTree.getRecid()
);
}
m_RecordManager.commit();
- } catch( IOException e )
+ } catch( IOException e )
{
throw new SpaceException(e);
}
}
-
+
/**
* Use with utmost care and at your own risk.
*
@@ -140,14 +140,14 @@
{
this.m_AutoCommit = b;
}
-
+
/**
* force commit
* @see setAutoCommit(boolean)
*/
public void commit()
{
- try
+ try
{
m_RecordManager.commit();
this.notifyAll();
@@ -156,9 +156,9 @@
throw new SpaceException( e );
}
}
-
+
/**
- * force rollback
+ * force rollback
* @see setAutoCommit(boolean)
*/
public void rollback()
@@ -171,7 +171,7 @@
throw new SpaceException( e );
}
}
-
+
/**
* close this space - use with care
*/
@@ -189,7 +189,7 @@
}
}
}
-
+
/**
* Write a new entry into the Space
* @param key Entry's key
@@ -199,7 +199,7 @@
{
out( key, value, -1 );
}
-
+
/**
* Write a new entry into the Space
* The entry will timeout after the specified period
@@ -219,18 +219,18 @@
expiration = Long.MAX_VALUE;
else
expiration = System.currentTimeMillis() + timeout;
-
+
Ref dataRef = new Ref( recid, expiration );
long dataRefRecId = m_RecordManager.insert( dataRef,
m_RefSerializer );

Head head = (Head) m_HTree.get( key );
- if( head == null )
+ if( head == null )
{
head = new Head();
head.first = dataRefRecId;
head.last = dataRefRecId;
head.count = 1;
- } else
+ } else
{
long previousLast = head.last;
Ref lastRef = (Ref) m_RecordManager.fetch( previousLast,
m_RefSerializer );
@@ -251,23 +251,23 @@
throw new SpaceException( e );
}
}
-
+
/**
- * Read probe reads an entry from the space if one exists,
+ * Read probe reads an entry from the space if one exists,
* return null otherwise.
* @param key Entry's key
* @return value or null
*/
public synchronized Object rdp( Object key )
{
- try
+ try
{
- if( key instanceof Template )
+ if( key instanceof Template )
return getObject( (Template) key, false );

Object obj = null;
Ref ref = getFirst( key, false );
- if( ref != null )
+ if( ref != null )
obj = m_RecordManager.fetch( ref.recid );
if( m_AutoCommit )
m_RecordManager.commit();
@@ -279,16 +279,16 @@
}

/**
- * In probe takes an entry from the space if one exists,
+ * In probe takes an entry from the space if one exists,
* return null otherwise.
* @param key Entry's key
* @return value or null
*/
public synchronized Object inp( Object key )
{
- try
+ try
{
- if (key instanceof Template)
+ if (key instanceof Template)
return getObject ((Template) key, true);

Object obj = null;
@@ -306,38 +306,38 @@
throw new SpaceException( e );
}
}
-
+
public synchronized Object in( Object key )
{
Object obj = inp( key );
- while( obj == null )
+ while( obj == null )
{
- try
+ try
{
this.wait();
- } catch( InterruptedException e )
+ } catch( InterruptedException e )
{}
obj = inp( key );
}
return obj;
}
-
+
/**
* Take an entry from the space, waiting forever until one exists.
* @param key Entry's key
* @return value
*/
- public synchronized Object in( Object key, long timeout )
+ public synchronized Object in( Object key, long timeout )
{
Object obj = inp( key );
long now = System.currentTimeMillis();
long end = now + timeout;
while( obj == null && now < end )
{
- try
+ try
{
this.wait( end - now );
- } catch (InterruptedException e)
+ } catch (InterruptedException e)
{}
obj = inp( key );
now = System.currentTimeMillis();
@@ -353,12 +353,12 @@
public synchronized Object rd( Object key )
{
Object obj = rdp( key );
- while( obj == null )
+ while( obj == null )
{
- try
+ try
{
this.wait();
- } catch( InterruptedException e )
+ } catch( InterruptedException e )
{}
obj = rdp( key );
}
@@ -379,17 +379,17 @@
long end = now + timeout;
while( obj == null && now < end )
{
- try
+ try
{
this.wait( end - now );
- } catch (InterruptedException e)
+ } catch (InterruptedException e)
{}
obj = rdp( key );
now = System.currentTimeMillis();
}
return obj;
}
-
+
/**
* @return aproximately queue size
*/
@@ -401,14 +401,14 @@
if( head == null )
return 0;
return head.count;
- } catch( IOException e )
+ } catch( IOException e )
{
throw new SpaceException( e );
}
}

private void purge( Object key )
- throws IOException
+ throws IOException
{
Head head = (Head) m_HTree.get( key );
Ref ref;
@@ -418,20 +418,20 @@
for( long recid = head.first ; recid >= 0 ; )
{
Ref r = (Ref) m_RecordManager.fetch( recid, m_RefSerializer
);
- if( r.isExpired() )
+ if( r.isExpired() )
{
m_RecordManager.delete( r.recid );
m_RecordManager.delete( recid );
head.count--;
- if( previousRef == null )
+ if( previousRef == null )
{
head.first = r.next;
- } else
+ } else
{
previousRef.next = r.next;
m_RecordManager.update( head.last, previousRef,
m_RefSerializer );
}
- } else
+ } else
{
previousRef = r;
head.last = recid;
@@ -442,13 +442,13 @@
{
m_HTree.remove (key);
}
- else
+ else
{
m_HTree.put( key, head );
}
}
}
-
+
/**
* garbage collector.
* removes expired entries
@@ -457,7 +457,7 @@
{
final String GCKEY = "GC$" + Integer.toString( hashCode() );
final long TIMEOUT = 24 * 3600 * 1000;
- try
+ try
{
FastIterator iter = m_HTree.keys();
Object obj = Boolean.TRUE;
@@ -466,37 +466,37 @@
out( GCKEY, obj, TIMEOUT );

obj = iter.next();
- while( obj != null)
+ while( obj != null)
{
out( GCKEY, obj, TIMEOUT );
Thread.yield();
obj = iter.next();
}
obj = inp( GCKEY );
- while( obj != null )
+ while( obj != null )
{
- synchronized( this )
+ synchronized( this )
{
purge( obj );
m_RecordManager.commit();
}
Thread.yield();
obj = inp( GCKEY );
- }
+ }
} catch( IOException e )
{
throw new SpaceException( e );
}
}
-
- public String getKeys()
+
+ public String getKeys()
{
StringBuffer sb = new StringBuffer();
- try
+ try
{
FastIterator iter = m_HTree.keys();
Object obj = iter.next();
- while ( obj != null)
+ while ( obj != null)
{
if( sb.length() > 0 )
sb.append( ' ' );
@@ -509,28 +509,28 @@
}
return sb.toString();
}
-
+
private Ref getFirst( Object key, boolean remove )
- throws IOException
+ throws IOException
{
Head head = (Head) m_HTree.get( key );
Ref ref = null;
if( head != null )
{
long recid;
- for( recid = head.first ; recid >= 0 ; )
+ for( recid = head.first ; recid >= 0 ; )
{
Ref r = (Ref) m_RecordManager.fetch( recid, m_RefSerializer
);
- if( r.isExpired() )
+ if( r.isExpired() )
{
m_RecordManager.delete( r.recid );
m_RecordManager.delete( recid );
recid = r.next;
head.count--;
- } else
+ } else
{
ref = r;
- if (remove)
+ if (remove)
{
m_RecordManager.delete( recid );
recid = ref.next;
@@ -538,12 +538,12 @@
}
break;
}
- }
+ }
if( head.first != recid )
{
if( recid < 0 )
m_HTree.remove( key );
- else
+ else
{
head.first = recid;
m_HTree.put( key, head );
@@ -552,9 +552,9 @@
}
return ref;
}
-
+
private void unlinkRef
- ( long recid, Head head, Ref r, Ref previousRef, long previousRecId
)
+ ( long recid, Head head, Ref r, Ref previousRef, long previousRecId )
throws IOException
{
m_RecordManager.delete( r.recid );
@@ -562,15 +562,15 @@
head.count--;
if( previousRef == null )
head.first = r.next;
- else
+ else
{
previousRef.next = r.next;
m_RecordManager.update( previousRecId, previousRef,
m_RefSerializer );
}
}
-
- private Object getObject( Template tmpl, boolean remove )
- throws IOException
+
+ private Object getObject( Template tmpl, boolean remove )
+ throws IOException
{
Object obj = null;
Object key = tmpl.getKey();
@@ -579,7 +579,7 @@
Ref previousRef = null;
long previousRecId = 0;
int unlinkCount = 0;
- if( head != null )
+ if( head != null )
{
for( long recid = head.first ; recid >= 0 ; )
{
@@ -608,14 +608,14 @@
previousRecId = recid;
}
recid = r.next;
- }
+ }
if( unlinkCount > 0 )
{
if( head.first == -1 )
{
m_HTree.remove( key );
}
- else
+ else
{
m_HTree.put( key, head );
}

Modified:
development/laboratory/planet/components/space/jdbm/src/main/org/jpos/space/MD5Template.java
==============================================================================
---
development/laboratory/planet/components/space/jdbm/src/main/org/jpos/space/MD5Template.java
(original)
+++
development/laboratory/planet/components/space/jdbm/src/main/org/jpos/space/MD5Template.java
Tue Feb 22 09:22:23 2005
@@ -63,6 +63,11 @@
import org.jpos.space.api.Template;


+/**
+ * @author Alejandro Revilla
+ * @version $Id$
+ * @since 2.0
+ */
public class MD5Template
implements Template, Serializable
{

Modified:
development/laboratory/planet/components/space/jdbm/src/main/org/jpos/space/Ref.java
==============================================================================
---
development/laboratory/planet/components/space/jdbm/src/main/org/jpos/space/Ref.java
(original)
+++
development/laboratory/planet/components/space/jdbm/src/main/org/jpos/space/Ref.java
Tue Feb 22 09:22:23 2005
@@ -15,14 +15,14 @@
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
- * "This product includes software developed by the jPOS project
- * (http://www.jpos.org/)". Alternately, this acknowledgment may
- * appear in the software itself, if and wherever such third-party
+ * "This product includes software developed by the jPOS project
+ * (http://www.jpos.org/)". Alternately, this acknowledgment may
+ * appear in the software itself, if and wherever such third-party
* acknowledgments normally appear.
*
- * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
- * or promote products derived from this software without prior
- * written permission. For written permission, please contact
+ * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
+ * or promote products derived from this software without prior
+ * written permission. For written permission, please contact
* license AT jpos.org.
*
* 5. Products derived from this software may not be called "jPOS",
@@ -31,14 +31,14 @@
*
* 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 JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, 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
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, 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.
* ====================================================================
*
@@ -49,6 +49,11 @@

package org.jpos.space.jdbm;

+/**
+ * @author Alejandro Revilla
+ * @version $Id$
+ * @since 2.0
+ */
final class Ref
{
long recid;
@@ -62,14 +67,14 @@
this.next = -1;
}

- public boolean isExpired()
+ public boolean isExpired()
{
return expires < System.currentTimeMillis();
}
-
- public String toString()
+
+ public String toString()
{
- return getClass().getName()
+ return getClass().getName()
+ "@" + Integer.toHexString( hashCode() )
+ ":[recid=" + recid
+ ",next=" + next

Modified:
development/laboratory/planet/components/space/jdbm/src/main/org/jpos/space/RefSerializer.java
==============================================================================
---
development/laboratory/planet/components/space/jdbm/src/main/org/jpos/space/RefSerializer.java
(original)
+++
development/laboratory/planet/components/space/jdbm/src/main/org/jpos/space/RefSerializer.java
Tue Feb 22 09:22:23 2005
@@ -15,14 +15,14 @@
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
- * "This product includes software developed by the jPOS project
- * (http://www.jpos.org/)". Alternately, this acknowledgment may
- * appear in the software itself, if and wherever such third-party
+ * "This product includes software developed by the jPOS project
+ * (http://www.jpos.org/)". Alternately, this acknowledgment may
+ * appear in the software itself, if and wherever such third-party
* acknowledgments normally appear.
*
- * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
- * or promote products derived from this software without prior
- * written permission. For written permission, please contact
+ * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
+ * or promote products derived from this software without prior
+ * written permission. For written permission, please contact
* license AT jpos.org.
*
* 5. Products derived from this software may not be called "jPOS",
@@ -31,14 +31,14 @@
*
* 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 JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, 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
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, 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.
* ====================================================================
*
@@ -53,10 +53,15 @@

import jdbm.helper.Serializer;

+/**
+ * @author Alejandro Revilla
+ * @version $Id$
+ * @since 2.0
+ */
final class RefSerializer
- implements Serializer
+ implements Serializer
{
- public byte[] serialize( Object obj )
+ public byte[] serialize( Object obj )
throws IOException
{
Ref d = (Ref) obj;
@@ -67,8 +72,8 @@
putLong( buf, 16, d.expires );
return buf;
}
-
- public Object deserialize( byte[] serialized )
+
+ public Object deserialize( byte[] serialized )
throws IOException
{
long recid = getLong( serialized, 0 );
@@ -78,7 +83,7 @@
d.next = next;
return d;
}
-
+
private void putLong( byte[] b, int off, long val )
{
b[ off + 7 ] = (byte) ( val >>> 0 );
@@ -90,8 +95,8 @@
b[ off + 1 ] = (byte) ( val >>> 48 );
b[ off + 0 ] = (byte) ( val >>> 56 );
}
-
- private long getLong( byte[] b, int off )
+
+ private long getLong( byte[] b, int off )
{
return ( ( b[ off + 7 ] & 0xFFL ) << 0 ) +
( ( b[ off + 6 ] & 0xFFL ) << 8 ) +

Modified:
development/laboratory/planet/components/space/persistent/src/main/org/jpos/space/persistent/Data.java
==============================================================================
---
development/laboratory/planet/components/space/persistent/src/main/org/jpos/space/persistent/Data.java
(original)
+++
development/laboratory/planet/components/space/persistent/src/main/org/jpos/space/persistent/Data.java
Tue Feb 22 09:22:23 2005
@@ -15,14 +15,14 @@
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
- * "This product includes software developed by the jPOS project
- * (http://www.jpos.org/)". Alternately, this acknowledgment may
- * appear in the software itself, if and wherever such third-party
+ * "This product includes software developed by the jPOS project
+ * (http://www.jpos.org/)". Alternately, this acknowledgment may
+ * appear in the software itself, if and wherever such third-party
* acknowledgments normally appear.
*
- * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
- * or promote products derived from this software without prior
- * written permission. For written permission, please contact
+ * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
+ * or promote products derived from this software without prior
+ * written permission. For written permission, please contact
* license AT jpos.org.
*
* 5. Products derived from this software may not be called "jPOS",
@@ -31,14 +31,14 @@
*
* 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 JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, 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
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, 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.
* ====================================================================
*
@@ -66,7 +66,12 @@
import org.jpos.space.api.SpaceException;
import org.jpos.space.api.SpaceListener;

-final class Data
+/**
+ * @author Alejandro Revilla
+ * @version $Id$
+ * @since 2.0
+ */
+final class Data
{
private LinkedList data;
private LinkedList stored;
@@ -74,7 +79,7 @@
private File dir;
private int m_CacheSize;

- protected Data( Object name, int cachesize )
+ Data( Object name, int cachesize )
{
super();
m_CacheSize = cachesize;
@@ -88,24 +93,24 @@
n += "H" + name.hashCode();
dir = new File( n );
dir.mkdirs();
- FilenameFilter filter = new FilenameFilter()
+ FilenameFilter filter = new FilenameFilter()
{
- public boolean accept( File f, String name )
+ public boolean accept( File f, String name )
{
return name.toUpperCase().startsWith( "S" );
}
};
File file[] = dir.listFiles( filter );
Arrays.sort( file );
- for( int i = 0; file.length > i; i++ )
+ for( int i = 0; file.length > i; i++ )
{
- if( m_CacheSize > data.size() )
+ if( m_CacheSize > data.size() )
{
Object value = readValue( file[i].getAbsolutePath() );
- if( value == null )
+ if( value == null )
{
file[i].getAbsoluteFile().delete();
- } else
+ } else
{
stored.add( file[i].getAbsolutePath() );
data.add( value );
@@ -117,28 +122,31 @@
}
}

- private Object readValue( String f )
+ private Object readValue( String f )
{
Object value = null;
ObjectInputStream ois = null;
- try
+ try
{
FileInputStream fis = new FileInputStream( f );
BufferedInputStream bis = new BufferedInputStream( fis );
ois = new ObjectInputStream( bis );
value = ois.readObject();
- } catch (Exception e)
- {
+ }
+ catch (Exception e)
+ {
throw new SpaceException( e );
- } finally
+ }
+ finally
{
if( ois != null )
{
- try
+ try
{
ois.close();
- } catch( Exception e )
- {
+ }
+ catch( Exception e )
+ {
throw new SpaceException( e );
}
}
@@ -146,11 +154,11 @@
return value;
}

- protected File createTempFile( String prefex, File dir )
+ private File createTempFile( String prefex, File dir )
{
long t = System.currentTimeMillis();
File f = null;
- do
+ do
{
String fn = prefex + Long.toHexString(t);
t = t + 1;
@@ -159,11 +167,11 @@
return f;
}

- protected void add( Object value )
+ void add( Object value )
{
File f = null;
FileOutputStream fos = null;
- try
+ try
{
f = createTempFile( "S", dir );
fos = new FileOutputStream( f );
@@ -172,18 +180,20 @@
fout.writeObject( value );
fout.flush();
fos.getFD().sync();
- } catch( Exception e )
+ }
+ catch( Exception e )
{
throw new SpaceException( e );
- } finally
+ }
+ finally
{
if( fos != null )
{
- try
+ try
{
fos.close();
- } catch( Exception e )
- {
+ } catch( Exception e )
+ {
throw new SpaceException( e );
};
}
@@ -199,15 +209,15 @@
}
}

- protected Object get( Object value )
+ Object get( Object value )
{
Object obj = null;
- while( size() > 0 )
+ while( size() > 0 )
{
obj = getFirst();
if( obj instanceof LeasedReference )
obj = ((LeasedReference) obj).get();
- if( obj == null )
+ if( obj == null )
{
data.removeFirst();
String filename = (String) stored.removeFirst();
@@ -220,7 +230,7 @@
return obj;
}

- protected Object getFirst()
+ Object getFirst()
{
Object object = null;
if( data.size() > 0 )
@@ -233,28 +243,28 @@
return object;
}

- protected int size()
+ int size()
{
return stored.size();
}

- protected Object remove()
+ Object remove()
{
Object obj = null;
File f = null;
- while( size() > 0 )
+ while( size() > 0 )
{
obj = getFirst();
- if( data.size () > 0 )
+ if( data.size () > 0 )
data.removeFirst();
String filename = (String) stored.removeFirst();
f = new File( filename );
f.delete();
- if( obj instanceof LeasedReference )
+ if( obj instanceof LeasedReference )
{
LeasedReference ref = (LeasedReference) obj;
obj = ref.get ();
- if( obj == null )
+ if( obj == null )
{
continue;
}
@@ -265,21 +275,21 @@
return obj;
}

- protected boolean isEmpty()
+ boolean isEmpty()
{
return stored.isEmpty() && listeners == null;
}

- protected void addListener( SpaceListener listener )
+ void addListener( SpaceListener listener )
{
if( listeners == null )
listeners = new LinkedList();
listeners.add( listener );
}
-
- protected void removeListener( SpaceListener listener )
+
+ void removeListener( SpaceListener listener )
{
- if( listeners != null )
+ if( listeners != null )
{
listeners.remove( listener );
if( listeners.isEmpty() )
@@ -287,7 +297,7 @@
}
}

- protected List getListeners ()
+ List getListeners ()
{
return listeners;
}

Modified:
development/laboratory/planet/components/space/persistent/src/main/org/jpos/space/persistent/PersistentSpace.java
==============================================================================
---
development/laboratory/planet/components/space/persistent/src/main/org/jpos/space/persistent/PersistentSpace.java
(original)
+++
development/laboratory/planet/components/space/persistent/src/main/org/jpos/space/persistent/PersistentSpace.java
Tue Feb 22 09:22:23 2005
@@ -15,14 +15,14 @@
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
- * "This product includes software developed by the jPOS project
- * (http://www.jpos.org/)". Alternately, this acknowledgment may
- * appear in the software itself, if and wherever such third-party
+ * "This product includes software developed by the jPOS project
+ * (http://www.jpos.org/)". Alternately, this acknowledgment may
+ * appear in the software itself, if and wherever such third-party
* acknowledgments normally appear.
*
- * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
- * or promote products derived from this software without prior
- * written permission. For written permission, please contact
+ * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
+ * or promote products derived from this software without prior
+ * written permission. For written permission, please contact
* license AT jpos.org.
*
* 5. Products derived from this software may not be called "jPOS",
@@ -31,14 +31,14 @@
*
* 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 JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, 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
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, 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.
* ====================================================================
*
@@ -65,38 +65,38 @@
/**
* Persistent Space implementation
* @author Alejandro Revilla, modified by Kris Leite for Persistent
- * @version $Revision: 1.13 $ $Date: 2003/10/01 13:50:37 $
+ * @version $Id$
* @since 2.0
*
* @metro.component name="persistent-space" lifestyle="singleton"
* @metro.service type="org.jpos.space.api.LocalSpace"
* @metro.service type="org.jpos.space.api.Space"
*/
-final public class PersistentSpace
+final public class PersistentSpace
implements LocalSpace
{
private HashMap m_Map;
private int m_CacheSize;

- public PersistentSpace( Parameters params )
+ public PersistentSpace( Parameters params )
throws ParameterException
{
m_Map = new HashMap();
m_CacheSize = params.getParameterAsInteger( "cache-size" );
}
-
- public synchronized void setCacheSize( int cacheSize )
+
+ public synchronized void setCacheSize( int cacheSize )
{
m_CacheSize = cacheSize;
}
-
- public void out( Object key, Object value )
+
+ public void out( Object key, Object value )
{
List listeners;
- synchronized( this )
+ synchronized( this )
{
Data data = (Data) m_Map.get( key );
- if( data == null )
+ if( data == null )
{
data = new Data( key, m_CacheSize );
m_Map.put( key, data );
@@ -105,24 +105,24 @@
listeners = data.getListeners();
this.notifyAll ();
}
- if( listeners != null )
+ if( listeners != null )
{
Iterator iter = listeners.iterator();
- while( iter.hasNext() )
+ while( iter.hasNext() )
{
SpaceListener listener = (SpaceListener) iter.next();
listener.notify( key, value );
}
}
}
-
- public void out( Object id, Object value, long timeout )
+
+ public void out( Object id, Object value, long timeout )
{
- LeasedReference ref = new LeasedReference( value, timeout );
+ LeasedReference ref = new LeasedReference( value, null, timeout );
out( id, ref );
}
-
- public synchronized int size( Object key )
+
+ public synchronized int size( Object key )
{
Data data = (Data) m_Map.get( key );
if( data == null )
@@ -132,8 +132,8 @@
}
return data.size();
}
-
- public synchronized Object rdp( Object key )
+
+ public synchronized Object rdp( Object key )
{
Data data = (Data) m_Map.get( key );
if( data == null )
@@ -143,8 +143,8 @@
}
return data.get( key );
}
-
- public synchronized Object inp( Object key )
+
+ public synchronized Object inp( Object key )
{
Data data = (Data) m_Map.get( key );
if( data == null )
@@ -154,66 +154,66 @@
}
return data.remove();
}
-
- public synchronized Object in( Object key )
+
+ public synchronized Object in( Object key )
{
Object obj = inp( key );
- while( obj == null)
+ while( obj == null)
{
-
- try
+
+ try
{
this.wait();
- } catch( InterruptedException e )
+ } catch( InterruptedException e )
{}
obj = inp( key );
}
return obj;
}
-
- public synchronized Object in( Object key, long timeout )
+
+ public synchronized Object in( Object key, long timeout )
{
Object obj = inp( key );
long now = System.currentTimeMillis();
long end = now + timeout;
-
+
while( obj == null && now < end )
{
- try
+ try
{
this.wait( end - now );
- } catch( InterruptedException e )
+ } catch( InterruptedException e )
{}
obj = inp (key);
now = System.currentTimeMillis();
}
return obj;
}
-
- public synchronized Object rd( Object key )
+
+ public synchronized Object rd( Object key )
{
Object obj = rdp( key );
- while( obj == null )
+ while( obj == null )
{
- try
+ try
{
this.wait();
- } catch( InterruptedException e )
+ } catch( InterruptedException e )
{}
obj = rdp( key );
}
return obj;
}
-
+
public synchronized Object rd( Object key, long timeout )
{
Object obj = rdp( key );
long now = System.currentTimeMillis();
long end = now + timeout;
-
+
while( obj == null && now < end )
{
- try
+ try
{
this.wait( end - now );
} catch( InterruptedException e )
@@ -223,8 +223,8 @@
}
return obj;
}
-
- public synchronized void addListener( Object key, SpaceListener listener
)
+
+ public synchronized void addListener( Object key, SpaceListener listener
)
{
Data data = (Data) m_Map.get( key );
if( data == null )
@@ -234,28 +234,28 @@
}
data.addListener( listener );
}
-
- public synchronized void removeListener( Object key, SpaceListener
listener)
+
+ public synchronized void removeListener( Object key, SpaceListener
listener)
{
Data data = (Data) m_Map.get( key );
if (data != null)
data.removeListener( listener );
}

- public Set getKeySet()
+ public Set getKeySet()
{
- synchronized( this )
+ synchronized( this )
{
return m_Map.keySet();
}
}
-
- public String getKeys()
+
+ public String getKeys()
{
StringBuffer sb = new StringBuffer();
Iterator iter = m_Map.keySet().iterator();
boolean first = true;
- while( iter.hasNext() )
+ while( iter.hasNext() )
{
if( ! first )
sb.append( ' ' );
@@ -266,12 +266,12 @@
return sb.toString();
}

- public void write( String key, String value )
+ public void write( String key, String value )
{
out( key, value );
}

- public String read( String key )
+ public String read( String key )
{
Object o = inp( key );
if( o == null )

Modified:
development/laboratory/planet/components/space/tiny/src/main/org/jpos/space/tiny/Data.java
==============================================================================
---
development/laboratory/planet/components/space/tiny/src/main/org/jpos/space/tiny/Data.java
(original)
+++
development/laboratory/planet/components/space/tiny/src/main/org/jpos/space/tiny/Data.java
Tue Feb 22 09:22:23 2005
@@ -15,14 +15,14 @@
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
- * "This product includes software developed by the jPOS project
- * (http://www.jpos.org/)". Alternately, this acknowledgment may
- * appear in the software itself, if and wherever such third-party
+ * "This product includes software developed by the jPOS project
+ * (http://www.jpos.org/)". Alternately, this acknowledgment may
+ * appear in the software itself, if and wherever such third-party
* acknowledgments normally appear.
*
- * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
- * or promote products derived from this software without prior
- * written permission. For written permission, please contact
+ * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
+ * or promote products derived from this software without prior
+ * written permission. For written permission, please contact
* license AT jpos.org.
*
* 5. Products derived from this software may not be called "jPOS",
@@ -31,14 +31,14 @@
*
* 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 JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, 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
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, 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.
* ====================================================================
*
@@ -53,38 +53,43 @@

import org.jpos.space.api.LeasedReference;

-final class Data
+/**
+ * @author Alejandro Revilla
+ * @version $Id$
+ * @since 2.0
+ */
+final class Data
{
LinkedList data;

- Data()
+ Data()
{
super();
data = new LinkedList();
}
-
- protected Data( Object value )
+
+ Data( Object value )
{
- this ();
- add (value);
+ this();
+ add( value );
}
-
- protected void add( Object value )
+
+ void add( Object value )
{
- data.add (value);
+ data.add( value );
}
-
- protected Object get( Object value )
+
+ Object get( Object value )
{
Object obj = null;
- while( size() > 0 )
+ while( size() > 0 )
{
obj = data.getFirst();
- if( obj instanceof LeasedReference )
+ if( obj instanceof LeasedReference )
{
LeasedReference ref = (LeasedReference) obj;
obj = ref.get();
- if( obj == null )
+ if( obj == null )
{
data.removeFirst();
continue;
@@ -94,23 +99,23 @@
}
return obj;
}
-
- protected int size()
+
+ int size()
{
return data.size();
}
-
- protected Object remove()
+
+ Object remove()
{
Object obj = null;
- while( size() > 0 )
+ while( size() > 0 )
{
obj = data.removeFirst();
if( obj instanceof LeasedReference )
{
LeasedReference ref = (LeasedReference) obj;
obj = ref.get();
- if( obj == null )
+ if( obj == null )
{
continue;
}
@@ -120,8 +125,8 @@
}
return obj;
}
-
- protected boolean isEmpty()
+
+ boolean isEmpty()
{
return data.isEmpty();
}

Modified:
development/laboratory/planet/components/space/tiny/src/main/org/jpos/space/tiny/TinySpace.java
==============================================================================
---
development/laboratory/planet/components/space/tiny/src/main/org/jpos/space/tiny/TinySpace.java
(original)
+++
development/laboratory/planet/components/space/tiny/src/main/org/jpos/space/tiny/TinySpace.java
Tue Feb 22 09:22:23 2005
@@ -15,14 +15,14 @@
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
- * "This product includes software developed by the jPOS project
- * (http://www.jpos.org/)". Alternately, this acknowledgment may
- * appear in the software itself, if and wherever such third-party
+ * "This product includes software developed by the jPOS project
+ * (http://www.jpos.org/)". Alternately, this acknowledgment may
+ * appear in the software itself, if and wherever such third-party
* acknowledgments normally appear.
*
- * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
- * or promote products derived from this software without prior
- * written permission. For written permission, please contact
+ * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
+ * or promote products derived from this software without prior
+ * written permission. For written permission, please contact
* license AT jpos.org.
*
* 5. Products derived from this software may not be called "jPOS",
@@ -31,14 +31,14 @@
*
* 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 JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, 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
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, 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.
* ====================================================================
*
@@ -53,6 +53,7 @@

import java.io.Serializable;

+import org.jpos.space.api.LeaseCallback;
import org.jpos.space.api.LeasedReference;
import org.jpos.space.api.Space;

@@ -60,32 +61,36 @@
* Tiny Space implementation
*
* @author Alejandro Revilla
- * @version $Revision: 1.2 $ $Date: 2003/12/30 21:19:26 $
- * @since 1.4.7
+ * @version $Id$
+ * @since 2.0
*
* @metro.component name="tiny-space" lifestyle="singleton"
* @metro.service type="org.jpos.space.api.Space"
*/
-public class TinySpace
- implements Space, Serializable
+public class TinySpace
+ implements Space, Serializable
{
protected HashMap map = new HashMap();

- public TinySpace()
+ public TinySpace()
{
super();
}
-
+
public void out( Object key, Object value )
{
- synchronized( this )
+ synchronized( this )
{
Object v = map.get( key );
if( v == null )
+ {
map.put( key, value );
+ }
else if( v instanceof Data )
+ {
((Data) v).add( value );
- else
+ }
+ else
{
Data data = new Data();
data.add( v );
@@ -95,114 +100,130 @@
this.notifyAll();
}
}
-
- public void out( Object id, Object value, long timeout )
+
+ public void out( Object id, Object value, long timeout )
{
- LeasedReference ref = new LeasedReference( value, timeout );
- out( id, ref );
+ LeaseCallback callback = new LeaseCallback()
+ {
+ public void expired( LeasedReference ref )
+ {
+ inp( ref.get() ); // remove the entry from the space.
+ }
+ };
+
+ LeasedReference ref = new LeasedReference( id, callback, timeout );
+ out( id, value );
}
-
- public synchronized Object rdp( Object key )
+
+ public Object rdp( Object key )
{
- Object obj = map.get( key );
- if( obj instanceof Data )
+ synchronized( this )
{
- Data data = (Data) obj;
- obj = data.get( key );
- }
- else if( obj instanceof LeasedReference )
- {
- LeasedReference ref = (LeasedReference) obj;
- obj = ref.get();
+ Object obj = map.get( key );
+ if( obj instanceof Data )
+ {
+ Data data = (Data) obj;
+ obj = data.get( key );
+ }
+ return obj;
}
- return obj;
}
-
- public synchronized Object inp( Object key )
+
+ public Object inp( Object key )
{
- Object obj = map.get( key );
- if( obj instanceof Data )
- {
- Data data = (Data) obj;
- obj = data.remove();
- if( data.isEmpty () )
- map.remove( key );
- } else if( obj != null )
+ synchronized( this )
{
- if( obj instanceof LeasedReference )
+ Object obj = map.get( key );
+ if( obj instanceof Data )
{
- LeasedReference ref = (LeasedReference) obj;
- obj = ref.get();
+ Data data = (Data) obj;
+ obj = data.remove();
+ if( data.isEmpty () )
+ map.remove( key );
+ } else if( obj != null )
+ {
+ map.remove( key );
}
- map.remove( key );
+ return obj;
}
- return obj;
}
-
- public synchronized Object in( Object key )
+
+ public Object in( Object key )
{
- Object obj = inp( key );
- while( obj == null)
+ synchronized( this )
{
- try
+ Object obj = inp( key );
+ while( obj == null)
{
- this.wait();
- } catch( InterruptedException e )
- {}
- obj = inp( key );
+ try
+ {
+ wait();
+ } catch( InterruptedException e )
+ {}
+ obj = inp( key );
+ }
+ return obj;
}
- return obj;
}
-
- public synchronized Object in( Object key, long timeout )
+
+ public Object in( Object key, long timeout )
{
- Object obj = inp( key );
- long now = System.currentTimeMillis();
- long end = now + timeout;
- while( obj == null && now < end )
+ synchronized( this )
{
- try
+ Object obj = inp( key );
+ long now = System.currentTimeMillis();
+ long end = now + timeout;
+ while( obj == null && now < end )
{
- this.wait( end - now );
- } catch( InterruptedException e )
- {}
- obj = inp( key );
- now = System.currentTimeMillis();
+ try
+ {
+ wait( end - now );
+ } catch( InterruptedException e )
+ {}
+ obj = inp( key );
+ now = System.currentTimeMillis();
+ }
+ return obj;
}
- return obj;
}
-
- public synchronized Object rd( Object key )
+
+ public Object rd( Object key )
{
- Object obj = rdp( key );
- while( obj == null )
+ synchronized( this )
{
- try
+ Object obj = rdp( key );
+ while( obj == null )
{
- this.wait();
- } catch( InterruptedException e )
- {}
- obj = rdp( key );
+ try
+ {
+ wait();
+ } catch( InterruptedException e )
+ {}
+ obj = rdp( key );
+ }
+ return obj;
}
- return obj;
}
-
- public synchronized Object rd( Object key, long timeout )
+
+ public Object rd( Object key, long timeout )
{
- Object obj = rdp( key );
- long now = System.currentTimeMillis();
- long end = now + timeout;
- while( obj == null && now < end )
+ synchronized( this )
{
- try
+ Object obj = rdp( key );
+ long now = System.currentTimeMillis();
+ long end = now + timeout;
+ while( obj == null && now < end )
{
- this.wait( end - now );
- } catch( InterruptedException e )
- {}
- obj = rdp( key );
- now = System.currentTimeMillis();
+ try
+ {
+ wait( end - now );
+ } catch( InterruptedException e )
+ {}
+ obj = rdp( key );
+ now = System.currentTimeMillis();
+ }
+ return obj;
}
- return obj;
}
}


Modified:
development/laboratory/planet/components/space/transient/src/main/org/jpos/space/transiient/Data.java
==============================================================================
---
development/laboratory/planet/components/space/transient/src/main/org/jpos/space/transiient/Data.java
(original)
+++
development/laboratory/planet/components/space/transient/src/main/org/jpos/space/transiient/Data.java
Tue Feb 22 09:22:23 2005
@@ -15,14 +15,14 @@
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
- * "This product includes software developed by the jPOS project
- * (http://www.jpos.org/)". Alternately, this acknowledgment may
- * appear in the software itself, if and wherever such third-party
+ * "This product includes software developed by the jPOS project
+ * (http://www.jpos.org/)". Alternately, this acknowledgment may
+ * appear in the software itself, if and wherever such third-party
* acknowledgments normally appear.
*
- * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
- * or promote products derived from this software without prior
- * written permission. For written permission, please contact
+ * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
+ * or promote products derived from this software without prior
+ * written permission. For written permission, please contact
* license AT jpos.org.
*
* 5. Products derived from this software may not be called "jPOS",
@@ -31,14 +31,14 @@
*
* 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 JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, 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
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, 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.
* ====================================================================
*
@@ -55,27 +55,32 @@
import org.jpos.space.api.LeasedReference;
import org.jpos.space.api.SpaceListener;

-final class Data
+/**
+ * @author Alejandro Revilla
+ * @version $Id$
+ * @since 2.0
+ */
+final class Data
{
private LinkedList data;
private LinkedList listeners;

- Data()
+ Data()
{
super();
data = new LinkedList();
listeners = null;
}
-
+
void add( Object value )
{
data.add( value );
}
-
+
Object get( Object value )
{
Object obj = null;
- while( size() > 0 )
+ while( size() > 0 )
{
obj = data.getFirst();
if( obj instanceof LeasedReference )
@@ -92,12 +97,12 @@
}
return obj;
}
-
+
int size()
{
return data.size();
}
-
+
Object remove()
{
Object obj = null;
@@ -118,30 +123,30 @@
}
return obj;
}
-
+
boolean isEmpty()
{
return data.isEmpty() && listeners == null;
}
-
+
void addListener( SpaceListener listener )
{
if (listeners == null)
listeners = new LinkedList();
listeners.add( listener );
}
-
+
void removeListener( SpaceListener listener )
{
- if( listeners != null )
+ if( listeners != null )
{
listeners.remove( listener );
if( listeners.isEmpty() )
listeners = null;
}
}
-
- List getListeners()
+
+ List getListeners()
{
return listeners;
}

Modified:
development/laboratory/planet/components/space/transient/src/main/org/jpos/space/transiient/TransientSpace.java
==============================================================================
---
development/laboratory/planet/components/space/transient/src/main/org/jpos/space/transiient/TransientSpace.java
(original)
+++
development/laboratory/planet/components/space/transient/src/main/org/jpos/space/transiient/TransientSpace.java
Tue Feb 22 09:22:23 2005
@@ -15,14 +15,14 @@
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
- * "This product includes software developed by the jPOS project
- * (http://www.jpos.org/)". Alternately, this acknowledgment may
- * appear in the software itself, if and wherever such third-party
+ * "This product includes software developed by the jPOS project
+ * (http://www.jpos.org/)". Alternately, this acknowledgment may
+ * appear in the software itself, if and wherever such third-party
* acknowledgments normally appear.
*
- * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
- * or promote products derived from this software without prior
- * written permission. For written permission, please contact
+ * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
+ * or promote products derived from this software without prior
+ * written permission. For written permission, please contact
* license AT jpos.org.
*
* 5. Products derived from this software may not be called "jPOS",
@@ -31,14 +31,14 @@
*
* 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 JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, 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
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, 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.
* ====================================================================
*
@@ -61,7 +61,7 @@
/**
* Transient Space implementation
* @author Alejandro Revilla
- * @version $Revision: 1.10 $ $Date: 2003/10/01 13:15:44 $
+ * @version $Id$
* @since 2.0
* @jmx:mbean description "TransientSpace"
*
@@ -69,7 +69,7 @@
* @metro.service type="org.jpos.space.api.LocalSpace"
* @metro.service type="org.jpos.space.api.Space"
*/
-public class TransientSpace
+public class TransientSpace
implements LocalSpace //, TransientSpaceMBean Niclas: Doesn't exist
{
protected HashMap map;
@@ -81,14 +81,14 @@
{
map = new HashMap();
}
-
+
public void out( Object key, Object value )
{
List listeners;
synchronized( this )
{
Data data = (Data) map.get( key );
- if( data == null )
+ if( data == null )
{
data = new Data();
map.put( key, data );
@@ -107,119 +107,143 @@
}
}
}
-
- public void out( Object id, Object value, long timeout )
+
+ public void out( Object id, Object value, long timeout )
{
- LeasedReference ref = new LeasedReference( value, timeout );
+ LeasedReference ref = new LeasedReference( value, null, timeout );
out( id, ref );
}
-
- public synchronized Object rdp( Object key )
+
+ public Object rdp( Object key )
{
- Object obj = null;
- Data data = (Data) map.get( key );
- if( data != null )
+ synchronized( this )
{
- return data.get( key );
+ Object obj = null;
+ Data data = (Data) map.get( key );
+ if( data != null )
+ {
+ return data.get( key );
+ }
+ return obj;
}
- return obj;
}
-
- public synchronized Object inp( Object key )
+
+ public Object inp( Object key )
{
- Object obj = null;
- Data data = (Data) map.get( key );
- if( data != null )
+ synchronized( this )
{
- obj = data.remove();
- if( data.isEmpty() )
- map.remove( key );
+ Object obj = null;
+ Data data = (Data) map.get( key );
+ if( data != null )
+ {
+ obj = data.remove();
+ if( data.isEmpty() )
+ map.remove( key );
+ }
+ return obj;
}
- return obj;
}
-
- public synchronized Object in( Object key )
+
+ public Object in( Object key )
{
- Object obj = inp( key );
- while( obj == null )
+ synchronized( this )
{
- try
+ Object obj = inp( key );
+ while( obj == null )
{
- this.wait();
- } catch( InterruptedException e )
- {}
- obj = inp( key );
+ try
+ {
+ this.wait();
+ } catch( InterruptedException e )
+ {}
+ obj = inp( key );
+ }
+ return obj;
}
- return obj;
}
-
- public synchronized Object in( Object key, long timeout )
+
+ public Object in( Object key, long timeout )
{
- Object obj = inp( key );
- long now = System.currentTimeMillis();
- long end = now + timeout;
- while( obj == null && now < end )
+ synchronized( this )
{
- try
+ Object obj = inp( key );
+ long now = System.currentTimeMillis();
+ long end = now + timeout;
+ while( obj == null && now < end )
{
- this.wait( end - now );
- } catch( InterruptedException e )
- {}
- obj = inp( key );
- now = System.currentTimeMillis();
+ try
+ {
+ this.wait( end - now );
+ } catch( InterruptedException e )
+ {}
+ obj = inp( key );
+ now = System.currentTimeMillis();
+ }
+ return obj;
}
- return obj;
}
-
- public synchronized Object rd( Object key )
+
+ public Object rd( Object key )
{
- Object obj = rdp( key );
- while( obj == null )
+ synchronized( this )
{
- try
+ Object obj = rdp( key );
+ while( obj == null )
{
- this.wait();
- } catch( InterruptedException e )
- {}
- obj = rdp( key );
- }
- return obj;
- }
-
- public synchronized Object rd( Object key, long timeout )
- {
- Object obj = rdp( key );
- long now = System.currentTimeMillis();
- long end = now + timeout;
- while( obj == null && now < end )
+ try
+ {
+ this.wait();
+ } catch( InterruptedException e )
+ {}
+ obj = rdp( key );
+ }
+ return obj;
+ }
+ }
+
+ public Object rd( Object key, long timeout )
+ {
+ synchronized( this )
{
- try
+ Object obj = rdp( key );
+ long now = System.currentTimeMillis();
+ long end = now + timeout;
+ while( obj == null && now < end )
{
- this.wait( end - now );
- } catch( InterruptedException e )
- {}
- obj = rdp( key );
- now = System.currentTimeMillis();
+ try
+ {
+ this.wait( end - now );
+ } catch( InterruptedException e )
+ {}
+ obj = rdp( key );
+ now = System.currentTimeMillis();
+ }
+ return obj;
}
- return obj;
}
-
- public synchronized void addListener( Object key, SpaceListener listener
)
+
+ public void addListener( Object key, SpaceListener listener )
{
- Data data = (Data) map.get( key );
- if( data == null )
+ synchronized( this )
{
- data = new Data();
- map.put( key, data );
+ Data data = (Data) map.get( key );
+ if( data == null )
+ {
+ data = new Data();
+ map.put( key, data );
+ }
+ data.addListener( listener );
}
- data.addListener( listener );
}
-
- public synchronized void removeListener( Object key, SpaceListener
listener )
+
+ public void removeListener( Object key, SpaceListener listener )
{
- Data data = (Data) map.get( key );
- if( data != null )
- data.removeListener( listener );
+ synchronized( this )
+ {
+ Data data = (Data) map.get( key );
+ if( data != null )
+ data.removeListener( listener );
+ }
}

/**
@@ -228,12 +252,12 @@
*/
public Set getKeySet()
{
- synchronized(this)
+ synchronized(this)
{
return map.keySet();
}
}
-
+
public String getKeys()
{
StringBuffer sb = new StringBuffer ();
@@ -277,7 +301,7 @@
return "null";
return obj.toString();
}
-
+
public int size( Object key )
{
Data data = (Data) map.get( key );

Modified:
development/laboratory/planet/components/space/util/src/main/org/jpos/space/util/Connector.java
==============================================================================
---
development/laboratory/planet/components/space/util/src/main/org/jpos/space/util/Connector.java
(original)
+++
development/laboratory/planet/components/space/util/src/main/org/jpos/space/util/Connector.java
Tue Feb 22 09:22:23 2005
@@ -15,14 +15,14 @@
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
- * "This product includes software developed by the jPOS project
- * (http://www.jpos.org/)". Alternately, this acknowledgment may
- * appear in the software itself, if and wherever such third-party
+ * "This product includes software developed by the jPOS project
+ * (http://www.jpos.org/)". Alternately, this acknowledgment may
+ * appear in the software itself, if and wherever such third-party
* acknowledgments normally appear.
*
- * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
- * or promote products derived from this software without prior
- * written permission. For written permission, please contact
+ * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
+ * or promote products derived from this software without prior
+ * written permission. For written permission, please contact
* license AT jpos.org.
*
* 5. Products derived from this software may not be called "jPOS",
@@ -31,14 +31,14 @@
*
* 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 JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, 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
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, 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.
* ====================================================================
*
@@ -60,16 +60,16 @@

/**
* @author Alejandro Revilla
- * @version $Revision: 1.4 $ $Date: 2003/05/16 04:11:58 $
+ * @version $Id$
* @since 2.0
*/
-public class Connector
+public class Connector
implements SpaceListener
{
private LocalSpace m_LocalSpace;
private String m_From;
private String m_To;
-
+
public Connector( ServiceManager man, Parameters params )
throws ServiceException, ParameterException
{
@@ -79,8 +79,8 @@
m_To = params.getParameter( "to" );
m_LocalSpace.addListener( m_From, this );
}
-
- public void notify( Object key, Object value )
+
+ public void notify( Object key, Object value )
{
Object o = m_LocalSpace.inp( key );
if( o != null )

Modified:
development/laboratory/planet/components/space/util/src/main/org/jpos/space/util/ObjectTemplate.java
==============================================================================
---
development/laboratory/planet/components/space/util/src/main/org/jpos/space/util/ObjectTemplate.java
(original)
+++
development/laboratory/planet/components/space/util/src/main/org/jpos/space/util/ObjectTemplate.java
Tue Feb 22 09:22:23 2005
@@ -10,6 +10,11 @@

import org.jpos.space.api.Template;

+/**
+ * @author Alejandro Revilla
+ * @version $Id$
+ * @since 2.0
+ */
public class ObjectTemplate
implements Template
{

Modified:
development/laboratory/planet/components/space/util/src/main/org/jpos/space/util/SpaceUtil.java
==============================================================================
---
development/laboratory/planet/components/space/util/src/main/org/jpos/space/util/SpaceUtil.java
(original)
+++
development/laboratory/planet/components/space/util/src/main/org/jpos/space/util/SpaceUtil.java
Tue Feb 22 09:22:23 2005
@@ -15,14 +15,14 @@
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
- * "This product includes software developed by the jPOS project
- * (http://www.jpos.org/)". Alternately, this acknowledgment may
- * appear in the software itself, if and wherever such third-party
+ * "This product includes software developed by the jPOS project
+ * (http://www.jpos.org/)". Alternately, this acknowledgment may
+ * appear in the software itself, if and wherever such third-party
* acknowledgments normally appear.
*
- * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
- * or promote products derived from this software without prior
- * written permission. For written permission, please contact
+ * 4. The names "jPOS" and "jPOS.org" must not be used to endorse
+ * or promote products derived from this software without prior
+ * written permission. For written permission, please contact
* license AT jpos.org.
*
* 5. Products derived from this software may not be called "jPOS",
@@ -31,14 +31,14 @@
*
* 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 JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, 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
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, 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.
* ====================================================================
*
@@ -58,11 +58,11 @@
* Space related helper methods
*
* @author Alejandro Revilla
- * @version $Revision: 1.2 $ $Date: 2004/04/10 21:23:31 $
- * @since 1.4.7
+ * @version $Id$
+ * @since 2.0
*/

-public class SpaceUtil
+public class SpaceUtil
{
/**
* return all entries under a given key
@@ -71,14 +71,14 @@
* @param key Entry's key
* @return array containing all entries under key
*/
- public static Object[] inpAll( Space sp, Object key )
+ public static Object[] inpAll( Space sp, Object key )
{
List list = new ArrayList();
Object value;
- do
+ do
{
value = sp.inp (key);
- if (value != null)
+ if (value != null)
{
list.add (value);
}
@@ -92,20 +92,20 @@
* @param sp the Space
* @param key Entry's key
*/
- public static void wipe( Space sp, Object key )
+ public static void wipe( Space sp, Object key )
{
while( sp.inp( key ) != null )
;
}
-
- public static long nextLong( Space sp, Object key )
+
+ public static long nextLong( Space sp, Object key )
{
long l = 0L;
- synchronized( sp )
+ synchronized( sp )
{
Object obj = sp.inp( key );
wipe( sp, key ); // just in case
- if( obj instanceof Long )
+ if( obj instanceof Long )
l = ( (Long) obj ).longValue();
sp.out( key, new Long( ++l ) );
}



  • svn commit: r1872 - in development/laboratory/planet/components/space: . api/src/main/org/jpos/space/api interceptor jdbm/src/main/org/jpos/space persistent/src/main/org/jpos/space/persistent proxy tiny/src/main/org/jpos/space/tiny transient/src/main/org/jpos/space/transiient tspace util/src/main/org/jpos/space/util, niclas, 02/22/2005

Archive powered by MHonArc 2.6.24.

Top of Page