This example illustrates VisiBroker for Java's location service. It enables developer code to discover, or be notified of, object instances that have particular attributes, such as satisfying an interface. The location service can be used for any function that requires knowledge of what objects are presently accessible and where they are. This information could be used for load balancing or debugging. This example subdirectory also contains a program illustrating triggers which are a part of the Location Service. Triggers are an asynchronous alternative to polling the OSAgent to learn when an instance becomes available or becomes unavailable. Note that usage of the LocationService (the OSAgent interface) with VisiBroker for Java currently requires the execution of the standalone server locserv which is provided with the VisiBroker for Java release. The program is shipped as part of the archive of platform-specific executables and scripts which should have been installed in the directory bin. Assuming the installation's bin directory has been added to your path, this executable can be run with the command:
prompt> locserv
IDL interface for the Location Service provided by VisiBroker for Java.
This program gathers information using the Location Service about all instances
satisfying the account interface. To do this, the Repository ID IDL:Account:1.0
of the account interface is passed to the Agent's all_instances().
This example is more generic than the AccountFinder.java
example above. It shows an example of acquiring an Agent (The Agent
is the CORBA interface to access the Location service) to obtain all Globally
scoped instances. The Agent is acquired by passing "Location
Service" to orb.resolve_initial_references() and then narrowing
the object returned to ObjLocation.Agent. ObjLocation.all_repository_ids()
is then used to retrieve the repository IDs of all interfaces that are
known to the OSAgent. Following this, information about all the interfaces
that have been retrieved is obtained using all_instances_descs().
This program implements a TriggerHandler. The main class creates and registers
a Handler instance. The trigger is set to notify when an instance with
the repository ID IDL:Account:1.0 registers itself with the OSAgent
and becomes accessible. The trigger handler is sticky in that it will continue
to fire when new instances of this interface become available, until explicitly
unregistered by the user. The program gives an option to the user to unregister
the trigger handler each time an instance of IDL:Account:1.0 becomes
available or unavailable.
To run the examples, first make sure that the VisiBroker Smart Agent (osagent executable) is running on your network. You should also have the Location Service (locserv executable) running on your network. Then start the Bank Server from the Bank example using the command:
prompt> vbj Server (start vbj Server on Windows) // Make Server run in the background
Next, start the AccountFinder, Find and AccountTrigger programs:
prompt> vbj -DORBservices="com.visigenic.vbroker.ObjLocation" AccountFinder
Note that the Location Service detects the Bank Server. Kill the bank server and again run the AccountFinder program as indicated above. Notice the change in output.
prompt> vbj -DORBservices="com.visigenic.vbroker.ObjLocation" Find
To test the find program, start one or more bank servers (or other servers).
The Find program provides with a command line user interface which allows
the user to obtain information about specific objects using their repository
id. To obtain a list of the options the Find program provides, start the
Find program and type
prompt> vbj -DORBservices="com.visigenic.vbroker.ObjLocation" AccountTrigger
The AccountTrigger program will notify the user when a provider goes
down or when a provider comes back up. Try running the AccountTrigger program
after either starting the bank server or stopping the bank server.