Summary: How to get entries in the same order in which they were written to the space.
OverviewSupporting FIFO (First In, First Out) behavior for Entries is a critical requirement when building messaging systems or implementing master-worker patterns. Users should be able to get Entries in the same order in which they were written. GigaSpaces supports both non-ordered Entries and FIFO ordered Entries when performing space operations. Enabling FIFOThe default space behavior is non-FIFO. The reason is that FIFO support comes at a cost: the space needs to organize and maintain the entries internally in a more complex fashion to support FIFO queries, thus slowing down concurrent write operations. To enable FIFO operations users need to turn on FIFO support for classes which will participate in such operations. If a FIFO operation is performed on an entry whose class does not support FIFO, an exception will be thrown. Setting FIFO support for a class can be done via the fifoSupport attribute on the @SpaceClass annotation: @SpaceClass(fifoSupport=FifoSupport.OPERATION)
public class Person
{
...
}
or when using gs.xml via the fifo-support attribute on the class element: <gigaspaces-mapping> <class name="com.gigaspaces.examples.Person" fifo-support="operation"> ... </class> </gigaspaces-mapping> The FifoSupport modes are:
Space Operations with FIFOQuery Operations with FIFOTo execute read/take operations with FIFO, use the ReadModifiers.FIFO modifier. For example: Person result = space.take(new Person(), timeout, ReadModifiers.FIFO);
If class Person is not set to support FIFO, an exception will be thrown. Read with FIFOReading without FIFO looks for a matching entry in the space and returns the first one found (if any), but not necessarily the one that was written first. Reading with FIFO guarantees that if there is more than one matching entry, the one that was written first will be returned (the write time is determined based on internal sequencing that ensures that a client receives Entries in FIFO order). Executing read with FIFO again with the same template will return the same result, assuming the entry hasn't been changed or deleted. Take with FIFOSimilar to read, executing take with FIFO guarantees that if there is more than one matching entry, the one that was written first will be taken. Executing take with FIFO again with the same template will return the next matching entry by order, and so on. A take operation using FIFO might be critical when building a Point-to-Point (P2P) messaging system which needs to have message senders and receivers, where the receivers must get the sent messages in the exact order these have been sent by the senders. Batch operations with FIFOWhen using the readMultiple or takeMultiple with FIFO, the returned array will be ordered according to the time the entries were written to the space. Transactions and FIFOFIFO Space operations can be performed using transactions. When transaction is rolled back, data is written back to the top of the FIFO queue and will be made available for next operation. For e.g., if a transactional polling container consumes data and throws an exception which results into a rollback of transaction, same data will be processed by the polling container in the next attempt. Events with FIFOWhen registering for events, use EventSessionConfig.setFifo(true) to instruct the space that events should be sent to the client in FIFO order. For example: // Create an event session configuration with FIFO: EventSessionConfig sessionConfig = new EventSessionConfig(); sessionConfig.setFifo(true); // Create a data event session using the configuration: EventSessionFactory sessionFactory = EventSessionFactory.getFactory(space.getSpace()); DataEventSession session = sessionFactory.newDataEventSession(sessionConfig, null); // Subscribe to an event: session.addListener(new Person(), listener);
FIFO GroupingThe FIFO Grouping designed to allow efficient processing of events with partial ordering constraints. Instead of maintaining a FIFO queue per class type, it lets you have a higher level of granularity by having FIFO queue maintained according to a specific value of a specific property. For more details see FIFO Grouping. Persistent Space in FIFO ModeWhen a space includes FIFO-enabled classes and is defined as persistent, the persistent store (RDBMS) includes the relevant information that ensures FIFO. This might impact the performance, since an additional index is created for each table storing the Entry Class instances. ConsiderationsFIFO ordering is maintained per class per space. Therefore the following limitations should be observed:
|
![]() |
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence |