Skip to Content.
Sympa Menu

notify-dpml - svn commit: r1884 - in development/laboratory/planet/components/space: . api/src/main/org/jpos/space/api jdbm persistent tiny/src/main/org/jpos/space/tiny transient 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: r1884 - in development/laboratory/planet/components/space: . api/src/main/org/jpos/space/api jdbm persistent tiny/src/main/org/jpos/space/tiny transient util/src/main/org/jpos/space/util
  • Date: Wed, 23 Feb 2005 19:19:19 +0100

Author: niclas
Date: Wed Feb 23 19:19:19 2005
New Revision: 1884

Added:

development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/SpaceStore.java
(contents, props changed)

development/laboratory/planet/components/space/tiny/src/main/org/jpos/space/tiny/DefaultExpiry.java
(contents, props changed)

development/laboratory/planet/components/space/tiny/src/main/org/jpos/space/tiny/TransientStore.java
(contents, props changed)
Removed:

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/jdbm/
development/laboratory/planet/components/space/persistent/

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

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
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/Space.java

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

development/laboratory/planet/components/space/tiny/src/main/org/jpos/space/tiny/TinySpace.java
Log:
Big reshuffle, change of API and cutting of the fat.

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
Wed Feb 23 19:19:19 2005
@@ -1,51 +1,3 @@
-/*
- * Copyright (c) 2000 jPOS.org. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, 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 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
- * license AT jpos.org.
- *
- * 5. Products derived from this software may not be called "jPOS",
- * nor may "jPOS" appear in their name, without prior written
- * permission of the jPOS project.
- *
- * 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
- * POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the jPOS Project. For more
- * information please see <http://www.jpos.org/>.
- */

package org.jpos.space.api;

@@ -53,108 +5,66 @@
import java.util.TimerTask;

/**
- * LeasedReference references an object for a limited amount of time
- * @author Alejandro Revilla
+ * A facade of an object, allowing for a callback method to be called
+ * when the object 'expires'.
+ *
+ * @author Niclas Hedhman
* @version $Id$
* @since 2.0
*/
public class LeasedReference extends TimerTask
{
- private Object m_referent;
+ private Object m_reference;
private LeaseCallback m_callback;
- private long m_expiration;
+ private long m_expiresAt;

- private static Timer timer = new Timer( true );
+ private static Timer m_timer = new Timer( true );

- private LeasedReference()
- {
- }
-
- public LeasedReference( Object referent, LeaseCallback callback, long
duration )
+ public LeasedReference( Object reference, LeaseCallback callback, long
duration )
{
super();
- m_referent = referent;
+ m_reference = reference;
m_callback = callback;
- m_expiration = System.currentTimeMillis() + duration;
- timer.schedule( this, duration );
- }
-
- public Object get()
- {
- synchronized( this )
- {
- if( isValid() )
- {
- return m_referent;
- }
- m_referent = null;
- m_expiration = 0;
- super.cancel();
- return null;
- }
+ renew( duration );
}

- public long getExpiration()
+ public Object getReference()
{
synchronized( this )
{
- return m_expiration;
+ return m_reference;
}
}

- public boolean discard()
+ public void renew( long duration )
{
synchronized( this )
{
- if( isValid() )
- {
- m_referent = null;
- m_expiration = 0;
- super.cancel();
- return true;
- }
+ cancel();
+ m_expiresAt = System.currentTimeMillis() + duration;
+ m_timer.schedule( this, duration );
}
- return false;
}

- public long renew( long duration )
+ public void run()
{
- synchronized( this )
+ long timeLeft = m_expiresAt - System.currentTimeMillis();
+ if( timeLeft < 0 )
{
- if( isExpired () )
- {
- return -1;
- }
- m_expiration = System.currentTimeMillis() + duration;
- return m_expiration;
+ if( m_callback != null )
+ m_callback.expired( this );
}
+ else
+ m_timer.schedule( this, timeLeft );
}

- public boolean isExpired()
+ public boolean equals( Object other )
{
- synchronized( this )
- {
- return m_expiration <= System.currentTimeMillis();
- }
+ return m_reference.equals( other );
}

- public boolean isValid()
+ public int hashCode()
{
- synchronized( this )
- {
- return m_expiration > System.currentTimeMillis();
- }
- }
-
- public void run()
- {
- long duration = m_expiration - System.currentTimeMillis();
- if( duration < 0 )
- {
- if( m_callback != null )
- m_callback.expired( this );
- discard();
- }
+ return m_reference.hashCode();
}
}
-

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
Wed Feb 23 19:19:19 2005
@@ -49,26 +49,22 @@

