JICSCore
Class OCSCORBAHelper

java.lang.Object
  extended by JICSCore.OCSCORBAHelper

public class OCSCORBAHelper
extends java.lang.Object

This class will be used to provide a number of convenience CORBA related functions which can be used throughout the WHTICS system. It provides a wrapper around some of the common CORBA related tasks that need to be performed when creating a CORBA based client or server.

Example

This code is from the ParameterNoticeBoard. The ParameterNoticeBoard object implements two CORBA interfaces and as such both interfaces must be handled separately. Two entries, one for each of the interfaces are entered into the COS name service in different contexts.

    public static void main(java.lang.String[] args) 
     {
        
        // This will be used to perform a lot of the donkey work
        // associated with setting up a CORBA server.
 
        OCSCORBAHelper OCSCorba = null;
        
        // The CORBA request broker or ORB which will be used for handling
        // CORBA requests
 
        ORB orb = null;
     
        // The portable object adapter which will be used by this class
 
        POA parameterNoticeBoardPOA = null;
        
      // This is the root naming service context
 
        NamingContextExt RootNamingServiceContext = null;
 
        // Set up the default port for connection to the name service
        // on this machine. Note that the persistent port is 35576 for
        // the parameter noticeboard. 
 
        try {
            OCSCorba = new OCSCORBAHelper(args,"35675","15242","ParameterNoticeBoardPOA");
        } catch (UnableToFindNameServerException e) {
            System.out.println("Unable to find name server " + e.getMessage());
            System.exit(-1);
        } catch (Exception e) {
            System.out.println("Error when initialising CORBA " + e.toString());
            System.exit(-2);
        }
 
        // Now get a reference to the ORB singleton
        
        orb = OCSCorba.getORB();
        
        // Now get a reference to the POA capable of creating persistent POAs
      // from the OCSCORBAHelper class
        
        parameterNoticeBoardPOA = OCSCorba.getPOA();
 
        // Now get a reference to the COS name service
 
        RootNamingServiceContext = OCSCorba.getNameServiceReference();
      
        // Now we need to create a instance of the
        // ParameterNoticeBoard CORBA object
      
        ParameterNoticeBoard parameterNoticeBoard = new ParameterNoticeBoard(syslogMessageHandler,orb);
      
        // Now attempt to add a reference to the ParameterNotice board
        // to the naming service. Note that we wrap the object up in a
        // TIE reference to get around the multiple inheritence
        // problem of java. 
 
        ParameterNoticeBoardSupplierPOATie parameterNoticeBoardPseudoImpl = new ParameterNoticeBoardSupplierPOATie(parameterNoticeBoard);
        
        try {
 
            parameterNoticeBoardPOA.activate_object_with_id("ParameterNoticeBoard".getBytes(),
                                                            parameterNoticeBoardPseudoImpl);
 
        } catch (Exception e) {
            System.out.println("Unable activate parameter noticeboard object > " 
                                             + e.toString());
            System.exit(-2);
        }
 
        // Now store the reference to the parameter noticeboard
        // interface in the name service using the OCSCorbaHelper library 
      // Note by specifying null as the context signifies that the object 
      // reference will be stored in the root context.
        
        try {
            OCSCorba.storeReferenceInNameService(parameterNoticeBoardPseudoImpl,null,"ParameterNoticeBoard");
        } catch (Exception e) {
            System.out.println("Unable to store parameter noticeboard reference " 
                                             + e.toString());
            System.exit(-2);        
        }
 
        // Now register the same object again only this time storing
        // it's InstrumentController interface so that we can provide
        // instrument control actions on the parameter noticeboard
        // (like close it down properly)
        
        InstrumentControllerPOATie controllerPseudoImpl = new InstrumentControllerPOATie(parameterNoticeBoard);
        
        try {
            parameterNoticeBoardPOA.activate_object_with_id("NoticeBoard".getBytes(), controllerPseudoImpl);
        } catch (Exception e) {
            System.out.println("Unable to activate object > " + e.toString());
            System.exit(-2);
        }
 
        // Now we need to store a reference to the CORBA
        // InstrumentController interface which will be used to close
        // the program down and modify it's behaviour. 
        // 
        // Note that although it is the same object, we have to treat
        // both the interfaces that it implements individually with
        // respect to CORBA 
 
        try {
            OCSCorba.storeReferenceInNameService(controllerPseudoImpl,
                                                 "InstrumentController","ParameterNoticeBoard");
        } catch (Exception e) {
            System.out.println("Unable to store instrument controller reference " 
                                             + e.toString());
            System.exit(-3);        
        }
 
        // Now activate the POA so we can wait for incoming service
        // requests
        
        try {
            parameterNoticeBoardPOA.the_POAManager().activate();
        } catch (Exception e) {
            System.out.println("Unable to activate parameter noticeboard POA " + e.getMessage() + " exiting application");
            System.exit(-1);
        }
        
        // Start servicing requests on our CORBA objects
 
        orb.run();     
     }
 
   

