Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question

Usage of space.Snapshot() in FIFO example


I've noticed the following lines of code in GS 6.0 RC1 Advanced JavaSpaces FIFO example:

{code}m_Space.snapshot(m_Template_fifo);{code} {code}m_Space.snapshot(m_Template_None_fifo);{code}

According to the documentation snapshot() is *not *supposed to change the object passed as an arg, it's supposed to return a snapshot of that object. Shouldn't the code look something like:

{code}m_Template_fifo = m_Space.snapshot(m_Template_fifo);{code} {code}m_Template_None_fifo = m_Space.snapshot(m_Template_None_fifo);{code}

Functionally this is probably equivalent, but if the use of snapshot is supposed to speed things up...could this be a bug in the example?

{quote}This thread was imported from the previous forum. For your reference, the original is [available here|http://forum.openspaces.org/thread.jspa?threadID=2115]{quote}

asked 2007-07-20 00:20:05 -0500

updated 2013-08-08 09:52:00 -0500

jaissefsfex gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

Both the first and second snapshot calls are not really required - they are there for debug purpose only - if you will debug the code and step into the code lines, you will see at the space browser the FifoEntry and NonFifoEntry classes right after the snapshot calls with their relevant FIFO mode (see class view) with no actual entries at the space. In general - The first write/read/take/notify operation will introduce the class to the space.

Here is the full story: The snapshot call with GigaSpaces returns in most cases an internal object named EntrySnapshot. This object encapsulates the underlying structure the client is using to communicate with this space (remote/embedded). The snapshot call generates also at the client and at the space (if has not been already created) meta data that describes the entry Class and its space behavior (for example indexed fields info). When using the snapshot call - there are several meta data attributes that are set at the template level such as FIFO mode - you can perform a take in FIFO mode or non FIFO mode via appropriate different template.

Using the returned result from the snapshot call is recommended to speed up the read/take operation. Still , the overhead involved with transforming the original template to EntrySnapshot is minimal.

The : m_Space.snapshot(m_Template_fifo); m_Space.snapshot(m_Template_None_fifo); calls at: \GigaSpacesEE\examples\Advanced\Advanced_JavaSpaces\fifo\src\com\j_spaces\examples\j_spaces_adv\fifo\Fifo.java done in order to introduce the space with the FIFO behavior of the FifoEntry. The first snapshot call will introduce the FifoEntry to the space (space is empty) and will make sure all write operations will "sort" the entries to allow these to be taken out in FIFO mode in case the read/take operation done with template that its FIFO mode set to true. When performing write operations for classes with their in FIFO mode set to true, the entry must have its FIFO mode set to true. The second snapshot will introduce the NonFifoEntry class to the space that does not support read/take FIFO operations.


answered 2007-07-21 23:11:04 -0500

shay hassidim gravatar image
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2007-07-20 00:20:05 -0500

Seen: 120 times

Last updated: Jul 21 '07