package org.jpos.space.api;

+import java.util.Iterator;

/** The Space API.
* <p><b>Space</b> uses concepts described in the Linda Coordination Language
- * that eases the implementation of other jPOS components (such as
- * Channels, Muxes, etc.), but it is not by any means an attempt to provide
- * a full implementation.</p>
+ * that eases the implementation of other components (such as
+ * Channels, Muxes, etc.). The Space API is fairly generic, but the
+ * implementations are lacking proper transaction support, and will not
+ * work outside the JVM, without it.</p>
*
- * <p>jPOS's Space is basically a Map where each entry is a LinkedList
+ * <p>DPML's Space is basically a Map where each entry is a LinkedList
* of values that can be used as a BlockingQueue</p>
*
- * <p>One can place entries on a queue by calling Space.out, take them
- * by calling Space.in and read (without taking) by calling Space.rd</p>
- *
* @author Alejandro Revilla
+ * @author Niclas Hedhman
* @version $Id$
* @since 2.0
- * @see LeasedReference
- * @see TransientSpace
- * @see SpaceError
- * @see <a href="http://www.cs.yale.edu/Linda/linda-lang.html";>The Linda
Coordination Language</a>
*
* @metro.service type="org.jpos.space.api.Space" version="1.0"
*/
@@ -76,69 +72,69 @@
public interface Space
{
/**
- * Write a new entry into the Space
- * @param key Entry's key
- * @param value Object value
- */
- void out( Object key, Object value );
-
- /**
- * Write a new entry into the Space, with an timeout value
+ * Write a new entry into the Space.
+ * <p>
+ * The key/value pair will be placed into the Space, and queued (fifo)
with
+ * other entries of the same key.
+ * </p>
+ * <p>
+ * The <code>timeout</code> parameter defines the minimum time that the
+ * key/value pair resides in the Space before the Space automatically
+ * removes it. Entries that are timing out will be reported over the
+ * SpaceListener interface, for interested parties.
+ * </p>
+ *
* @param key Entry's key
* @param value Object value
- * @param timeout timeout value
+ * @param timeout the time that the key/value pair will
+ * exist in the Space before automatically discarded.
+ * If timeout <= 0 then it will reside there forever, and that
+ * is not recommended.
*/
- void out( Object key, Object value, long timeout );
+ void place( Object key, Object value, long timeout );

/**
* Take an entry from the space, waiting forever until one exists.
* @param key Entry's key
* @return value
*/
- Object in( Object key );
-
- /**
- * Read an entry from the space, waiting forever until one exists.
- * @param key Entry's key
- * @return value
- */
- Object rd( Object key );
+ Object take( Object key );

/**
* Take an entry from the space, waiting a limited amount of time
* until one exists.
* @param key Entry's key
- * @param timeout millis to wait
+ * @param timeout milliseconds to wait. If zero, then don't wait at
+ * all, and if less < 0, wait forever.
* @return value or null
*/
- Object in( Object key, long timeout );
-
+ Object take( Object key, long timeout );

/**
* Read an entry from the space, waiting a limited amount of time
* until one exists.
* @param key Entry's key
- * @param timeout millis to wait
+ * @param timeout milliseconds to wait. If zero, then don't wait at
+ * all, and if less < 0, wait forever.
* @return value or null
*/
- Object rd( Object key, long timeout );
+ Object look( Object key, long timeout );

+ /** Adds a SpaceListener.
+ * @param key Entry's key.
+ */
+ void addSpaceListener( SpaceListener listener );

- /**
- * In probe takes an entry from the space if one exists,
- * return null otherwise.
+ /** Removes a SpaceListener.
* @param key Entry's key
- * @return value or null
*/
- Object inp( Object key );
+ void removeSpaceListener( SpaceListener listener );

-
- /**
- * Read probe reads an entry from the space if one exists,
- * return null otherwise.
- * @param key Entry's key
- * @return value or null
+ /** Returns an iterator of the SpaceListeners that has been registered
+ * at the Space.
+ * @return A iterator that is thread-safe and will <strong>not</strong>
+ * throw any <code>java.util.ConcurrentModificationExceptions</code>.
*/
- Object rdp( Object key );
+ Iterator getSpaceListeners();
}


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
Wed Feb 23 19:19:19 2005
@@ -51,19 +51,31 @@

