bamboo.lss
Class Rpc

java.lang.Object
  extended by bamboo.util.StandardStage
      extended by bamboo.lss.Rpc
All Implemented Interfaces:
EventHandlerIF, SingleThreadedEventHandlerIF

public class Rpc
extends StandardStage

A simple mechanism for associating request and response messages, with error checking. To use, receivers call register_request_cb(java.lang.Class, bamboo.lss.Rpc.RequestCB, java.lang.Object) to set the function to be called when a request is received. A sender sends a request using send_request(ostore.util.NodeId, ostore.util.QuickSerializable, long, java.lang.Class, bamboo.lss.Rpc.ResponseCB, java.lang.Object), which will later result in a call to supplied callback. This stage will ensure that the response has the type specified in the call to send_request(ostore.util.NodeId, ostore.util.QuickSerializable, long, java.lang.Class, bamboo.lss.Rpc.ResponseCB, java.lang.Object). To send a response, the receiving node calls #send_response with the token passed to the request callback.


Nested Class Summary
static class Rpc.Msg
           
static interface Rpc.RequestCB
           
static interface Rpc.ResponseCB
           
 
Field Summary
protected  HashMap handlers
           
protected  HashMap inflight
           
protected static Rpc instance
           
protected  HashSet known_types
           
protected  long next_xact_id
           
 ASyncCore.TimerCB request_timeout_cb
           
 
Fields inherited from class bamboo.util.StandardStage
acore, classifier, DEBUG, event_types, inb_msg_types, logger, my_node_id, my_sink, outb_msg_types, sim_running
 
Constructor Summary
Rpc()
           
 
Method Summary
protected  void ensure_known(Class clazz)
           
 void handleEvent(QueueElementIF item)
           
static Rpc instance()
           
protected  long next_xact_id()
           
 void register_request_cb(Class req_class, Rpc.RequestCB cb, Object user_data)
           
 void send_request(ostore.util.NodeId dest, ostore.util.QuickSerializable req, long timeout_sec, Class resp_class, Rpc.ResponseCB cb, Object user_data)
           
 void send_response(ostore.util.QuickSerializable resp, Object token)
           
 
Methods inherited from class bamboo.util.StandardStage
BUG, BUG, BUG, config_get_boolean, config_get_double, config_get_int, config_get_string, configGetInt, destroy, dispatch, enqueue, handleEvents, init, lookup_stage, now_ms, timer_ms
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

protected static Rpc instance

next_xact_id

protected long next_xact_id

handlers

protected HashMap handlers

inflight

protected HashMap inflight

known_types

protected HashSet known_types

request_timeout_cb

public ASyncCore.TimerCB request_timeout_cb
Constructor Detail

Rpc

public Rpc()
Method Detail

ensure_known

protected void ensure_known(Class clazz)

next_xact_id

protected long next_xact_id()

instance

public static Rpc instance()

register_request_cb

public void register_request_cb(Class req_class,
                                Rpc.RequestCB cb,
                                Object user_data)

send_request

public void send_request(ostore.util.NodeId dest,
                         ostore.util.QuickSerializable req,
                         long timeout_sec,
                         Class resp_class,
                         Rpc.ResponseCB cb,
                         Object user_data)

send_response

public void send_response(ostore.util.QuickSerializable resp,
                          Object token)

handleEvent

public void handleEvent(QueueElementIF item)
Specified by:
handleEvent in interface EventHandlerIF
Overrides:
handleEvent in class StandardStage