Class SemiSpace
java.lang.Object
org.semispace.SemiSpace
- All Implemented Interfaces:
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
Nested ClassesModifier and TypeClassDescriptionprotected classNeed to wrap write in own thread in order to make terracotta pick it up. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancancelElement(Long id, boolean isTake, String className) protected booleancancelListener(ListenerHolder holder) Long[]findOrWaitLeaseForTemplate(Map<String, String> templateSet, long timeout, boolean isToTakeTheLease) Public for the benefit of the webservices interface.getAdmin()Return admin elementExposing serializer instance in order to allow outside manipulation of aliases and classloader affiliation.protected SemiSpaceStatisticsFor the benefit of junit test(s) - defensively copied statisticsvoidharvest()Harvest old elements from diverse listeners.notify(Object tmpl, SemiEventListener listener, long duration) None of the parameters can be nullnotify(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.protected voidnotifyListeners(DistributedEvent distributedEvent) Distributed notification method.intNeed present statistics here due to spring JMX configuration.intNeed present statistics here due to spring JMX configuration.intNeed present statistics here due to spring JMX configuration.intNeed present statistics here due to spring JMX configuration.intNeed present statistics here due to spring JMX configuration.intNeed present statistics here due to spring JMX configuration.intReturn the number of elements in the space.intNeed present statistics here due to spring JMX configuration.intNeed present statistics here due to spring JMX configuration.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> Tread(T tmpl, long timeout) Read an object from the space, which has matching fields (or getters) with the templatereadHolderById(long hId) Used for retrieving element with basis in id<T> TreadIfExists(T tmpl) Same as read, with duration 0protected booleanrenewElement(Holder holder, long duration) protected booleanrenewListener(ListenerHolder holder, long duration) retrievePropertiesFromObject(Object examine) Protected for the benefit of junit test(s)static SemiSpaceInterfacevoidsetAdmin(SemiSpaceAdminInterface admin) Preparing for future injection of admin.<T> Ttake(T tmpl, long timeout) Same as read, except that the object is removed from the space.<T> TtakeIfExists(T tmpl) Same as take, with a duration of 0Notice that the lease time is the time in milliseconds the element is wants to live, not the system time plus the time to live.This method is public for the benefit of the web services, which shortcuts the writing process.
-
Field Details
-
ONE_DAY
public static final long ONE_DAY- See Also:
-
-
Method Details
-
retrieveSpace
- Returns:
- Return the space
-
notify
None of the parameters can be null- Specified by:
notifyin interfaceSemiSpaceInterface- Parameters:
tmpl- Template to be matched.listener- Listener to be notified when object with a matching template is foundduration- 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
Distributed notification method. -
write
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:
writein interfaceSemiSpaceInterface- Parameters:
entry- Object to be written into the spaceleaseTimeMs- Life time in milliseconds of the written object- Returns:
- Either the resulting lease or null if an error
-
writeToElements
-
read
public <T> T read(T tmpl, long timeout) Description copied from interface:SemiSpaceInterfaceRead an object from the space, which has matching fields (or getters) with the template- Specified by:
readin interfaceSemiSpaceInterface- 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:SemiSpaceInterfaceSame as read, with duration 0- Specified by:
readIfExistsin interfaceSemiSpaceInterface- See Also:
-
readHolderById
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:SemiSpaceInterfaceSame as read, except that the object is removed from the space.- Specified by:
takein interfaceSemiSpaceInterface- See Also:
-
takeIfExists
public <T> T takeIfExists(T tmpl) Description copied from interface:SemiSpaceInterfaceSame as take, with a duration of 0- Specified by:
takeIfExistsin interfaceSemiSpaceInterface- See Also:
-
processTemplate
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
-
setAdmin
Preparing for future injection of admin. Note that you must call initialization yourself after setting the objectThis is tested in junit test (and under terracotta).
-
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
For the benefit of junit test(s) - defensively copied statistics -
cancelListener
- Returns:
- true if listener was removed
-
renewListener
-
cancelElement
-
renewElement
- Returns:
- true if the object actually was renewed. (I.e. it exists and got a new timeout.)
-
findAllHolderIds
- See Also:
-
getSerializer
Exposing serializer instance in order to allow outside manipulation of aliases and classloader affiliation.- Returns:
- The serializer used.
-