org.semispace
Class SemiSpace

java.lang.Object
  extended by org.semispace.SemiSpace
All Implemented Interfaces:
SemiSpaceInterface

public class SemiSpace
extends Object
implements SemiSpaceInterface

A tuple space implementation which can be distributed with terracotta. This is the main class from which the SemiSpace interface is obtained.


Nested Class Summary
protected  class SemiSpace.WrappedInternalWriter
          Need to wrap write in own thread in order to make terracotta pick it up.
 
Field Summary
static long ONE_DAY
           
 
Method Summary
protected  boolean cancelElement(Long id, boolean isTake, String className)
           
protected  boolean cancelListener(ListenerHolder holder)
           
 Long[] findAllHolderIds()
           
 String findOrWaitLeaseForTemplate(Map<String,String> templateSet, long timeout, boolean isToTakeTheLease)
          Public for the benefit of the webservices interface.
 SemiSpaceAdminInterface getAdmin()
          Return admin element
protected  SemiSpaceStatistics getStatistics()
          For the benefit of junit test(s) - defensively copied statistics
 com.thoughtworks.xstream.XStream getXStream()
          Exposing xstream instance in order to allow outside manipulation of aliases and classloader affiliation.
 void harvest()
          Harvest old elements from diverse listeners.
 SemiEventRegistration notify(Map<String,String> searchProps, SemiEventListener listener, long duration)
          Basically the same as the notify method demanded by the interface, except that it accepts search properties directly.
 SemiEventRegistration notify(Object tmpl, SemiEventListener listener, long duration)
          None of the parameters can be null
protected  void notifyListeners(DistributedEvent distributedEvent)
          Distributed notification method.
 int numberOfBlockingRead()
          Need present statistics here due to spring JMX configuration.
 int numberOfBlockingTake()
          Need present statistics here due to spring JMX configuration.
 int numberOfMissedRead()
          Need present statistics here due to spring JMX configuration.
 int numberOfMissedTake()
          Need present statistics here due to spring JMX configuration.
 int numberOfNumberOfListeners()
          Need present statistics here due to spring JMX configuration.
 int numberOfRead()
          Need present statistics here due to spring JMX configuration.
 int numberOfSpaceElements()
          Return the number of elements in the space.
 int numberOfTake()
          Need present statistics here due to spring JMX configuration.
 int numberOfWrite()
          Need present statistics here due to spring JMX configuration.
 Object processTemplate(Object template)
          Create a pre-processed template object that can be used to reduce the amount of work required to match templates during a take.
<T> T
read(T tmpl, long timeout)
          Read an object from the space, which has matching fields (or getters) with the template
 Holder readHolderById(long hId)
          Used for retrieving element with basis in id
<T> T
readIfExists(T tmpl)
          Same as read, with duration 0
protected  boolean renewElement(Holder holder, long duration)
           
protected  boolean renewListener(ListenerHolder holder, long duration)
           
protected  Map<String,String> retrievePropertiesFromObject(Object examine)
          Protected for the benefit of junit test(s)
static SemiSpaceInterface retrieveSpace()
           
 void setAdmin(SemiSpaceAdminInterface admin)
          Preparing for future injection of admin.
<T> T
take(T tmpl, long timeout)
          Same as read, except that the object is removed from the space.
<T> T
takeIfExists(T tmpl)
          Same as take, with a duration of 0
 SemiLease write(Object entry, long leaseTimeMs)
          Notice that the lease time is the time in milliseconds the element is wants to live, not the system time plus the time to live.
 SemiLease writeToElements(String entryClassName, long leaseTimeMs, String xml, Map<String,String> searchMap)
          This method is public for the benefit of the web services, which shortcuts the writing process.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ONE_DAY

public static final long ONE_DAY
See Also:
Constant Field Values
Method Detail

retrieveSpace

public static SemiSpaceInterface retrieveSpace()
Returns:
Return the space

notify

public SemiEventRegistration notify(Object tmpl,
                                    SemiEventListener listener,
                                    long duration)
None of the parameters can be null

Specified by:
notify in interface SemiSpaceInterface
Parameters:
tmpl - Template to be matched.
listener - Listener to be notified when object with a matching template is found
duration - How long this particular listener is valid.
Returns:
Returning null if something went wrong or was wrong, a registration object otherwise.
See Also:
SemiSpaceInterface.notify(Object, SemiEventListener, long)

notify

public SemiEventRegistration notify(Map<String,String> searchProps,
                                    SemiEventListener listener,
                                    long duration)
Basically the same as the notify method demanded by the interface, except that it accepts search properties directly. Used from the web services class. None of the parameters can be null

Returns:
Returning null if something went wrong or was wrong, a registration object otherwise.

notifyListeners

protected void notifyListeners(DistributedEvent distributedEvent)
Distributed notification method.


write

public SemiLease write(Object entry,
                       long leaseTimeMs)
Notice that the lease time is the time in milliseconds the element is wants to live, not the system time plus the time to live.

