The Location Service Example
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:
From this example, you will learn how to:
-
Use the Location Service API provided by VisiBroker for Java to detect instances becoming available.
-
Implement triggers for notification when an instance becomes available or unavailable.
Directory Contents
-
locate.idl
IDL interface for the Location Service provided by VisiBroker for Java.
-
AccountFinder.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().
-
Find.java
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().
-
AccountTrigger.java
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.
-
Makefile (vbmake.bat on Windows): Used to build all the test targets.
Building this example
Typing make(vbmake on Windows) in the locate subdirectory will build the following classes:
-
AccountFinder.class
This java application uses the LocationService to obtain object references for any currently available implementations of the Bank::AccountManager interface.
-
Find.class
This java application uses the LocationService to obtain information about all currently available implementations
-
AccountTrigger.class
This java application registers a Trigger with the LocationService and will be notified as any new implementations of the interface Bank::AccountManager become available or when any implementation of the interface Bank::AccountManager becomes unavailable.
Compilation Warnings
You will see the following compilation warnings when you type make(vbmake on Windows) in the locate subdirectory or when you explicitly compile AccountTrigger.java and Find.java using:
prompt>javac AccountTrigger.java
Note: AccountTrigger.java uses a deprecated API. Recompile with
"-deprecation" for details.
1 warning
prompt>javac Find.java
Note: Find.java uses a deprecated API. Recompile with
"-deprecation" for details.
1 warning
These warnings occur because the example uses a Java API that has been deprecated since JDK1.1. The calls to the deprecated Java API have not been changed for the sake of JDK1.0.2 users.
Running this example
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.
The AccountFinder program:
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
Note that the Location Service detects the Bank Server.
Next start the AccountFinder:
prompt> vbj -DORBservices="com.visigenic.vbroker.ObjLocation" AccountFinder
Kill the bank server and again run the AccountFinder program as indicated above. Notice the change in output.
The Find program:
The Find program provides a command line user interface which allows the user to obtain information about specific objects using the
repository id. To test the Find program, start one or more Bank servers. Then start the Find program:
prompt> vbj -DORBservices="com.visigenic.vbroker.ObjLocation" Find
To obtain a list of the options the Find program provides, type at the Find program's command prompt.
The AccountTrigger program:
The AccountTrigger program will notify the user when a provider comes up or goes down.
To test the AccountTrigger program, first start the Bank server:
prompt> vbj Server
Then start AccountTrigger:
prompt> vbj -DORBservices="com.visigenic.vbroker.ObjLocation" AccountTrigger
Try killing the Bank server. AccountTrigger should notify the user of this change. When you kill the server it may take up to 5 minutes for osagent to cleanup its tables. Hence AccountTrigger notification will be delayed. Running the following command after killing the server will make osagent clean up its tables immediately.
prompt> osfind -LOCverify 1
Return to the top-level examples page.