home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-05-08 | 6.2 KB | 168 lines |
- /*
- * Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
- *
- * This SOURCE CODE FILE, which has been provided by Borland as part
- * of a Borland product for use ONLY by licensed users of the product,
- * includes CONFIDENTIAL and PROPRIETARY information of Borland.
- *
- * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
- * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
- * THE PRODUCT.
- *
- * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
- * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
- * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
- * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
- * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
- * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
- * CODE FILE.
- */
- package visibroker.samples.locate;
-
-
- public class Find {
-
- private static void UsageHelper()
- {
- System.out.println("Unable to locate LocationService\n" +
- " -Make sure the locserv process is running\n" +
- " -Make sure you set the client's System Property\n" +
- " ORBservices=\"com.visigenic.vbroker.ObjLocation\"");
- }
-
- public static void main(String[] args)
- {
- try {
- // Initialize the ORB.
- org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);
- // Initialize the BOA.
- org.omg.CORBA.BOA boa = orb.BOA_init();
- com.visigenic.vbroker.ObjLocation.Agent agent = null;
-
- try {
- org.omg.CORBA.Object obj =
- orb.resolve_initial_references("LocationService");
- if ((obj == null) ||
- ((agent=com.visigenic.vbroker.ObjLocation.AgentHelper.narrow(obj)) == null)) {
- UsageHelper();
- System.exit(1);
- }
- } catch (org.omg.CORBA.ORBPackage.InvalidName e) {
- System.out.println("Not able to resolve references " +
- "for LocationService");
- UsageHelper();
- System.exit(1);
- } catch (Exception e) {
- System.out.println("Caught exception: " + e);
- UsageHelper();
- System.exit(1);
- }
-
- boolean done=false;
- java.io.DataInputStream in = new java.io.DataInputStream(System.in);
-
- while (! done) {
- System.out.print("-> ");
- System.out.flush();
- /* This code is needed for some VMs, but not others!!!*/
- if (System.getProperty("VM_THREAD_BUG") != null) {
- while(in.available() == 0) {
- try {
- Thread.currentThread().sleep(100);
- }
- catch(InterruptedException e) {
- }
- }
- }
-
- String line = in.readLine();
- if(line.startsWith("agents")) {
- java.lang.String[] agentList = agent.all_agent_locations();
- System.out.println("Located " + agentList.length + " agents");
- for (int i=0; i < agentList.length; i++) {
- System.out.println("\t" + "Agent #" + (i+1) + ": " +
- agentList[i]);
- }
- } else if(line.startsWith("rep")) {
- java.lang.String[] repIds = agent.all_repository_ids();
- System.out.println("Located " + repIds.length
- + " repository Ids");
- for (int i=0; i < repIds.length; i++) {
- System.out.println("\t" + "Repository Id #" + (i+1) + ": " +
- repIds[i]);
- }
- } else if(line.startsWith("objects ")) {
- String names =
- line.substring("objects ".length(), line.length());
- PrintObjects(names,agent,orb);
- } else if(line.startsWith("quit")) {
- done = true;
- } else {
- System.out.println("Commands: agents\n" +
- " repository_ids\n" +
- " objects <rep Id>\n" +
- " objects <rep Id> <obj name>\n" +
- " quit\n");
- }
- }
- } catch (com.visigenic.vbroker.ObjLocation.Fail err) {
- System.out.println("Location call failed with reason " +
- err.reason);
- } catch (java.lang.Exception err) {
- System.out.println("Caught error " + err);
- err.printStackTrace();
- }
- }
-
- public static void PrintObjects(String names,
- com.visigenic.vbroker.ObjLocation.Agent agent,
- org.omg.CORBA.ORB orb)
- throws com.visigenic.vbroker.ObjLocation.Fail
- {
- int space_pos = names.indexOf(' ');
- String repository_id;
- String object_name;
-
- if (space_pos == -1) {
- repository_id = names;
- object_name = null;
- } else {
- repository_id = names.substring(0,names.indexOf(' '));
- object_name = names.substring(names.indexOf(' ')+1);
- }
-
- org.omg.CORBA.Object[] objects;
- com.visigenic.vbroker.ObjLocation.Desc[] descriptors;
-
- if (object_name == null) {
- objects = agent.all_instances(repository_id);
- descriptors = agent.all_instances_descs(repository_id);
- } else {
- objects = agent.all_replica(repository_id,object_name);
- descriptors = agent.all_replica_descs(repository_id,object_name);
- }
-
- System.out.println("Returned " + objects.length + " objects");
- for (int i=0; i<objects.length; i++) {
- System.out.println("\n\nObject #" + (i+1) + ":");
- System.out.println("==================");
- System.out.println("\tRep ID: " + objects[i]._repository_id());
- System.out.println("\tInstance:" + objects[i]._object_name());
- System.out.println("\tIOR: " + orb.object_to_string(objects[i]));
- System.out.println();
- System.out.println("Descriptor #" + (i+1));
- System.out.println("=====================================");
- System.out.println("IIOP: " +
- descriptors[i].iiop_locator.iiop_version.major +
- " " +
- descriptors[i].iiop_locator.iiop_version.minor);
- System.out.println("Host: " + descriptors[i].iiop_locator.host);
- System.out.println("Port: " + descriptors[i].iiop_locator.port);
- System.out.println("Agent Host: " + descriptors[i].agent_hostname);
- System.out.println("Repository Id: " + descriptors[i].repository_id);
- System.out.println("Instance: " + descriptors[i].instance_name);
- System.out.println("Activable: " + descriptors[i].activable);
- }
- }
- }
-