Problem:
- Product Name: VisiBroker for Java
- Product Version: 5.2.1
- Product Component: ORB Smart Agent (osagent), Location Service
- Platform/OS Version: AIX 5.1
Changes in the behavior of the osagent from VB 5.0.1 to VB 5.2.1 meant that the agent returned all instances of an object on the entire network rather than just those registered with a specific osagent. How can the client programmer obtain objects from only one host/osagent?
Resolution:
There are two fairly simple alternatives:
1) Separate ORB domains.
Each host can run with a different OSAGENT_PORT setting. The servers that are to register with that agent should use the vbroker.agent.port property (or OSAGENT_PORT env variable) to specify what agent to use.
The client application should use vbroker.agent.port to select the appropriate server based on the port it is using.
2) Use the location service API to search for the specific agent host.
The following code from a simple java location service client that gives an idea of how the Desc structure can be used from the Location Service API to inspect which agent host the instance of interest came from. The agent host is represented as an IP address string in the Desc structure.
They should use the iiop_locator member of the Desc structure which is defined as follows:
struct Desc {
Object ref;
::IIOP::ProfileBodyValue iiop_locator;
string repository_id;
string instance_name;
boolean activable;
string agent_hostname;
};
The host member is a string representing the ip address of the host where the server is running.
The sample code and a typical run is below:
// Client.java
public class Client {
public static void main(String[] args) {
String repositoryId = "IDL:Bank/AccountManager:1.0";
java.net.InetAddress host_addr = null;
try {
host_addr =
java.net.InetAddress.getByName("smibmscm2.sm.inprise.com");
System.out.println("The ip address of smibmscm2 is "
host_addr.getHostAddress() );
} catch (java.net.UnknownHostException uhe) {
uhe.printStackTrace();
}
try {
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
com.inprise.vbroker.ObjLocation.Agent agent = null;
try {
agent = com.inprise.vbroker.ObjLocation.AgentHelper.narrow(
orb.resolve_initial_references("LocationService"));
} catch (org.omg.CORBA.ORBPackage.InvalidName ie) {
System.out.println("Not able to resolve references "
"for Location Service");
System.exit(1);
} catch (Exception ex) {
ex.printStackTrace();
}
com.inprise.vbroker.ObjLocation.Desc[] descriptors;
descriptors = agent.all_instances_descs(repositoryId);
System.out.println("Returned " descriptors.length " descriptors ");
for ( int i = 0; i < descriptors.length; i ) {
if ( descriptors[ i ].agent_hostname.equals(host_addr.getHostAddress()) ) {
System.out.println("\\nFound instance registered on smibmscm2");
System.out.println(
" OSAgent Host: " descriptors[ i ].agent_hostname " "
"\\n Rep Id: " descriptors[ i ].repository_id " "
"\\n Instance name: " descriptors[ i ].instance_name " "
"\\n Server host: " descriptors[ i ].iiop_locator.host " "
);
}
}
} catch (java.lang.Exception err) {
System.out.println("Caught error: " err);
err.printStackTrace();
}
}
}
The output - one osagent but servers on two different hosts:
- The agent_hostname is the same for all objects.
- The iiop_locator.host entry is different.
The ip address of smibmscm2 is 172.20.20.136
Returned 4 descriptors Found instance registered on smibmscm2 OSAgent Host: 172.20.20.136 Rep Id: IDL:Bank/AccountManager:1.0 Instance name: BankManager Server host: 172.20.20.138 Found instance registered on smibmscm2 OSAgent Host: 172.20.20.136 Rep Id: IDL:Bank/AccountManager:1.0 Instance name: BankManager Server host: 172.20.20.136 Found instance registered on smibmscm2 OSAgent Host: 172.20.20.136 Rep Id: IDL:Bank/AccountManager:1.0 Instance name: BankManager Server host: 172.20.20.136 Found instance registered on smibmscm2 OSAgent Host: 172.20.20.136 Rep Id: IDL:Bank/AccountManager:1.0 Instance name: BankManager Server host: 172.20.20.138
You could also study the product location service example as a reference.
#Security
#VisiBroker




