Class SemiSpace

java.lang.Object
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.
  • Field Details

  • Method Details

    • 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:
    • 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:
    • 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:
    • 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:
    • 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)
      Returns:
      true if listener was removed
    • 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:
    • getSerializer

      public SemiSpaceSerializer getSerializer()
      Exposing serializer instance in order to allow outside manipulation of aliases and classloader affiliation.
      Returns:
      The serializer used.