Implementing Functionality
Knowing which model to use, the developer can customize node behavior. After connecting successfully, the node does not have to reconnect. The same connection can be used for both providing and consuming capabilities. The node further interacts with pxGrid by registering the appropriate query and notification callers and handlers as detailed below.
Query Handler
A provider must register a query handler with the GCL to service a query that it needs to expose over pxGrid. When a consumer initiates a query, the GCL invokes the corresponding query handler on the provider's node to service the request and return response.
A query handler is created by implementing an interface. API details vary depending on the programming language. A realistic implementation would contain extensive business logic and would likely interact with external components such as databases. The handler is registered by associating the handler with a pxGrid connection. The handler remains active and can potentially process requests until the thread disconnects from pxGrid. Before a query handler can be registered, the provider must establish its intent to be provider of a capability. This will be successful only if the node is authorized to be a provider for that capability.
Query Caller
To be able to invoke a query, a node must establish its intent to be a consumer of the capability by invoking a subscribe capability method on the pxGrid connection and must be authorized to be a consumer of the capability.
A query caller is created by assembling a request and calling the query method on the pxGrid connection. Then the query method is called. Since queries are processed synchronously, the query method blocks until a response is received from the provider (or a timeout occurs). Note that the query is not directed to a provider by the caller, this is done internally by pxGrid. If there is no registered provider for the query, then an error is returned.
Notification Handler
A consumer node registers a notification handler with the pxGrid connection to receive notifications for a capability. Before a notification handler can be registered, the consumer must invoke a subscribe capability method to establish itself as a consumer for a capability.
The developer creates a notification handler by implementing a notification callback interface. By registering an instance of this implementation with the pxGrid connection, notifications will be received whenever a provider sends them. Note that this communication is asynchronous. The handler remains live until the node is disconnected from pxGrid.
Notifier
To be able to publish notifications, the provider node must first invoke a publish capability method on the pxGrid connection to establish itself as a provider for a capability. If the node does not have the right authorization group, the pxGrid server will return an authorization error. Calling notify on the pxGrid connection sends the object to any nodes connected to pxGrid that have registered for notifications of this class. Note that the notify method does not block.