Specified by:
write in interface SemiSpaceInterface
Parameters:
entry - Object to be written into the space
leaseTimeMs - Life time in milliseconds of the written object
Returns:
Either the resulting lease or null if an error

writeToElements

public SemiLease writeToElements(String entryClassName,
                                 long leaseTimeMs,
                                 String xml,
                                 Map<String,String> searchMap)
This method is public for the benefit of the web services, which shortcuts the writing process. All values are expected to be non-null and valid upon entry.


read

public <T> T read(T tmpl,
                  long timeout)
Description copied from interface: SemiSpaceInterface
Read an object from the space, which has matching fields (or getters) with the template

Specified by:
read in interface SemiSpaceInterface
Parameters:
tmpl - Object of exactly the same type as what is wanted as return value, with zero or more none-null fields or getters.
timeout - How long you are willing to wait for an answer / match.
Returns:
An object when matches the template, or null of none are found.

findOrWaitLeaseForTemplate

public String findOrWaitLeaseForTemplate(Map<String,String> templateSet,
                                         long timeout,
                                         boolean isToTakeTheLease)
Public for the benefit of the webservices interface.

Parameters:
timeout - how long to wait in milliseconds. If timeout is zero or negative, query once.
isToTakeTheLease - true if the element shall be marked as taken.
Returns:
XML version of data, if found, or null

readIfExists

public <T> T readIfExists(T tmpl)
Description copied from interface: SemiSpaceInterface
Same as read, with duration 0

Specified by:
readIfExists in interface SemiSpaceInterface
See Also:
SemiSpaceInterface.read(Object, long)

readHolderById

public Holder readHolderById(long hId)
Used for retrieving element with basis in id

Returns:
Element with given holder id, or null if not found (or expired

take

public <T> T take(T tmpl,
                  long timeout)
Description copied from interface: SemiSpaceInterface
Same as read, except that the object is removed from the space.

Specified by:
take in interface SemiSpaceInterface
See Also:
SemiSpaceInterface.read(Object, long)

takeIfExists

public <T> T takeIfExists(T tmpl)
Description copied from interface: SemiSpaceInterface
Same as take, with a duration of 0

Specified by:
takeIfExists in interface SemiSpaceInterface
See Also:
SemiSpaceInterface.take(Object, long), SemiSpaceInterface.read(Object, long)

processTemplate

public Object processTemplate(Object template)
Create a pre-processed template object that can be used to reduce the amount of work required to match templates during a take. Applications that take a lot of objects using the same template instance, a noticeable performance improvement can be had.

Parameters:
template - The object to preprocess
Returns:
A pre-processed object that can be passed to read/take

retrievePropertiesFromObject

protected Map<String,String> retrievePropertiesFromObject(Object examine)
Protected for the benefit of junit test(s)

Parameters:
examine - Non-null object

setAdmin

public void setAdmin(SemiSpaceAdminInterface admin)
Preparing for future injection of admin. Note that you must call initialization yourself after setting the object

This is tested in junit test (and under terracotta).


getAdmin

public SemiSpaceAdminInterface getAdmin()
Return admin element


harvest

public void harvest()
Harvest old elements from diverse listeners. Used from the periodic harvester and junit tests.


numberOfSpaceElements

public int numberOfSpaceElements()
Return the number of elements in the space. Notice that this may report old elements that have not been purged yet.


numberOfBlockingRead

public int numberOfBlockingRead()
Need present statistics here due to spring JMX configuration.


numberOfBlockingTake

public int numberOfBlockingTake()
Need present statistics here due to spring JMX configuration.


numberOfMissedRead

public int numberOfMissedRead()
Need present statistics here due to spring JMX configuration.


numberOfMissedTake

public int numberOfMissedTake()
Need present statistics here due to spring JMX configuration.


numberOfNumberOfListeners

public int numberOfNumberOfListeners()
Need present statistics here due to spring JMX configuration.


numberOfRead

public int numberOfRead()
Need present statistics here due to spring JMX configuration.


numberOfTake

public int numberOfTake()
Need present statistics here due to spring JMX configuration.


numberOfWrite

public int numberOfWrite()
Need present statistics here due to spring JMX configuration.


getStatistics

protected SemiSpaceStatistics getStatistics()
For the benefit of junit test(s) - defensively copied statistics


cancelListener

protected boolean cancelListener(ListenerHolder holder)

renewListener

protected boolean renewListener(ListenerHolder holder,
                                long duration)

cancelElement

protected boolean cancelElement(Long id,
                                boolean isTake,
                                String className)
Parameters:
isTake - true if reason for the cancellation is a take.

renewElement

protected boolean renewElement(Holder holder,
                               long duration)
Returns:
true if the object actually was renewed. (I.e. it exists and got a new timeout.)

findAllHolderIds

public Long[] findAllHolderIds()
See Also:
HolderContainer.findAllHolderIds()

getXStream

public com.thoughtworks.xstream.XStream getXStream()
Exposing xstream instance in order to allow outside manipulation of aliases and classloader affiliation.

Returns:
The xstream instance used.


Copyright © 2008-2012. All Rights Reserved.