Version:
$Id: OCSCORBAHelper.java,v 1.9 2007/01/24 09:53:34 cb Exp $
Author:
Craige Bevil


Field Summary
(package private) static boolean ClassInstantiated
          Used to ensure that only ever one instance of this class exists in a process.
private  java.lang.String COSNameServiceHost
          The machine which is hosting the name service
private  int NameServicePortNumber
          This is the port number of the name service which by default is 35777
private  org.omg.CORBA.ORB Orb
          A reference to the the ORB singleton for this process
private  java.lang.String ORBName
          This is the name of the ORB which will be used in the event of one not been supplied.
private  iParameterNoticeBoard.ParameterNoticeBoardSupplier ParameterNoticeBoard
          This is a reference to the parameter noticeboard;
private  org.omg.PortableServer.POA Poa
          This is a POA which is to be created.
private  java.lang.String POAName
          This is the name of the POA which will be used in the event of one not been supplied.
private  org.omg.CosNaming.NamingContextExt rootNamingServiceContext
          This is a reference to the top level context in the naming service
private  org.omg.PortableServer.POA rootPOA
          This is the root POA of the CORBA system
 
Constructor Summary
OCSCORBAHelper(java.lang.String[] args, java.util.Properties CORBAHelperProperties)
          The constructor.
OCSCORBAHelper(java.lang.String[] args, java.lang.String POAName)
          The constructor.
OCSCORBAHelper(java.lang.String[] args, java.lang.String POAName, int COSNameServicePortNumber)
          The constructor.
OCSCORBAHelper(java.lang.String[] args, java.lang.String POAName, int COSNameServicePortNumber, java.lang.String COSNameServiceHost)
          The constructor.
OCSCORBAHelper(java.lang.String[] args, java.lang.String POAName, java.lang.String COSNameServiceHost)
          The constructor.
OCSCORBAHelper(java.lang.String[] args, java.lang.String ORBPersistentPort, java.lang.String ORBServerID, java.lang.String POAName)
          The constructor.
OCSCORBAHelper(java.lang.String[] args, java.lang.String ORBPersistentPort, java.lang.String ORBServerID, java.lang.String POAName, java.lang.String COSNameServiceHost)
          The constructor.
 
Method Summary
 void CORBAcloseDown()
          Close down the CORBA communications.
 void createNamingServiceContext(java.lang.String Context)
          Creates a new context in the naming service.
 org.omg.PortableServer.POA createNewPOA(java.lang.String POAIdentifier)
          This will be used to create a new POA which supports persistent object references.
private  org.omg.CosNaming.NamingContextExt findNameService()
          Looks up and returns a proxy Name Server CORBA object which can be used to access the name server.
 iInstrumentController.InstrumentController getInstrumentControllerReference(java.lang.String InstrumentControllerTaskName)
          Returns a CORBA reference to the instrument controller interface associated with the instrument controller which was specified as part of the argument sequence.
 org.omg.CosNaming.NamingContextExt getNameServiceReference()
          Returns a reference to the CORBA name service which was resolved when the class was instantiated.
 org.omg.CORBA.ORB getORB()
          Returns a reference to the ORB singleton.
 iParameterNoticeBoard.ParameterNoticeBoardSupplier getParameterNoticeBoardReference()
          Returns a CORBA reference to the parameter noticeboard.
 org.omg.PortableServer.POA getPOA()
          Returns a reference to a POA which was setup to create objects with persistent IOR references
private  void InitialiseCORBAHelper(java.lang.String[] args, java.lang.String POAName)
          Will be used to initialise the CORBA helper but no persistent reference policy will be created for this ORB/POA.
(package private)  void InitialiseCORBAHelper(java.lang.String[] args, java.lang.String ORBPersistentPort, java.lang.String ORBServerID, java.lang.String POAName)
          Initialise the ICS CORBA helper class.
static void main(java.lang.String[] args)
          This is the main routine and can be used to test the class
 void storeReferenceInNameService(org.omg.PortableServer.Servant ActiveServant, java.lang.String Context, java.lang.String NamingServiceLocation)
          Store a given CORBA servant reference to the name service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ORBName

private java.lang.String ORBName
This is the name of the ORB which will be used in the event of one not been supplied.


POAName

private java.lang.String POAName
This is the name of the POA which will be used in the event of one not been supplied.


COSNameServiceHost

private java.lang.String COSNameServiceHost
The machine which is hosting the name service


ParameterNoticeBoard

private iParameterNoticeBoard.ParameterNoticeBoardSupplier ParameterNoticeBoard
This is a reference to the parameter noticeboard;


rootPOA

private org.omg.PortableServer.POA rootPOA
This is the root POA of the CORBA system


Poa

private org.omg.PortableServer.POA Poa
This is a POA which is to be created. All references created using this ORB will have persistent references


Orb

private org.omg.CORBA.ORB Orb
A reference to the the ORB singleton for this process


rootNamingServiceContext

private org.omg.CosNaming.NamingContextExt rootNamingServiceContext
This is a reference to the top level context in the naming service


NameServicePortNumber

private int NameServicePortNumber
This is the port number of the name service which by default is 35777


ClassInstantiated

static boolean ClassInstantiated
Used to ensure that only ever one instance of this class exists in a process.

Constructor Detail

OCSCORBAHelper

public OCSCORBAHelper(java.lang.String[] args,
                      java.util.Properties CORBAHelperProperties)
               throws UnableToFindNameServerException,
                      java.lang.Exception
The constructor. This will initialise the ORB for use and retrieve a reference to the top level context of the name server. Furthermore, if the user has specified a persistent port in the properties, it creates a new POA which has persistent IOR policy which can be accessed using the getPOA() method.

Note that this method performs the configuration necessary to create persistent references in jacorb and the Sun ORB. Should another ORB be used, it will need to be configured further.

Parameters:
args - This should contain the command line arguments which were passed into the application. These may contain options which could modify the behaviour of the ORB.

CORBAHelperProperties - A set of properties which will be used by the class to configure the ORB help. The details of the possible properties which can be set are highlighted in the table below :

Property Meaning
PersistentPortNumber The port for the task to bind to. If not specified then a random port will be used but the ORB will not create persistent references.
COSNameServiceHost This is the machine which is hosting the COS name service. The default is localhost
ORBName The name of the ORB server. Defaults to DEFAULTORB
POAName The is the name of the default POA which is created. The default is DEFAULTPOA
COSNameServicePortNumber The port to be used to talk to the COS name service. Defaults to 35777 if not specified.

Throws:
UnableToFindNameServerException
java.lang.Exception
See Also:
getPOA()

OCSCORBAHelper

public OCSCORBAHelper(java.lang.String[] args,
                      java.lang.String ORBPersistentPort,
                      java.lang.String ORBServerID,
                      java.lang.String POAName)
               throws UnableToFindNameServerException,
                      java.lang.Exception
The constructor. This will initialise the ORB for use and retrieve a reference to the top level context of the name server. Furthermore it creates a new POA which has persistent IOR policy which can be accessed using the getPOA() method.

Note that this method performs the configuration necessary to create persistent references in jacorb and the Sun ORB. Should another ORB be used, it will need to be configured further.

Parameters:
args - This should contain the command line arguments which were passed into the application. These may contain options which could modify the behaviour of the ORB.

ORBPersistentPort - A host unique port number which will be used by this CORBA server to maintain persistent object references.

ORBServerID - A string which will be used in defining the persistent object reference for this process.

POAName - This is the name to give to the POA which will be created with a persistent policy.

Throws:
UnableToFindNameServerException
java.lang.Exception
See Also:
getPOA()

OCSCORBAHelper

public OCSCORBAHelper(java.lang.String[] args,
                      java.lang.String ORBPersistentPort,
                      java.lang.String ORBServerID,
                      java.lang.String POAName,
                      java.lang.String COSNameServiceHost)
               throws UnableToFindNameServerException,
                      java.lang.Exception
The constructor. This will initialise the ORB for use and retrieve a reference to the top level context of the name server. Furthermore it creates a new POA which has persistent IOR policy which can be accessed using the getPOA() method.

Note that this method performs the configuration necessary to create persistent references in jacorb and the Sun ORB. Should another ORB be used, it will need to be configured further.

Parameters:
args - This should contain the command line arguments which were passed into the application. These may contain options which could modify the behaviour of the ORB.

ORBPersistentPort - A host unique port number which will be used by this CORBA server to maintain persistent object references.

ORBServerID - A string which will be used in defining the persistent object reference for this process.

POAName - This is the name to give to the POA which will be created with a persistent policy.

COSNameServiceHost - This is the name of the machine which is to host the name service.
Throws:
UnableToFindNameServerException
java.lang.Exception
See Also:
getPOA()

OCSCORBAHelper

public OCSCORBAHelper(java.lang.String[] args,
                      java.lang.String POAName,
                      int COSNameServicePortNumber,
                      java.lang.String COSNameServiceHost)
               throws UnableToFindNameServerException,
                      java.lang.Exception
The constructor. This will initialise the ORB for use and retrieve a reference to the top level context of the name server. It will create a POA which does not have a persistent IOR reference which can be referenced using the getPOA() method.

Parameters:
args - This should contain the command line arguments which were passed into the application. These may contain options which could modify the behaviour of the ORB.

POAName - This is the name of the POA which is to be created
COSNameServicePortNumber - This is the port number upon which we expect to find the COS Name service
COSNameServiceHost - This is the name of the machine which is hosting the COS name service
Throws:
UnableToFindNameServerException
java.lang.Exception
See Also:
getPOA()

OCSCORBAHelper

public OCSCORBAHelper(java.lang.String[] args,
                      java.lang.String POAName,
                      int COSNameServicePortNumber)
               throws UnableToFindNameServerException,
                      java.lang.Exception
The constructor. This will initialise the ORB for use and retrieve a reference to the top level context of the name server. It will create a POA which does not have a persistent IOR reference which can be referenced using the getPOA() method.

Parameters:
args - This should contain the command line arguments which were passed into the application. These may contain options which could modify the behaviour of the ORB.

POAName - This is the name of the POA which is to be created
COSNameServicePortNumber - This is the port number upon which we expect to find the COS Name service
Throws:
UnableToFindNameServerException
java.lang.Exception
See Also:
getPOA()

OCSCORBAHelper

public OCSCORBAHelper(java.lang.String[] args,
                      java.lang.String POAName,
                      java.lang.String COSNameServiceHost)
               throws UnableToFindNameServerException,
                      java.lang.Exception
The constructor. This will initialise the ORB for use and retrieve a reference to the top level context of the name server. It will create a POA which does not have a persistent IOR reference which can be referenced using the getPOA() method.

Parameters:
args - This should contain the command line arguments which were passed into the application. These may contain options which could modify the behaviour of the ORB.

POAName - This is the name of the POA which is to be created
COSNameServiceHost - This is the name of the machine which is hosting the COS name service
Throws:
UnableToFindNameServerException
java.lang.Exception
See Also:
getPOA()

OCSCORBAHelper

public OCSCORBAHelper(java.lang.String[] args,
                      java.lang.String POAName)
               throws UnableToFindNameServerException,
                      java.lang.Exception
The constructor. This will initialise the ORB for use and retrieve a reference to the top level context of the name server. It will create a POA which does not have a persistent IOR reference which can be referenced using the getPOA() method.

Parameters:
args - This should contain the command line arguments which were passed into the application. These may contain options which could modify the behaviour of the ORB.

POAName - This is the name of the POA which is to be created
Throws:
UnableToFindNameServerException
java.lang.Exception
See Also:
getPOA()
Method Detail

InitialiseCORBAHelper

void InitialiseCORBAHelper(java.lang.String[] args,
                           java.lang.String ORBPersistentPort,
                           java.lang.String ORBServerID,
                           java.lang.String POAName)
                     throws UnableToFindNameServerException,
                            java.lang.Exception
Initialise the ICS CORBA helper class. A POA with a persistent reference policy will be created.

Note that this method performs the configuration necessary to create persistent references in jacorb and the Sun ORB. Should! another ORB be used, it will need to be configured further.

Parameters:
args - This should contain the command line arguments which were passed into the application. These may contain options which could modify the behaviour of the ORB.

ORBPersistentPort - A host unique port number which will be used by this CORBA server to maintain persistent object references.

ORBServerID - A string which will be used in defining the persistent object reference for this process.

POAName - This is the name to give to the POA which will be created with a persistent policy.

Throws:
UnableToFindNameServerException
java.lang.Exception
See Also:
getPOA()

InitialiseCORBAHelper

private void InitialiseCORBAHelper(java.lang.String[] args,
                                   java.lang.String POAName)
                            throws UnableToFindNameServerException,
                                   java.lang.Exception
Will be used to initialise the CORBA helper but no persistent reference policy will be created for this ORB/POA.

Parameters:
args - Command line arguments which will be passed to the ORB.
POAName - This is the name of the name of the POA.
Throws:
UnableToFindNameServerException - If the name service cannot be contacted.
java.lang.Exception
See Also:
getPOA()

