GridGain™ 3.6.0e
Enterprise Edition

org.gridgain.grid.spi.eventstorage.memory
Class GridMemoryEventStorageSpi

java.lang.Object
  extended by org.gridgain.grid.spi.GridSpiAdapter
      extended by org.gridgain.grid.spi.eventstorage.memory.GridMemoryEventStorageSpi
All Implemented Interfaces:
GridEventStorageSpi, GridMemoryEventStorageSpiMBean, GridSpi, GridSpiJsonConfigurable, GridSpiManagementMBean

@GridSpiInfo(author="GridGain Systems",
             url="www.gridgain.com",
             email="support@gridgain.com",
             version="3.6.0e.13012012")
@GridSpiMultipleInstancesSupport(value=true)
public class GridMemoryEventStorageSpi
extends GridSpiAdapter
implements GridEventStorageSpi, GridMemoryEventStorageSpiMBean

In-memory GridEventStorageSpi implementation. All events are kept in the FIFO queue. If no configuration is provided a default expiration GridMemoryEventStorageSpi.DFLT_EXPIRE_AGE_MS and default count GridMemoryEventStorageSpi.DFLT_EXPIRE_COUNT will 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:

Java Example

GridMemoryEventStorageSpi 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.
 GridMemoryEventStorageSpi = new GridMemoryEventStorageSpi();

 // Init own events size.
 spi.setExpireCount(2000);

 GridJexlPredicate filter = new GridJexlPredicate("event.taskName == 'task'", "event");

 // Add filter.
 spi.setFilter(filter);

 GridConfigurationAdapter cfg = new GridConfigurationAdapter();

 // Override default event storage SPI.
 cfg.setEventStorageSpi(spi);

 // Starts grid.
 G.start(cfg);
 

Spring Example

GridMemoryEventStorageSpi can be configured from Spring XML configuration file:
 <bean id="grid.custom.cfg" class="org.gridgain.grid.GridConfigurationAdapter" singleton="true">
         ...
         <property name="discoverySpi">
             <bean class="org.gridgain.grid.spi.eventStorage.memory.GridMemoryEventStorageSpi">
                 <property name="expireCount" value="2000"/>
                 <property name="filter">
                     <bean class="org.gridgain.grid.lang.GridJexlPredicate">
                         <property name="expression">
                             <value>
                                 <![CDATA[elem.taskName == 'task']]>
                             </value>
                         </property>
                     </bean>
                 </property>
             </bean>
         </property>
         ...
 </bean>
 


For information about Spring framework visit www.springframework.org

Wiki & Forum:


Wiki
Forum

See Also:
GridEventStorageSpi
 

Field Summary
static long DFLT_EXPIRE_AGE_MS
          Default event time to live value in milliseconds (value is Long.MAX_VALUE).
static int DFLT_EXPIRE_COUNT
          Default expire count (value is 10000).
 
Constructor Summary
GridMemoryEventStorageSpi()
           
 
Method Summary
 void clearAll()
          Removes all events from the event queue.
 long getExpireAgeMs()
          Gets event time-to-live value.
 long getExpireCount()
          Gets maximum event queue size.
 GridPredicate<GridEvent> getFilter()
          Gets filter for events to be recorded.
 long getQueueSize()
          Gets current queue size of the event queue.
 Collection<GridEvent> localEvents(GridPredicate<? super GridEvent>... p)
          Queries locally-stored events only.
 void record(GridEvent evt)
          Records single event.
 void setExpireAgeMs(long expireAgeMs)
          Sets events expiration time.
 void setExpireCount(long expireCnt)
          Sets events queue size.
 void setFilter(GridPredicate<GridEvent> filter)
          Sets filter for events to be recorded.
 void spiStart(String gridName)
          This method is called to start SPI.
 void spiStop()
          This method is called to stop SPI.
 String toString()
          
 
Methods inherited from class org.gridgain.grid.spi.GridSpiAdapter
assertParameter, checkConfigurationConsistency, configInfo, createSpiAttributeName, getAuthor, getConsistentAttributeNames, getGridGainHome, getLocalNodeId, getName, getNodeAttributes, getSpiContext, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, getVendorEmail, getVendorUrl, getVersion, injectables, onContextDestroyed, onContextInitialized, registerMBean, setJson, setName, 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.gridgain.grid.spi.GridSpi
getName, getNodeAttributes, onContextDestroyed, onContextInitialized
 
Methods inherited from interface org.gridgain.grid.spi.GridSpiJsonConfigurable
setJson
 
Methods inherited from interface org.gridgain.grid.spi.GridSpiManagementMBean
getAuthor, getGridGainHome, getLocalNodeId, getName, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, getVendorEmail, getVendorUrl, getVersion
 

Field Detail

DFLT_EXPIRE_AGE_MS

public static final long DFLT_EXPIRE_AGE_MS
Default event time to live value in milliseconds (value is Long.MAX_VALUE).

See Also:
Constant Field Values

DFLT_EXPIRE_COUNT

public static final int DFLT_EXPIRE_COUNT
Default expire count (value is 10000).

See Also:
Constant Field Values
Constructor Detail

GridMemoryEventStorageSpi

public GridMemoryEventStorageSpi()
Method Detail

getFilter

public GridPredicate<GridEvent> getFilter()
Gets filter for events to be recorded.

Returns:
Filter to use.

setFilter

@GridSpiConfiguration(optional=true)
public void setFilter(GridPredicate<GridEvent> filter)
Sets filter for events to be recorded.

Parameters:
filter - Filter to use.
See Also:
GridJexlPredicate

spiStart

public void spiStart(String gridName)
              throws GridSpiException
This method is called to start SPI. After this method returns successfully kernel assumes that SPI is fully operational.

Specified by:
spiStart in interface GridSpi
Throws:
GridSpiException - Throws in case of any error during SPI start.
Parameters:
gridName - Name of grid instance this SPI is being started for (null for default grid).

spiStop

public void spiStop()
             throws GridSpiException
This 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:
spiStop in interface GridSpi
Throws:
GridSpiException - Thrown in case of any error during SPI stop.

setExpireAgeMs

@GridSpiConfiguration(optional=true)
public void 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 GridMemoryEventStorageSpi.DFLT_EXPIRE_AGE_MS.

Parameters:
expireAgeMs - Expiration time in milliseconds.

setExpireCount

@GridSpiConfiguration(optional=true)
public void setExpireCount(long expireCnt)
Sets events queue size. Events will be filtered out when new request comes.

If not provided, default value GridMemoryEventStorageSpi.DFLT_EXPIRE_COUNT will be used.

Parameters:
expireCnt - Maximum queue size.

getExpireAgeMs

public long getExpireAgeMs()
Gets event time-to-live value. Implementation must guarantee that event would not be accessible if its lifetime exceeds this value.

Specified by:
getExpireAgeMs in interface GridMemoryEventStorageSpiMBean
Returns:
Event time-to-live.

getExpireCount

public long getExpireCount()
Gets maximum event queue size. New incoming events will oust oldest ones if queue size exceeds this limit.

Specified by:
getExpireCount in interface GridMemoryEventStorageSpiMBean
Returns:
Maximum event queue size.

getQueueSize

public long getQueueSize()
Gets current queue size of the event queue.

Specified by:
getQueueSize in interface GridMemoryEventStorageSpiMBean
Returns:
Current queue size of the event queue.

clearAll

public void clearAll()
Removes all events from the event queue.

Specified by:
clearAll in interface GridMemoryEventStorageSpiMBean

localEvents

public Collection<GridEvent> localEvents(GridPredicate<? super GridEvent>... p)
Queries locally-stored events only. Events could be filtered out by given predicate filters.

Specified by:
localEvents in interface GridEventStorageSpi
Parameters:
p - Event predicate filters. If no filters are provided - all local events will be returned.
Returns:
Collection of events.

record

public void record(GridEvent evt)
            throws GridSpiException
Records single event.

Specified by:
record in interface GridEventStorageSpi
Throws:
GridSpiException - If event recording failed for any reason.
Parameters:
evt - Event that should be recorded.

toString

public String toString()

Overrides:
toString in class Object

GridGain™ 3.6.0e
Enterprise Edition

GridGain - Real Time Big Data
Enterprise Edition, ver. 3.6.0e.13012012
2012 Copyright © GridGain Systems
Follow us:   Follow GridGain on Github Follow GridGain on Facebook Join GridGain User Group Follow GridGain on Twitter Follow GridGain on YouTube