ti.chimera
Class Registry

java.lang.Object
  extended byti.chimera.registry.RegistryCore
      extended byti.chimera.Registry

public class Registry
extends RegistryCore

The registry is a mechanism that allows different parts of the system share data. It is traditionally used to store registered plugins and services, but other parts of the system can use the registry to store or share data. The registry uses a publish-subscribe model, where in order to track the value of a node, the user subscribes to the node, and whenever the value of the node changes the most recent value is published to the subscriber's callback function. The registry will ensure that changes are published in the order they occur, and that all changes will be published, even if they've already been super- ceded by subsequent changes.

The registry is organized as a hierarchical tree, where "nodes" are either parent nodes (directories) or data nodes. Directory nodes are just data nodes whose data is a table mapping child names to nodes. A path is a / delimited string that specifies how to find a node from the root of the tree. Paths can contain .. to refer to one level up in the tree, or . to refer to the current level in the tree.

The registry can be accessed via Main.getRegistry() or from the script environment variable registry.

Version:
0.1
Author:
Rob Clark
See Also:
Main.getRegistry()

Nested Class Summary
 
Nested classes inherited from class ti.chimera.registry.RegistryCore
RegistryCore.DirectoryNode
 
Field Summary
 
Fields inherited from class ti.chimera.registry.RegistryCore
main, root
 
Method Summary
 Service getService(java.lang.String name)
          Get service provided by a plugin by name.
 void register(Plugin plugin)
          Register a plugin.
 void subscribeToCreation(java.lang.String path, NodeCreationSubscriber subscriber)
          Subscribe to the creation of a node.
 void subscribeToDeletion(java.lang.String path, NodeDeletionSubscriber subscriber)
          Subscribe to the deletion of a node.
 void subscribeToValue(java.lang.String path, NodeContract contract, NodeSubscriber subscriber)
          Subscribe to receive notification of changes to the value of the node at the specified path.
 void unsubscribeFromCreation(NodeCreationSubscriber subscriber)
          Unsubscribe to the creation of a node.
 void unsubscribeFromDeletion(NodeDeletionSubscriber subscriber)
          Unsubscribe to the deletion of a node.
 void unsubscribeFromValue(NodeSubscriber subscriber)
          Unsubscribe from specified path.
 
Methods inherited from class ti.chimera.registry.RegistryCore
basename, dirname, exists, link, mkdir, normalize, resolve, unlink, unlink
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

subscribeToValue

public void subscribeToValue(java.lang.String path,
                             NodeContract contract,
                             NodeSubscriber subscriber)
Subscribe to receive notification of changes to the value of the node at the specified path. This subscription is relative to the specified path, and not the node that is currently located at that path. If there is currently a node at this path, then the subscriber will be immediately called with the current value, otherwise the subscriber will be called once the node is created. If the node at this path is removed, and then at some later time another node is RegistryCore.link(ti.chimera.registry.Node, java.lang.String)ed in to this path, then the subscriber will subscribed to that node (and immediately called with it's value), and so on.

If contract is not null, then only subscribe to the node if it has a compatible contract.

Parameters:
path - the path to the node to subscribe to
contract - the optional contract, or null
subscriber - the subscriber

unsubscribeFromValue

public void unsubscribeFromValue(NodeSubscriber subscriber)
Unsubscribe from specified path. If not subscribed, do nothing.

Parameters:
subscriber - the subscriber

subscribeToCreation

public void subscribeToCreation(java.lang.String path,
                                NodeCreationSubscriber subscriber)
Subscribe to the creation of a node. The subscriber will be called whenever a node is RegistryCore.link(ti.chimera.registry.Node, java.lang.String)ed in to the specified path. If the node already exists, the subscriber will be called (pretty much) immediately.

Parameters:
path - the path to the node to subscribe to
subscriber - the subscriber

unsubscribeFromCreation

public void unsubscribeFromCreation(NodeCreationSubscriber subscriber)
Unsubscribe to the creation of a node. If not subscribed, do nothing.

Parameters:
subscriber - the subscriber

subscribeToDeletion

public void subscribeToDeletion(java.lang.String path,
                                NodeDeletionSubscriber subscriber)
Subscribe to the deletion of a node. The subscriber will be called whenever a node is RegistryCore.unlink(java.lang.String)ed from the specified path.

Parameters:
path - the path to the node to subscribe to
subscriber - the subscriber

unsubscribeFromDeletion

public void unsubscribeFromDeletion(NodeDeletionSubscriber subscriber)
Unsubscribe to the deletion of a node. If not subscribed, do nothing.

Parameters:
subscriber - the subscriber

register

public void register(Plugin plugin)
Register a plugin. This is how a plugin is added to the system. Once a plugin is added, the plugin can be resolved by #getPlugin and a service provided by a plugin can be resolved by getService(java.lang.String). The registry will handle starting a plugin if needed.

Parameters:
plugin - the plugin to register
See Also:
#getPlugin, getService(java.lang.String)

getService

public Service getService(java.lang.String name)
Get service provided by a plugin by name. This will automatically start the plugin providing the service if it has not already been started.

Parameters:
name - the name of the plugin to find
See Also:
#getServiceNames