Skip to content

Application Callbacks

tbarker9comcast edited this page Apr 21, 2014 · 3 revisions

#Application Callback Methods These methods are used by the Sirius library to provide a request handler to Sirius so that the application can service the requests. The object, to accept and process these requests, must extend or mix-in the Scala trait RequestHandler, in Java the class would implement it as an interface.

There are three methods that need to be implemented. They are handlePut, handleGet, and handleDelete. These three methods will be used by Sirius in the processing of requests that are made to the corresponding enqueue methods of the Sirius library.

##handleGet handleGet takes one parameter. This parameter is a String and is the value of the key to be retrieved. The method returns a SiriusResult object that contains the value associated with the key. The handleGet method is concidered to be mostly vestigial at this time as the enqueueGet method just calls handleGet which would in turn call the application method to retrieve the data. The data would then be passed back along the chain and returned back to the application. If the application directly retrieves the data from the datastore, the application will be much more efficient. Most of the applications using Sirius would be able to implement handleGet as a NOOP method. One of the reasons to concider using the application-enqueueGet-handleGet-application chain is to avoid threading issues, as Sirius will make the calls to handleGet sequentially.

##handlePut handlePut takes two parameters, one key and one value. The key is a String and the value is an array of bytes representing the data value. The conversion of the object to and from the byte array is application specific and the details of the conversion are left up to the designer of the application. The application should be aware of the underlying method to perform the conversion. If the developer is using a particular implementation of the conversion and a later update changes how the conversion process is completed, the application will no longer be able to convert the data from Sirius into its objects in a meaningful way. The method will need to return a SiriusResult object indicating the result of the put. Typically the method will return an empty result on success, but this is up to the application. The Sirius library does not do anything with the returned value at the moment.

##handleDelete Like handleGet, handleDelete takes one parameter which is a String for the key and returns a SiriusResult object. The handleDelete method will be invoked to remove a key/value pair from the datastore. Like the handlePut method the returned SiriusObject should be SiriusResult.none() on a sucessful deletion from the datastore.