Task Execution

This page relates to Scala

A wrapper around the GigaSpaces API provides some sugaring on top of the GigaSpace#execute methods.

Usage

Import the following into scope to use the methods demonstrated below.

import com.gigaspaces.async.AsyncResult import org.openspaces.scala.core.ScalaGigaSpacesImplicits.ScalaEnhancedGigaSpaceWrapper

Some examples:

/** Import GigaSpace implicits into scope */ import com.gigaspaces.async.AsyncResult import org.openspaces.scala.core.ScalaGigaSpacesImplicits._ ... val gsm = admin.getGridServiceManagers.waitForAtLeastOne gsm.deploy(new org.openspaces.admin.space.SpaceDeployment("mySpace")) val Some(gigaSpace) = getGigaSpace("mySpace") case class Data @SpaceClassConstructor() ( @BeanProperty @SpaceId @SpaceProperty(nullValue = "-1") id: Long = -1, @BeanProperty @SpaceRouting @SpaceProperty(nullValue = "-1") routing The mechanism that is in charge of routing the objects into and out of the corresponding partitions. The routing is based on a designated attribute inside the objects that are written to the Space, called the Routing Index.: Long = -1, @BeanProperty data: String = null ) ... gigaSpace write Data(id = 1, routing = 2, data = "some data") gigaSpace write Data(id = 2, routing = 3, data = "some other data") val asyncFuture1 = gigaSpace.execute { gigaSpace: GigaSpace => gigaSpace.readById(classOf[Data], 1l) } println("Execute1 result: " + asyncFuture1.get()) val asyncFuture2 = gigaSpace.execute( { gigaSpace: GigaSpace => gigaSpace.read(Data()).data } /* map */, { results: Seq[AsyncResult[String]] => results.map { _.getResult() }.mkString } /* reduce */ ) println("Map reduce result: " + asyncFuture2.get())