/**
* @author Alejandro Revilla
+ * @author Niclas Hedhman
* @version $Id$
* @since 2.0
- * @see Space
+ * @see org.jpos.space.api.Space
*/
public interface SpaceListener
{
- /**
- * <p>Called by Space implementation whenever an object
- * with the given key is being placed in the Space.</p>
+ /** Notify that an entry has been placed into the Space.
*
* @param key Object's key
* @param value Object's value
*/
- public void notify( Object key, Object value );
-}
+ void placed( Object key, Object value );
+
+ /** Notify that an entry has been taken from the Space.
+ *
+ * @param key Object's key
+ * @param value Object's value
+ */
+ void taken( Object key, Object value );

+ /** Notifies that an entry has been removed from the Space, due
+ * to timeout.
+ * @param key Object's key
+ * @param value Object's value
+ */
+ void timedOut( Object key, Object value );
+}

Added:
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/SpaceStore.java
==============================================================================
--- (empty file)
+++
development/laboratory/planet/components/space/api/src/main/org/jpos/space/api/SpaceStore.java
Wed Feb 23 19:19:19 2005
@@ -0,0 +1,20 @@
+package org.jpos.space.api;
+
+import java.util.Iterator;
+
+public interface SpaceStore
+{
+ /** Adds a key/value pair to the store.
+ */
+ void add( Object key, Object value );
+
+ /** Returns a value associated with the key.
+ * If more than one value is available, the oldest one is returned.
+ */
+ Object get( Object key );
+
+ /** Removes a value associated with the key.
+ * If more than one value is available, the oldest one is removed.
+ */
+ void remove( Object key );
+}
\ No newline at end of file

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

- <project basedir="jdbm" >
- <info>
- <name>jpos-space-jdbm</name>
- <group>jpos/space</group>
- <version>2.0.0</version>
- </info>
- <dependencies>
- <include key="jpos-space-api" />
- <include key="jdbm" />
- <include key="dpml-parameters-api" />
- </dependencies>
- <plugins>
- <include key="dpml-meta-tools" />
- </plugins>
- </project>
-
- <project basedir="persistent" >
- <info>
- <name>jpos-space-persistent</name>
- <group>jpos/space</group>
- <version>2.0.0</version>
- </info>
- <dependencies>
- <include key="jpos-space-api" />
- <include key="dpml-parameters-api" />
- </dependencies>
- <plugins>
- <include key="dpml-meta-tools" />
- </plugins>
- </project>
-
<project basedir="tiny" >
<info>
<name>jpos-space-tiny</name>
@@ -61,50 +30,9 @@
</info>
<dependencies>
<include key="jpos-space-api" />
- </dependencies>
- <plugins>
- <include key="dpml-meta-tools" />
- </plugins>
- </project>
-
- <project basedir="transient" >
- <info>
- <name>jpos-space-transient</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="tspace" >
- <info>
- <name>jpos-space-tspace</name>
- <group>jpos/space</group>
- <version>2.0.0</version>
- </info>
- <dependencies>
- <include key="jpos-space-api" />
- <include key="jpos-space-util" />
- </dependencies>
- <plugins>
- <include key="dpml-meta-tools" />
- </plugins>
- </project>
-
- <project basedir="util" >
- <info>
- <name>jpos-space-util</name>
- <group>jpos/space</group>
- <version>2.0.0</version>
- </info>
- <dependencies>
- <include key="jpos-space-api" />
- <include key="dpml-parameters-api" />
+ <include key="dpml-logging-api" />
+ <include key="dpml-context-api" />
+ <include key="dpml-parameters-api"/>
<include key="dpml-service-api" />
</dependencies>
<plugins>

Added:
development/laboratory/planet/components/space/tiny/src/main/org/jpos/space/tiny/DefaultExpiry.java
==============================================================================
--- (empty file)
+++
development/laboratory/planet/components/space/tiny/src/main/org/jpos/space/tiny/DefaultExpiry.java
Wed Feb 23 19:19:19 2005
@@ -0,0 +1,49 @@
+package org.jpos.space.tiny;
+
+import java.util.Iterator;
+
+import net.dpml.logging.Logger;
+
+import org.jpos.space.api.LeaseCallback;
+import org.jpos.space.api.LeasedReference;
+import org.jpos.space.api.SpaceListener;
+
+/** This class receives notifications from LeasedReference that expiry has
+ * occurred and clean up should take place.
+ */
+class DefaultExpiry
+ implements LeaseCallback
+{
+ private TinySpace m_space;
+ private Logger m_logger;
+
+ DefaultExpiry( TinySpace space, Logger logger )
+ {
+ m_space = space;
+ m_logger = logger;
+ }
+
+ public void expired( LeasedReference lease )
+ {
+ Object ref = lease.getReference();
+ Object value = m_space.look( ref, 0L );
+ Iterator listeners = m_space.getSpaceListeners();
+ fireTimeoutEvents( ref, value, listeners );
+ m_space.take( ref, 0L ); // remove the entry from the space.
+ }
+
+ private void fireTimeoutEvents( Object key, Object value, Iterator
listeners )
+ {
+ while( listeners.hasNext() )
+ {
+ SpaceListener listener = (SpaceListener) listeners.next();
+ try
+ {
+ listener.timedOut( key, value );
+ } catch( Exception e )
+ {
+ m_logger.error( "Exception in SpaceListener.", e );
+ }
+ }
+ }
+}

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
Wed Feb 23 19:19:19 2005
@@ -49,13 +49,21 @@

package org.jpos.space.tiny;

-import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;

import java.io.Serializable;

+import net.dpml.logging.Logger;
+
+import net.dpml.service.ServiceException;
+import net.dpml.service.ServiceManager;
+
import org.jpos.space.api.LeaseCallback;
import org.jpos.space.api.LeasedReference;
import org.jpos.space.api.Space;
+import org.jpos.space.api.SpaceListener;
+import org.jpos.space.api.SpaceStore;

/**
* Tiny Space implementation
@@ -67,163 +75,146 @@
* @metro.component name="tiny-space" lifestyle="singleton"
* @metro.service type="org.jpos.space.api.Space"
*/
-public class TinySpace
+public final class TinySpace
implements Space, Serializable
{
- protected HashMap map = new HashMap();
+ private SpaceStore m_store;
+ private Logger m_logger;
+ private LinkedList m_listeners;

- public TinySpace()
+
+ /**
+ * @metro.logger name="space.tiny"
+ *
+ * @metro.dependency type="org.jpos.space.api.SpaceStore" key="store"
+ */
+ public TinySpace( Logger logger, ServiceManager man )
+ throws ServiceException
{
- super();
+ m_logger = logger;
+ m_store = (SpaceStore) man.lookup( "store" );
}

- public void out( Object key, Object value )
+ public void place( Object key, Object value, long timeout )
{
+ LeaseCallback callback = new DefaultExpiry( this, m_logger );
+ key = new LeasedReference( key, callback, timeout );
+ Iterator listeners = null;
synchronized( this )
{
- Object v = map.get( key );
- if( v == null )
- {
- map.put( key, value );
- }
- else if( v instanceof Data )
- {
- ((Data) v).add( value );
- }
- else
- {
- Data data = new Data();
- data.add( v );
- data.add( value );
- map.put( key, data );
- }
- this.notifyAll();
+ m_store.add( key, value );
+ notifyAll();
}
- }
-
- public void out( Object id, Object value, long timeout )
- {
- LeaseCallback callback = new LeaseCallback()
+ if( listeners != null )
{
- public void expired( LeasedReference ref )
+ while( listeners.hasNext() )
{
- inp( ref.get() ); // remove the entry from the space.
+ SpaceListener listener = (SpaceListener) listeners.next();
+ try
+ {
+ listener.placed( key, value );
+ } catch( Exception e )
+ {
+ m_logger.error( "Exception in SpaceListener.placed()", e
);
+ }
}
- };
-
- LeasedReference ref = new LeasedReference( id, callback, timeout );
- out( id, value );
+ }
}

- public Object rdp( Object key )
+ public Object take( Object key )
{
- synchronized( this )
- {
- Object obj = map.get( key );
- if( obj instanceof Data )
- {
- Data data = (Data) obj;
- obj = data.get( key );
- }
- return obj;
- }
+ return take( key, -1 );
}

- public Object inp( Object key )
+ public Object take( Object key, long timeout )
{
+ Object obj = null;
synchronized( this )
{
- 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 )
- {
- map.remove( key );
- }
- return obj;
+ obj = look( key, timeout );
+ m_store.remove( key );
}
- }
-
- public Object in( Object key )
- {
- synchronized( this )
+ if( listeners != null )
{
- Object obj = inp( key );
- while( obj == null)
+ Iterator listeners = getSpaceListeners();
+ while( listeners.hasNext() )
{
+ SpaceListener listener = (SpaceListener) listeners.next();
try
{
- wait();
- } catch( InterruptedException e )
- {}
- obj = inp( key );
+ listener.taken( key, obj );
+ } catch( Exception e )
+ {
+ m_logger.error( "Exception in SpaceListener.placed()", e
);
+ }
}
- return obj;
}
+ return obj;
}

