|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.sandev.tools.util.DirectCallMessager
A Messager implementation that translates all communications into direct method calls. This class is only appropriate for for use on single server deployments, or as a base class for other Messager implementations. While the DirectCallMessager provides a reasonable facsimile of the maximum possible messaging speed in Java, it has some noteworthy aspects:
Direct messaging doesn't cause problems, but it can definitely bring
some hidden ugly code to the foreground, while hiding other issues. Be
aware of your resource locks and message paths.
How it works:
Each DirectCallMessager instance keeps a dictionary of Messageable
instances indexed by instance name. We look up the instance name to get
the object and then make the call.
If the instance is not found in the dictionary, then we convert our
Messageable into a Controllable (we are assuming here that our Messageable
is a node, and all nodes are Controllable so this works). From the root,
we traverse the tree looking for the node with the specified instance name.
If found, we add it to the dictionary and make the call. If not, then we
fail.
On failure we throw an exception. Subclasses can override this
behavior and take the direct call failure as an indication that the
target node is not local. At that point they would try to get the
message across via the supporting communications technology.
| Field Summary | |
protected org.sandev.basics.structs.NodeInstance |
ourInstance
The instance of the node we are serving. |
protected org.sandev.basics.nodecommon.Messageable |
ourNode
The node we are serving. |
protected java.util.HashMap |
subTable
All known direct subscribers |
| Fields inherited from interface org.sandev.basics.nodecommon.Messager |
MODE_DIRECT, MODE_INVALID, MODE_SECURE, OPTIMIZE_IF_POSSIBLE, OPTIMIZE_NEVER, WIRE_BASICSECURITY, WIRE_SECURECOMMS, WIRE_TRANSPORTONLY |
| Constructor Summary | |
DirectCallMessager()
Default ctor does nothing. |
|
| Method Summary | |
protected void |
addSubscriber(org.sandev.basics.nodecommon.Messageable node,
java.lang.String msgClass)
Add the specified node to our list of subscribers |
protected org.sandev.basics.structs.SandMessage |
doQuery(org.sandev.basics.structs.SandMessage msg,
java.lang.String recipient,
int optimize)
Query the specified node. |
protected void |
doSend(org.sandev.basics.structs.SandMessage msg,
java.util.ArrayList al)
Workhorse for interface doSend method. |
protected void |
doSend(org.sandev.basics.structs.SandMessage msg,
int optimize)
Send the message. |
protected void |
doSubscribe(org.sandev.basics.nodecommon.Messageable node,
java.lang.String msgClass,
java.lang.String sender,
int optimize)
Make the subscription happen. |
protected void |
doUnsubscribe(org.sandev.basics.nodecommon.Messageable node,
java.lang.String msgClass,
java.lang.String sender,
int optimize)
Make the subscription go away. |
protected void |
error(java.lang.String text)
General error reporting method. |
protected int |
getImplementationWireSecurity()
Override this method to return the level of security provided by this messager implementation. |
protected org.sandev.basics.nodecommon.Messageable |
getMessageable(java.lang.String instanceName)
Return the Messageable corresponding to the instance name specified. |
org.sandev.basics.structs.NodeInstance |
getOurInstance()
accessor for ourInstance |
org.sandev.basics.nodecommon.Messageable |
getOurNode()
accessor for ourNode |
protected java.util.Map |
getSubTable()
|
int |
getWireSecurity()
Return the wire security level this messager implementation provides. |
protected void |
info(java.lang.String text)
General info logging method. |
void |
init(org.sandev.basics.nodecommon.Messageable node,
org.sandev.basics.structs.NodeInstance instance)
|
org.sandev.basics.structs.SandMessage |
query(org.sandev.basics.structs.SandMessage msg,
java.lang.String recipient,
int optimize,
int mode,
java.lang.String localAuth)
Query the specified recipient and return the result. |
void |
queryReceiver(org.sandev.basics.nodecommon.Messageable node,
java.lang.String messageClass,
java.lang.String localAuth)
Get the local authorizer and register this node as the recipient for these kinds of queries. |
protected void |
removeSubscriber(org.sandev.basics.nodecommon.Messageable node,
java.lang.String msgClass)
Remove the specified node from our list of subscribers |
void |
send(org.sandev.basics.structs.SandMessage msg,
int optimize,
int mode,
java.lang.String auth)
If this is a secure send, call our local authorizer directly and have them wrap and send. |
void |
setOurInstance(org.sandev.basics.structs.NodeInstance instance)
mutator for ourInstance |
void |
setOurNode(org.sandev.basics.nodecommon.Messageable node)
mutator for ourNode |
void |
shutdown()
|
void |
subscribe(org.sandev.basics.nodecommon.Messageable node,
java.lang.String msgClass,
java.lang.String sender,
int optimize,
int mode,
java.lang.String localAuth,
org.sandev.basics.structs.SandAttrVal[] matchDescription)
Hook us up for broadcast messages of the specified type from the specified source. |
void |
unsubscribe(org.sandev.basics.nodecommon.Messageable node,
java.lang.String msgClass,
java.lang.String sender,
int optimize,
int mode,
java.lang.String localAuth)
Undo the subscription. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected java.util.HashMap subTable
protected org.sandev.basics.nodecommon.Messageable ourNode
protected org.sandev.basics.structs.NodeInstance ourInstance
| Constructor Detail |
public DirectCallMessager()
| Method Detail |
protected java.util.Map getSubTable()
public org.sandev.basics.nodecommon.Messageable getOurNode()
public void setOurNode(org.sandev.basics.nodecommon.Messageable node)
public org.sandev.basics.structs.NodeInstance getOurInstance()
public void setOurInstance(org.sandev.basics.structs.NodeInstance instance)
public void init(org.sandev.basics.nodecommon.Messageable node,
org.sandev.basics.structs.NodeInstance instance)
throws org.sandev.basics.nodecommon.MessagerException
init in interface org.sandev.basics.nodecommon.Messagerorg.sandev.basics.nodecommon.MessagerExceptionpublic void shutdown()
shutdown in interface org.sandev.basics.nodecommon.Messager
public void subscribe(org.sandev.basics.nodecommon.Messageable node,
java.lang.String msgClass,
java.lang.String sender,
int optimize,
int mode,
java.lang.String localAuth,
org.sandev.basics.structs.SandAttrVal[] matchDescription)
throws org.sandev.basics.nodecommon.MessagerException
The matchDescription is ignored. The node already has logic
to check this, and it doesn't matter if this checking occurs up
front or not since it's all direct calls.
subscribe in interface org.sandev.basics.nodecommon.Messagerorg.sandev.basics.nodecommon.MessagerException
public void unsubscribe(org.sandev.basics.nodecommon.Messageable node,
java.lang.String msgClass,
java.lang.String sender,
int optimize,
int mode,
java.lang.String localAuth)
throws org.sandev.basics.nodecommon.MessagerException
unsubscribe in interface org.sandev.basics.nodecommon.Messagerorg.sandev.basics.nodecommon.MessagerException
public void send(org.sandev.basics.structs.SandMessage msg,
int optimize,
int mode,
java.lang.String auth)
throws org.sandev.basics.nodecommon.MessagerException
send in interface org.sandev.basics.nodecommon.Messagerorg.sandev.basics.nodecommon.MessagerException
public org.sandev.basics.structs.SandMessage query(org.sandev.basics.structs.SandMessage msg,
java.lang.String recipient,
int optimize,
int mode,
java.lang.String localAuth)
throws org.sandev.basics.nodecommon.MessagerException
For secure queries, the recipient is the remote authorizer
instance name. That authorizer finds the appropriate recipient
through the receive registrations established on startup.
query in interface org.sandev.basics.nodecommon.Messagerorg.sandev.basics.nodecommon.MessagerException
public void queryReceiver(org.sandev.basics.nodecommon.Messageable node,
java.lang.String messageClass,
java.lang.String localAuth)
throws org.sandev.basics.nodecommon.MessagerException
queryReceiver in interface org.sandev.basics.nodecommon.Messagerorg.sandev.basics.nodecommon.MessagerExceptionpublic int getWireSecurity()
getWireSecurity in interface org.sandev.basics.nodecommon.Messagerprotected int getImplementationWireSecurity()
protected void doSubscribe(org.sandev.basics.nodecommon.Messageable node,
java.lang.String msgClass,
java.lang.String sender,
int optimize)
throws org.sandev.basics.nodecommon.MessagerException
When overriding this method in a subclass, you can first call
here to try optimized delivery. If that succeeds, you're done.
If optimized delivery doesn't succeed it will throw.
org.sandev.basics.nodecommon.MessagerException
protected void doUnsubscribe(org.sandev.basics.nodecommon.Messageable node,
java.lang.String msgClass,
java.lang.String sender,
int optimize)
throws org.sandev.basics.nodecommon.MessagerException
org.sandev.basics.nodecommon.MessagerException
protected void doSend(org.sandev.basics.structs.SandMessage msg,
int optimize)
throws org.sandev.basics.nodecommon.MessagerException
If for any reason our send fails, we just log it and continue since the failure is in the subscriber node and not our stuff.
When overriding this method in a subclass, you can first call
here to try optimized delivery. If that succeeds, you're done.
If optimized delivery doesn't succeed then this method will
throw, and non-optimized delivery would then be attempted.
It is possible to subscribe to an interface, rather than a
specific message, although there is really only one seminal case
where this is necessary and that's SandUpdateMessage. This is
because the CacheManager needs to subscribe to any kind of an
update from the DataManager, and it can't know at declaration time
what kinds of SandUpdateMessages have been defined. Rather than
do an extensive generator interface, we handle this one special
case through a recursive call here. If this turns out to be a
general issue, then we'll generalize this code.
org.sandev.basics.nodecommon.MessagerException
protected void doSend(org.sandev.basics.structs.SandMessage msg,
java.util.ArrayList al)
throws org.sandev.basics.nodecommon.MessagerException
org.sandev.basics.nodecommon.MessagerException
protected org.sandev.basics.structs.SandMessage doQuery(org.sandev.basics.structs.SandMessage msg,
java.lang.String recipient,
int optimize)
throws org.sandev.basics.nodecommon.MessagerException
Query the specified node. We ignore the optimize flag since this
messager only does optimzed delivery.
When overriding this method in a subclass, you can first call
here to try optimized delivery. If that succeeds, you're done.
If optimized delivery doesn't succeed it will throw.
org.sandev.basics.nodecommon.MessagerExceptionprotected void error(java.lang.String text)
protected void info(java.lang.String text)
protected void addSubscriber(org.sandev.basics.nodecommon.Messageable node,
java.lang.String msgClass)
protected void removeSubscriber(org.sandev.basics.nodecommon.Messageable node,
java.lang.String msgClass)
protected org.sandev.basics.nodecommon.Messageable getMessageable(java.lang.String instanceName)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||