createNewPOA

public org.omg.PortableServer.POA createNewPOA(java.lang.String POAIdentifier)
                                        throws UnableToCreatePOA
This will be used to create a new POA which supports persistent object references. This new POA is returned to the caller.

Parameters:
POAIdentifier - The identifier which is to be associated with the POA

Returns:
POA

The POA which was created by the method.

Throws:
UnableToCreatePOA - If we are unable to create the POA for whatever reason


findNameService

private org.omg.CosNaming.NamingContextExt findNameService()
                                                    throws UnableToFindNameServerException
Looks up and returns a proxy Name Server CORBA object which can be used to access the name server. Any failure to resolve the name server will result in an exception. The method expects the ORB which is specified to have been initialised and will use whatever configuration that was specified when it was bootstrapped in order to locate the name server.

Returns:
NamingContextExt

A reference to root naming context in the name server.

Throws:
UnableToFindNameServerException - When unable to locate the name server


getPOA

public org.omg.PortableServer.POA getPOA()
Returns a reference to a POA which was setup to create objects with persistent IOR references

Returns:
POA

The POA which was created when the class was instantiated.

See Also:
createNewPOA(java.lang.String)

getORB

public org.omg.CORBA.ORB getORB()
Returns a reference to the ORB singleton.

Returns:
ORB - The ORB singleton

getNameServiceReference

public org.omg.CosNaming.NamingContextExt getNameServiceReference()
Returns a reference to the CORBA name service which was resolved when the class was instantiated.

Returns:
NamingContextExt The top level naming context of the COS name service.

getInstrumentControllerReference

public iInstrumentController.InstrumentController getInstrumentControllerReference(java.lang.String InstrumentControllerTaskName)
                                                                            throws UnableToLocateInstrumentController
Returns a CORBA reference to the instrument controller interface associated with the instrument controller which was specified as part of the argument sequence.

Parameters:
InstrumentControllerTaskName - This is the name of the instrument controller task which we are to locate

Throws:
UnableToLocateInstrumentController - Unable to find the details of the instrument controller which was specified in the name service

getParameterNoticeBoardReference

public iParameterNoticeBoard.ParameterNoticeBoardSupplier getParameterNoticeBoardReference()
                                                                                    throws UnableToLocateParameterNoticeBoard
Returns a CORBA reference to the parameter noticeboard. The method will attempt to look up the object reference in the name service which was resolved when this class was instantiated.

Returns:
ParameterNoticeBoardSupplier A reference to the parameter noticeboard CORBA object. This can then be directly used to interact with the parameter noticeboard.
Throws:
UnableToLocateParameterNoticeBoard - When unable to resolve the reference to the parameter noticeboard from the name service.


createNamingServiceContext

public void createNamingServiceContext(java.lang.String Context)
                                throws java.lang.Exception
Creates a new context in the naming service. The context can be specified as having multiple levels such as /level0/level1/level2. This method is more powerful than the standard OMG methods as it permits the multiple embedded contexts to be created in a single call

Parameters:
Context - This is the name of the context to be created in the naming service. This should take the form of ContextA/ContextB.

Throws:
java.lang.Exception - This is thrown if there are any problems creating the new context.

storeReferenceInNameService

public void storeReferenceInNameService(org.omg.PortableServer.Servant ActiveServant,
                                        java.lang.String Context,
                                        java.lang.String NamingServiceLocation)
                                 throws java.lang.Exception
Store a given CORBA servant reference to the name service. It is possible to specify the context of the object reference in which it is to be stored which will be created automatically if it does not already exist.

Parameters:
ActiveServant - This is an active servant which is to be stored in the naming service.

Context - This is the full context in the name service in which the object reference is to be stored. This should be left null if it is to be stored in the top level context of the name service.

For example, the following are valid contexts

  • InstrumentController/ParameterNoticeBoard
  • SubAction

Do not specify the trailing / symbol.

Note that if the context does not already exist in the COS name service, it will be automatically created.

NamingServiceLocation - This is the label with which the object will be stored in the naming service.

Throws:
org.omg.PortableServer.POAPackage.ServantNotActive - The servant which was provided has not been activated using the POA

java.lang.Exception
See Also:
createNamingServiceContext(String)

CORBAcloseDown

public void CORBAcloseDown()
Close down the CORBA communications. It destroys the root POA and the closes down the ORB.


main

public static void main(java.lang.String[] args)
This is the main routine and can be used to test the class

Parameters:
args - Command line arguments provided when started