Skip to content

Getting started with Sirius

Maulan Byron edited this page Feb 23, 2014 · 15 revisions

======

This tutorial used code snippets from a simple application that uses the Sirius library to provide a simple distribute and consistent data store. We will first walk through the steps to write a Sirius powered application.

When developing with Sirius there are four blocks that you need. A Sirius representation, some class that configures what will be your Sirius Implementation. A RequestHandler class that extends the Sirius RequestHandle trait/interface, overriding the handleGet, handlePut and handleDelete method. A controller class that determines when and what data gets written to or read from Sirius. And finally a implementation of some in memory data store.

Configuring Sirius: Here we configure what the cluster will look like, how many, how often they message each other etc. java public SiriusImpl initializeSirius(RequestHandler requestHandler, String siriusLog, String clusterConfig, int siriusPort){

Implementing a RequestHandler: Here we are only interested in the handlePut and handleGet. When you issue an enqueuePut the underlying Sirius library also fires the corresponding RequestHandler’s handlePut method. when you issue an enqueueGet the Sirius library then fires the corresponding RequestHandler’s handleGet method.

 public SiriusResult handleGet(String key)
 	map.get(key)
 public SiriusResult handlePut(String key, byte[] data)
 	map.put(key,data)
 public SiriusResult handleDelete(String key)
 	map.remove(key)



 public SiriusResult handlePut(String key, byte[] body){
     logger.trace("Handling a PUT {}-size:{}", key, body);

     Container container = Container.deserialize(body);
     InMemoryDataStore.IMS.createContainer(container);
     if(container != null){
        return SiriusResult.some(OK);
     }
     else{
         return SiriusResult.none();
     }

 }

 public SiriusResult handleDelete(String key){......}

Storing Data in Sirius: Storing data in Sirius is simple. You can do an enqueueGet, enqueuePut or enqueueDelete. java Future <SiriusResult> future = sirius.enqueuePut(key, bytes) Future <SiriusResult> future = sirius.enqueueGet(key)