home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-05-08 | 4.9 KB | 152 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.
- */
- // AccountTrigger.java
-
- import java.io.DataInputStream;
-
- class TriggerHandlerImpl extends
- com.visigenic.vbroker.ObjLocation._TriggerHandlerImplBase
- {
- public TriggerHandlerImpl(com.visigenic.vbroker.ObjLocation.Agent agent,
- com.visigenic.vbroker.ObjLocation.TriggerDesc initial_desc)
- {
- _agent = agent;
- _initial_desc = initial_desc;
- }
-
- public void impl_is_ready(com.visigenic.vbroker.ObjLocation.Desc desc)
- {
- notification(desc, true);
- }
- public void impl_is_down(com.visigenic.vbroker.ObjLocation.Desc desc)
- {
- notification(desc, false);
- }
-
- private void notification(com.visigenic.vbroker.ObjLocation.Desc desc,
- boolean isReady)
- {
- if (isReady) {
- System.out.println("Implementation is ready:");
- } else {
- System.out.println("Implementation is down:");
- }
- System.out.println("\tRepository Id = " + desc.repository_id + "\n" +
- "\tInstance Name = " + desc.instance_name + "\n" +
- "\tHost Name = " + desc.iiop_locator.host + "\n" +
- "\tBOA Port = " + desc.iiop_locator.port + "\n" +
- "\tActivable = " + desc.activable + "\n" + "\n");
- System.out.println("Unregister this handler and exit (yes/no)?");
- try {
- DataInputStream in = new DataInputStream(System.in);
- /* 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("y") || line.startsWith("Y")) {
- try {
- _agent.unreg_trigger(_initial_desc, this);
- } catch (com.visigenic.vbroker.ObjLocation.Fail e) {
- System.out.println("Failed to unregister trigger with reason=[" +
- e.reason + "]");
- }
- System.out.println("exiting...");
- System.exit(0);
- }
- } catch (java.io.IOException e) {
- System.out.println("Unexpected exception caught: " + e);
- System.exit(1);
- }
-
- }
-
- private com.visigenic.vbroker.ObjLocation.Agent _agent;
- private com.visigenic.vbroker.ObjLocation.TriggerDesc _initial_desc;
- }
-
- public class AccountTrigger
- {
-
- 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 the_agent = null;
-
- try {
- org.omg.CORBA.Object obj =
- orb.resolve_initial_references("LocationService");
- if ((obj == null) ||
- ((the_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);
- }
-
- // Create a trigger description and an appropriate TriggerHandler.
- // The TriggerHandler will be invoked when the osagent becomes
- // aware of any new implementations of the interface
- // "Bank::AccountManger"
-
- com.visigenic.vbroker.ObjLocation.TriggerDesc desc =
- new com.visigenic.vbroker.ObjLocation.TriggerDesc(
- "IDL:Bank/AccountManager:1.0", "", "");
- com.visigenic.vbroker.ObjLocation.TriggerHandler trig =
- new TriggerHandlerImpl(the_agent, desc);
-
- boa.obj_is_ready(trig);
- the_agent.reg_trigger(desc, trig);
-
- boa.impl_is_ready();
-
- } catch (Exception e) {
- System.out.println("Caught exception: " + e);
- System.exit(1);
- }
- }
- }
-