home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / TRIAL / JBUILDER / JVISBRKR.Z / AccountTrigger.java < prev    next >
Encoding:
Java Source  |  1998-05-08  |  4.9 KB  |  152 lines

  1. /*
  2.  * Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
  3.  * 
  4.  * This SOURCE CODE FILE, which has been provided by Borland as part
  5.  * of a Borland product for use ONLY by licensed users of the product,
  6.  * includes CONFIDENTIAL and PROPRIETARY information of Borland.  
  7.  *
  8.  * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 
  9.  * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
  10.  * THE PRODUCT.
  11.  *
  12.  * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
  13.  * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
  14.  * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
  15.  * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
  16.  * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
  17.  * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
  18.  * CODE FILE.
  19.  */
  20. // AccountTrigger.java
  21.  
  22. import java.io.DataInputStream;
  23.  
  24. class TriggerHandlerImpl extends 
  25.         com.visigenic.vbroker.ObjLocation._TriggerHandlerImplBase
  26. {
  27.   public TriggerHandlerImpl(com.visigenic.vbroker.ObjLocation.Agent agent,
  28.            com.visigenic.vbroker.ObjLocation.TriggerDesc initial_desc)
  29.   {
  30.     _agent = agent;
  31.     _initial_desc = initial_desc;
  32.   }
  33.  
  34.   public void impl_is_ready(com.visigenic.vbroker.ObjLocation.Desc desc)
  35.   {
  36.     notification(desc, true);
  37.   }
  38.   public void impl_is_down(com.visigenic.vbroker.ObjLocation.Desc desc)
  39.   {
  40.     notification(desc, false);
  41.   }
  42.  
  43.   private void notification(com.visigenic.vbroker.ObjLocation.Desc desc, 
  44.             boolean isReady)
  45.   {
  46.     if (isReady) {
  47.       System.out.println("Implementation is ready:");
  48.     } else {
  49.       System.out.println("Implementation is down:");
  50.     }
  51.     System.out.println("\tRepository Id = " + desc.repository_id + "\n" +
  52.                "\tInstance Name = " + desc.instance_name + "\n" +
  53.                "\tHost Name     = " + desc.iiop_locator.host + "\n" +
  54.                "\tBOA Port      = " + desc.iiop_locator.port + "\n" +
  55.                "\tActivable     = " + desc.activable + "\n" + "\n");
  56.     System.out.println("Unregister this handler and exit (yes/no)?");
  57.     try {
  58.       DataInputStream in = new DataInputStream(System.in);
  59.       /* This code is needed for some VMs, but not others!!!*/
  60.       if (System.getProperty("VM_THREAD_BUG") != null) {
  61.     while(in.available() == 0) {
  62.       try {
  63.         Thread.currentThread().sleep(100);
  64.       }
  65.       catch(InterruptedException e) {
  66.       }
  67.     }
  68.       }
  69.       String line = in.readLine();
  70.       if(line.startsWith("y") || line.startsWith("Y")) {
  71.     try {
  72.       _agent.unreg_trigger(_initial_desc, this);
  73.     } catch (com.visigenic.vbroker.ObjLocation.Fail e) {
  74.       System.out.println("Failed to unregister trigger with reason=[" +
  75.                  e.reason + "]");
  76.     }
  77.     System.out.println("exiting...");
  78.     System.exit(0);
  79.       }
  80.     } catch (java.io.IOException e) {
  81.       System.out.println("Unexpected exception caught: " + e);
  82.       System.exit(1);
  83.     }
  84.  
  85.   }
  86.  
  87.   private com.visigenic.vbroker.ObjLocation.Agent        _agent;
  88.   private com.visigenic.vbroker.ObjLocation.TriggerDesc  _initial_desc;
  89. }
  90.  
  91. public class AccountTrigger 
  92. {
  93.  
  94.   private static void UsageHelper()
  95.   {
  96.     System.out.println("Unable to locate LocationService\n" +
  97.        "   -Make sure the locserv process is running\n" +
  98.        "   -Make sure you set the client's System Property\n" +
  99.        "    ORBservices=\"com.visigenic.vbroker.ObjLocation\"");
  100.   }
  101.  
  102.   public static void main(String args[])
  103.   {
  104.     try {
  105.       // Initialize the ORB.
  106.       org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);
  107.       // Initialize the BOA.
  108.       org.omg.CORBA.BOA boa = orb.BOA_init();
  109.       com.visigenic.vbroker.ObjLocation.Agent the_agent = null;
  110.  
  111.       try {
  112.     org.omg.CORBA.Object obj = 
  113.       orb.resolve_initial_references("LocationService");
  114.     if ((obj == null) ||
  115.         ((the_agent=com.visigenic.vbroker.ObjLocation.AgentHelper.narrow(obj)) == null)) {
  116.       UsageHelper();
  117.       System.exit(1);
  118.     }
  119.       } catch (org.omg.CORBA.ORBPackage.InvalidName e) {
  120.     System.out.println("Not able to resolve references " +
  121.                "for LocationService");
  122.     UsageHelper();
  123.     System.exit(1);
  124.       } catch (Exception e) {
  125.     System.out.println("Caught exception: " + e);
  126.     UsageHelper();
  127.     System.exit(1);
  128.       }
  129.  
  130.       // Create a trigger description and an appropriate TriggerHandler.
  131.       // The TriggerHandler will be invoked when the osagent becomes
  132.       // aware of any new implementations of the interface
  133.       // "Bank::AccountManger"
  134.  
  135.       com.visigenic.vbroker.ObjLocation.TriggerDesc desc = 
  136.     new com.visigenic.vbroker.ObjLocation.TriggerDesc(
  137.         "IDL:Bank/AccountManager:1.0", "", "");
  138.       com.visigenic.vbroker.ObjLocation.TriggerHandler trig = 
  139.     new TriggerHandlerImpl(the_agent, desc);
  140.  
  141.       boa.obj_is_ready(trig);
  142.       the_agent.reg_trigger(desc, trig);
  143.  
  144.       boa.impl_is_ready();
  145.  
  146.     } catch (Exception e) {
  147.       System.out.println("Caught exception: " + e);
  148.       System.exit(1);
  149.     }
  150.   }
  151. }
  152.