- public Object in( Object key, long timeout )
+ public Object look( Object key, long timeout )
{
synchronized( this )
{
- Object obj = inp( key );
+ Object obj = probe( key );
+ if( timeout < 0 )
+ return obj;
long now = System.currentTimeMillis();
long end = now + timeout;
- while( obj == null && now < end )
+ if( timeout == 0 )
+ end = Long.MAX_VALUE;
+ while( obj == null && now < end )
{
try
{
wait( end - now );
} catch( InterruptedException e )
{}
- obj = inp( key );
+ obj = probe( key );
now = System.currentTimeMillis();
}
return obj;
}
}

- public Object rd( Object key )
+ public void addSpaceListener( SpaceListener listener )
{
synchronized( this )
{
- Object obj = rdp( key );
- while( obj == null )
- {
- try
- {
- wait();
- } catch( InterruptedException e )
- {}
- obj = rdp( key );
- }
- return obj;
+ LinkedList clone = (LinkedList) m_listeners.clone();
+ clone.add( listener );
+ m_listeners = clone;
}
}

- public Object rd( Object key, long timeout )
+ public void removeSpaceListener( SpaceListener listener )
{
synchronized( this )
{
- Object obj = rdp( key );
- long now = System.currentTimeMillis();
- long end = now + timeout;
- while( obj == null && now < end )
+ if( m_listeners == null )
+ return;
+ if( m_listeners.size() <= 1 )
{
- try
- {
- wait( end - now );
- } catch( InterruptedException e )
- {}
- obj = rdp( key );
- now = System.currentTimeMillis();
+ m_listeners = null;
+ return;
}
- return obj;
+ LinkedList clone = (LinkedList) m_listeners.clone();
+ clone.remove( listener );
+ m_listeners = clone;
}
}
-}

+ public Iterator getSpaceListeners()
+ {
+ synchronized( this )
+ {
+ return m_listeners.iterator();
+ }
+ }
+
+ private Object probe( Object key )
+ {
+ Object obj = m_store.get( key );
+ return obj;
+ }
+}
\ No newline at end of file

Added:
development/laboratory/planet/components/space/tiny/src/main/org/jpos/space/tiny/TransientStore.java
==============================================================================
--- (empty file)
+++
development/laboratory/planet/components/space/tiny/src/main/org/jpos/space/tiny/TransientStore.java
Wed Feb 23 19:19:19 2005
@@ -0,0 +1,65 @@
+
+package org.jpos.space.tiny;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import net.dpml.logging.Logger;
+
+import org.jpos.space.api.LeasedReference;
+import org.jpos.space.api.SpaceListener;
+import org.jpos.space.api.SpaceStore;
+
+/**
+ * @author Niclas Hedhman
+ * @version $Id$
+ * @since 2.0
+ *
+ * @metro.component lifestyle="request"
+ * @metro.service type="org.jpos.space.api.SpaceStore"
+ */
+public final class TransientStore
+ implements SpaceStore
+{
+ private HashMap m_map;
+
+ private Logger m_logger;
+
+ /**
+ * @metro.logger name="transient-store"
+ */
+ public TransientStore( Logger logger )
+ {
+ m_logger = logger;
+ m_map = new HashMap();
+ }
+
+ public void add( Object key, Object value, long timeout )
+ {
+ LinkedList bucket = (LinkedList) m_map.get( key );
+ if( bucket == null )
+ bucket = new LinkedList();
+ bucket.addLast( value );
+ }
+
+ public Object get( Object key )
+ {
+ LinkedList bucket = (LinkedList) m_map.get( key );
+ if( bucket == null )
+ return null;
+
+ Object obj = bucket.getFirst();
+ return obj;
+ }
+
+ public void remove( Object key )
+ {
+ LinkedList bucket = (LinkedList) m_map.get( key );
+ if( bucket == null )
+ return;
+
+ bucket.removeFirst();
+ }
+}
+



  • svn commit: r1884 - in development/laboratory/planet/components/space: . api/src/main/org/jpos/space/api jdbm persistent tiny/src/main/org/jpos/space/tiny transient util/src/main/org/jpos/space/util, niclas, 02/23/2005

Archive powered by MHonArc 2.6.24.

Top of Page