Class MemoryEventStorageSpi
- java.lang.Object
-
- org.apache.ignite.spi.IgniteSpiAdapter
-
- org.apache.ignite.spi.eventstorage.memory.MemoryEventStorageSpi
-
- All Implemented Interfaces:
EventStorageSpi,IgniteSpi
@IgniteSpiMultipleInstancesSupport(true) public class MemoryEventStorageSpi extends IgniteSpiAdapter implements EventStorageSpi
In-memoryEventStorageSpiimplementation. All events are kept in the FIFO queue. If no configuration is provided a default expirationDFLT_EXPIRE_AGE_MSand default countDFLT_EXPIRE_COUNTwill be used.It's recommended not to set huge size and unlimited TTL because this might lead to consuming a lot of memory and result in
OutOfMemoryError. Both event expiration time and maximum queue size could be changed at runtime.Configuration
Mandatory
This SPI has no mandatory configuration parameters.Optional
The following configuration parameters are optional:- Event queue size (see
setExpireCount(long)) - Event time-to-live value (see
setExpireAgeMs(long)) setFilter(org.apache.ignite.lang.IgnitePredicate)- Event filter that should be used for decision to accept event.
Java Example
MemoryEventStorageSpi is used by default and should be explicitly configured only if some SPI configuration parameters need to be overridden. Examples below insert own events queue size value that differs from default 10000.MemoryEventStorageSpi = new MemoryEventStorageSpi(); // Init own events size. spi.setExpireCount(2000); IgniteConfiguration cfg = new IgniteConfiguration(); // Override default event storage SPI. cfg.setEventStorageSpi(spi); // Starts grid. G.start(cfg);
Spring Example
MemoryEventStorageSpi can be configured from Spring XML configuration file:<bean id="grid.custom.cfg" class="org.apache.ignite.configuration.IgniteConfiguration" singleton="true"> ... <property name="eventStorageSpi"> <bean class="org.apache.ignite.spi.eventStorage.memory.MemoryEventStorageSpi"> <property name="expireCount" value="2000"/> </bean> </property> ... </bean>
For information about Spring framework visit www.springframework.org- See Also:
EventStorageSpi
-
-
Field Summary
Fields Modifier and Type Field Description static longDFLT_EXPIRE_AGE_MSDefault event time to live value in milliseconds (value isLong.MAX_VALUE).static intDFLT_EXPIRE_COUNTDefault expire count (value is10000).-
Fields inherited from class org.apache.ignite.spi.IgniteSpiAdapter
ignite, igniteInstanceName
-
-
Constructor Summary
Constructors Constructor Description MemoryEventStorageSpi()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearAll()Removes all events from the event queue.longgetExpireAgeMs()longgetExpireCount()IgnitePredicate<Event>getFilter()Gets filter for events to be recorded.longgetQueueSize()Gets current queue size of the event queue.<T extends Event>
Collection<T>localEvents(IgnitePredicate<T> p)Queries locally-stored events only.voidrecord(Event evt)Records single event.MemoryEventStorageSpisetExpireAgeMs(long expireAgeMs)Sets events expiration time.MemoryEventStorageSpisetExpireCount(long expireCnt)Sets events queue size.MemoryEventStorageSpisetFilter(IgnitePredicate<Event> filter)Sets filter for events to be recorded.MemoryEventStorageSpisetName(String name)Sets SPI name.voidspiStart(String igniteInstanceName)This method is called to start SPI.voidspiStop()This method is called to stop SPI.StringtoString()-
Methods inherited from class org.apache.ignite.spi.IgniteSpiAdapter
addTimeoutObject, assertParameter, checkConfigurationConsistency0, clientFailureDetectionTimeout, configInfo, createSpiAttributeName, failureDetectionTimeout, failureDetectionTimeoutEnabled, failureDetectionTimeoutEnabled, getConsistentAttributeNames, getExceptionRegistry, getLocalNode, getName, getNodeAttributes, getSpiContext, ignite, initFailureDetectionTimeout, injectables, injectResources, isNodeStopping, onBeforeStart, onClientDisconnected, onClientReconnected, onContextDestroyed, onContextDestroyed0, onContextInitialized, onContextInitialized0, registerMBean, removeTimeoutObject, started, startInfo, startStopwatch, stopInfo, unregisterMBean
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.ignite.spi.IgniteSpi
getName, getNodeAttributes, onClientDisconnected, onClientReconnected, onContextDestroyed, onContextInitialized
-
-
-
-
Field Detail
-
DFLT_EXPIRE_AGE_MS
public static final long DFLT_EXPIRE_AGE_MS
Default event time to live value in milliseconds (value isLong.MAX_VALUE).- See Also:
- Constant Field Values
-
DFLT_EXPIRE_COUNT
public static final int DFLT_EXPIRE_COUNT
Default expire count (value is10000).- See Also:
- Constant Field Values
-
-
Method Detail
-
getFilter
public IgnitePredicate<Event> getFilter()
Gets filter for events to be recorded.- Returns:
- Filter to use.
-
setFilter
@IgniteSpiConfiguration(optional=true) public MemoryEventStorageSpi setFilter(IgnitePredicate<Event> filter)
Sets filter for events to be recorded.- Parameters:
filter- Filter to use.- Returns:
thisfor chaining.
-
spiStart
public void spiStart(String igniteInstanceName) throws IgniteSpiException
This method is called to start SPI. After this method returns successfully kernel assumes that SPI is fully operational.- Specified by:
spiStartin interfaceIgniteSpi- Parameters:
igniteInstanceName- Name of Ignite instance this SPI is being started for (nullfor default Ignite instance).- Throws:
IgniteSpiException- Throws in case of any error during SPI start.
-
spiStop
public void spiStop() throws IgniteSpiExceptionThis method is called to stop SPI. After this method returns kernel assumes that this SPI is finished and all resources acquired by it are released.Note that this method can be called at any point including during recovery of failed start. It should make no assumptions on what state SPI will be in when this method is called.
- Specified by:
spiStopin interfaceIgniteSpi- Throws:
IgniteSpiException- Thrown in case of any error during SPI stop.
-
getExpireAgeMs
public long getExpireAgeMs()
- Returns:
- Event time-to-live.
-
setExpireAgeMs
@IgniteSpiConfiguration(optional=true) public MemoryEventStorageSpi setExpireAgeMs(long expireAgeMs)
Sets events expiration time. All events that exceed this value will be removed from the queue when next event comes.If not provided, default value is
DFLT_EXPIRE_AGE_MS.- Parameters:
expireAgeMs- Expiration time in milliseconds.- Returns:
thisfor chaining.
-
getExpireCount
public long getExpireCount()
- Returns:
- Maximum event queue size.
-
setExpireCount
@IgniteSpiConfiguration(optional=true) public MemoryEventStorageSpi setExpireCount(long expireCnt)
Sets events queue size. Events will be filtered out when new request comes.If not provided, default value
DFLT_EXPIRE_COUNTwill be used.- Parameters:
expireCnt- Maximum queue size.- Returns:
thisfor chaining.
-
getQueueSize
public long getQueueSize()
Gets current queue size of the event queue.- Returns:
- Current queue size of the event queue.
-
clearAll
public void clearAll()
Removes all events from the event queue.
-
localEvents
public <T extends Event> Collection<T> localEvents(IgnitePredicate<T> p)
Queries locally-stored events only. Events could be filtered out by given predicate filter.- Specified by:
localEventsin interfaceEventStorageSpi- Type Parameters:
T- Type of events.- Parameters:
p- Event predicate filter.- Returns:
- Collection of events.
-
record
public void record(Event evt) throws IgniteSpiException
Records single event.- Specified by:
recordin interfaceEventStorageSpi- Parameters:
evt- Event that should be recorded.- Throws:
IgniteSpiException- If event recording failed for any reason.
-
setName
public MemoryEventStorageSpi setName(String name)
Sets SPI name.- Overrides:
setNamein classIgniteSpiAdapter- Parameters:
name- SPI name.- Returns:
thisfor chaining.
-
-