Search in sources :

Example 1 with POA

use of org.omg.PortableServer.POA in project ACS by ACS-Community.

the class Server method run.

public void run(String[] args) {
    String iorFileName = null;
    final Logger sharedLogger = ClientLogManager.getAcsLogManager().getLoggerForApplication(CDB_LOGGER_NAME, true);
    try {
        Properties properties = System.getProperties();
        // default is JDK ORB
        boolean useJacORB = false;
        int portNumber = Integer.parseInt(ACSPorts.getCDBPort());
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-OAport") || args[i].equals("-OAPort")) {
                if (i < args.length - 1) {
                    portNumber = Integer.valueOf(args[++i]).intValue();
                }
            }
            if (args[i].equals("-OAIAddr")) {
                if (i < args.length - 1) {
                    properties.put("OAIAddr", args[++i]);
                }
            }
            if (args[i].equals("-orbacus")) {
                sharedLogger.log(AcsLogLevel.NOTICE, "ORBacus is no longer supported, switching to JacORB.");
                //System.err.println(
                //	"ORBacus is no longer supported, switching to JacORB.");
                useJacORB = true;
            }
            if (args[i].equals("-jacorb")) {
                useJacORB = true;
            }
            if (args[i].equals("-o")) {
                if (i < args.length - 1) {
                    iorFileName = args[++i];
                } else {
                    iorFileName = "DAL.ior";
                }
            }
        }
        if (useJacORB) {
            sharedLogger.log(AcsLogLevel.DELOUSE, "DALfs will use JacORB ORB");
            properties.put("org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB");
            properties.put("org.omg.CORBA.ORBSingletonClass", "org.jacorb.orb.ORBSingleton");
            // port
            properties.put("OAPort", Integer.toString(portNumber));
            // ORB implementation name
            properties.put("jacorb.implname", "ORB");
            /*
				 * by setting the following property, the ORB will
				 * accept client requests targeted at the object with
				 * key "CDB", so more readable corbaloc URLs
				 * can be used
				 */
            properties.put("jacorb.orb.objectKeyMap.CDB", "ORB/dalPOA/CDB");
        } else {
            properties.put("com.sun.CORBA.POA.ORBPersistentServerPort", Integer.toString(portNumber));
        }
        // create and initialize the ORB
        ORB orb = ORB.init(args, properties);
        // get reference to rootpoa & activate the POAManager
        POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
        /* create a user defined poa for the naming contexts */
        org.omg.CORBA.Policy[] policies = new org.omg.CORBA.Policy[2];
        policies[0] = rootpoa.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID);
        if (useJacORB)
            policies[1] = rootpoa.create_lifespan_policy(LifespanPolicyValue.PERSISTENT);
        else
            policies[1] = rootpoa.create_lifespan_policy(LifespanPolicyValue.TRANSIENT);
        POA dalpoa = rootpoa.create_POA("dalPOA", rootpoa.the_POAManager(), policies);
        for (int i = 0; i < policies.length; i++) policies[i].destroy();
        rootpoa.the_POAManager().activate();
        // create servant and register it with the ORB
        final WDALImpl servantDelegate = new WDALImpl(args, orb, dalpoa, sharedLogger);
        WJDALOperations topLevelServantDelegate = servantDelegate;
        if (Boolean.getBoolean(LOG_CDB_CALLS_PROPERTYNAME)) {
            // Currently we only intercept the functional IDL-defined methods, by wrapping servantDelegate.
            // If we want to also intercept the CORBA admin methods, then *servant* should be wrapped with a dynamic proxy instead.
            WJDALOperations interceptingServantDelegate = SimpleCallInterceptor.createSimpleInterceptor(WJDALOperations.class, servantDelegate, sharedLogger);
            topLevelServantDelegate = interceptingServantDelegate;
        }
        final Servant servant = new WJDALPOATie(topLevelServantDelegate);
        //create object id
        byte[] id = { 'C', 'D', 'B' };
        //activate object
        dalpoa.activate_object_with_id(id, servant);
        // get object reference from the servant
        org.omg.CORBA.Object ref = dalpoa.servant_to_reference(servant);
        jdal = JDALHelper.narrow(ref);
        // try to bind it in IOR
        if (useJacORB) {
        // nothing to do here
        } else {
            ((com.sun.corba.se.internal.Interceptors.PIORB) orb).register_initial_reference("CDB", rootpoa.servant_to_reference(servant));
        }
        // register in name service if available
        try {
            // get the root naming context
            org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
            NamingContext ncRef = NamingContextHelper.narrow(objRef);
            // Bind the object reference in naming
            NameComponent nc = new NameComponent("CDB", "");
            NameComponent[] path = { nc };
            ncRef.rebind(path, jdal);
        }// is not set at all with the ORBInitRef.NameService property
         catch (Exception e1) {
            sharedLogger.log(AcsLogLevel.NOTICE, "JDAL is NOT registered in the name service because of: " + e1);
        }
        if (Integer.getInteger("ACS.logstdout", 4) < 4) {
            sharedLogger.log(AcsLogLevel.INFO, "JDAL is listening on " + ACSPorts.getIP() + ":" + portNumber + "/CDB");
        }
        // recover (notify) clients
        if (servantDelegate instanceof Recoverer) {
            ((Recoverer) servantDelegate).recoverClients();
        }
        if (iorFileName != null) {
            // write the object reference to a file
            PrintWriter iorFile = new PrintWriter(new FileWriter(iorFileName));
            iorFile.println(orb.object_to_string(jdal));
            iorFile.close();
        }
        sharedLogger.log(AcsLogLevel.INFO, "JDAL is ready and waiting ...");
        // GCH 2006-11-13
        // Here we put also a println to be sure that the message
        // ALWAYS appears on standart output, also if the logging level 
        // is put higher than INFO.
        // This is needed because the ACS startup scripts wait for this message
        // to declare complete the startup of the CDB. 
        System.out.println("JDAL is ready and waiting ...");
        // preload cache
        new Thread(new Runnable() {

            public void run() {
                preloadCache(servantDelegate.getDALImplDelegate(), sharedLogger);
            }
        }, "preload-cache").start();
        // Init remote Logging
        try {
            ClientLogManager.getAcsLogManager().initRemoteLoggingForService(orb, true);
        } catch (Throwable t) {
            sharedLogger.log(AcsLogLevel.ERROR, "Error initializing the remote logging");
        }
        // wait for invocations from clients
        orb.run();
        sharedLogger.log(AcsLogLevel.INFO, "JDAL exiting ORB loop ...");
    } catch (Exception e) {
        sharedLogger.log(AcsLogLevel.NOTICE, "ERROR: " + e);
        e.printStackTrace(System.out);
    }
}
Also used : WJDALOperations(com.cosylab.CDB.WJDALOperations) NameComponent(org.omg.CosNaming.NameComponent) FileWriter(java.io.FileWriter) Logger(java.util.logging.Logger) Properties(java.util.Properties) NamingContext(org.omg.CosNaming.NamingContext) Servant(org.omg.PortableServer.Servant) PrintWriter(java.io.PrintWriter) POA(org.omg.PortableServer.POA) WJDALPOATie(com.cosylab.CDB.WJDALPOATie) ORB(org.omg.CORBA.ORB)

Example 2 with POA

use of org.omg.PortableServer.POA in project ACS by ACS-Community.

the class AcsCorba method createPOAForComponent.

/**
	 * Creates a new POA that is responsible for exactly one component.
	 * Dependent CORBA objects (offshoots) are activated through a child POA. 
	 * The new POA is created as a child of the shared ComponentPOA.
	 * <p>
	 * The new component POA uses its own POA manager, which allows discarding requests for this component 
	 * (w/o discarding requests for other components, the container, or even this component's offshoots).  
	 * 
	 * @param compName  the name of the component; used to construct the POA name by prepending "ComponentPOA_"
	 * @return the new component POA; never null.
	 * @throws AcsJContainerServicesEx  if creation of the POA fails.
	 */
public POA createPOAForComponent(String compName) throws AcsJContainerEx {
    if (m_componentPOA == null) {
        throw new IllegalStateException("Must call 'initPOAForComponents()' before 'createPOAForComponent'.");
    }
    POA compChildPOA = null;
    String compChildPOAName = "ComponentPOA_" + compName;
    try {
        try {
            // will create its own POAManager
            compChildPOA = m_componentPOA.create_POA(compChildPOAName, null, m_compPolicies);
        } catch (org.omg.PortableServer.POAPackage.AdapterAlreadyExists ex1) {
            // todo: perhaps better create a new POA, since the old POA of the same name may belong 
            // to a shutting down component for which etherealization timed out.
            // Perhaps mark a component POA as "useless" once manager calls deactivate on the container
            m_logger.warning(compChildPOAName + " already exists even though it should not. Will try to reuse it...");
            compChildPOA = m_componentPOA.find_POA(compChildPOAName, true);
        }
        compChildPOA.the_POAManager().activate();
    } catch (Throwable thr) {
        AcsJContainerEx ex = new AcsJContainerEx();
        ex.setContextInfo("failed to create POA for component " + compName);
        throw ex;
    }
    return compChildPOA;
}
Also used : AcsJContainerEx(alma.JavaContainerError.wrappers.AcsJContainerEx) POA(org.omg.PortableServer.POA) AdapterAlreadyExists(org.omg.PortableServer.POAPackage.AdapterAlreadyExists)

Example 3 with POA

use of org.omg.PortableServer.POA in project ACS by ACS-Community.

the class AcsCorba method activateOffShoot.

/**
	 * Activates an offshoot object (which is a regular CORBA object
	 * owned by a component).
	 * <p>
	 * All offshoot objects for a component are activated using a non-persistent "offshootPOA".
	 *  
	 * @param servant  the offshoot servant.
	 * @param compPOA  the POA responsible for the component which activates the offshoot.
	 * @return the activated offshoot corba object.
	 * @throws AcsJContainerServicesEx
	 */
public org.omg.CORBA.Object activateOffShoot(Servant servant, POA compPOA) throws AcsJContainerEx, AcsJUnexpectedExceptionEx {
    if (servant == null || compPOA == null) {
        String msg = "activateOffShoot called with missing parameter.";
        AcsJContainerEx ex = new AcsJContainerEx();
        ex.setContextInfo(msg);
        throw ex;
    }
    POA offshootPoa = getPOAForOffshoots(compPOA);
    org.omg.CORBA.Object actObj = null;
    try {
        offshootPoa.activate_object(servant);
        actObj = offshootPoa.servant_to_reference(servant);
        // just to provoke an exc. if something is wrong with our new object
        actObj._hash(Integer.MAX_VALUE);
        m_logger.finer("offshoot of type '" + servant.getClass().getName() + "' activated as a CORBA object.");
    } catch (Throwable thr) {
        AcsJContainerEx ex = new AcsJContainerEx(thr);
        ex.setContextInfo("failed to activate offshoot of type '" + servant.getClass().getName());
        throw ex;
    }
    return actObj;
}
Also used : AcsJContainerEx(alma.JavaContainerError.wrappers.AcsJContainerEx) POA(org.omg.PortableServer.POA) Object(org.omg.CORBA.Object)

Example 4 with POA

use of org.omg.PortableServer.POA in project ACS by ACS-Community.

the class ManagerImplSerializationTest method testContainerDie.

public void testContainerDie() throws Throwable {
    // should be something else then deafault because
    // the default is in use by the Manager
    Properties table = new Properties();
    table.put("OAPort", "12121");
    // new ORB instance
    ORB ourOrb = ORB.init(new String[0], table);
    try {
        POA rootPOA = POAHelper.narrow(ourOrb.resolve_initial_references("RootPOA"));
        // activate POA
        POAManager manager = rootPOA.the_POAManager();
        manager.activate();
    } catch (Exception e) {
        e.printStackTrace();
    }
    ContainerProxyImpl activator = new ContainerProxyImpl(clientName);
    si.ijs.maci.ClientInfo clientInfo = manager.login(activator._this(ourOrb));
    if (clientInfo == null || clientInfo.h == 0)
        fail("Unable to login to manager");
    // just destroy its ORB
    ourOrb.shutdown(true);
    // get object as it is stored in recovery store
    ManagerImpl newManager = (ManagerImpl) deserializeManager(new ManagerImpl());
    HandleDataStore activators = newManager.getContainers();
    // the client now is still in stored data
    assertEquals(activators.first(), 1);
    newManager.initialize(null, null, null, null, null);
    // now wait for timer task to remove client
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
        fail();
    }
    // since the client died the menager automaticaly log it out    
    activators = newManager.getClients();
    // not any more
    assertEquals(activators.first(), 0);
}
Also used : POA(org.omg.PortableServer.POA) POAManager(org.omg.PortableServer.POAManager) ManagerImpl(com.cosylab.acs.maci.manager.ManagerImpl) HandleDataStore(com.cosylab.acs.maci.manager.HandleDataStore) Properties(java.util.Properties) ORB(org.omg.CORBA.ORB)

Example 5 with POA

use of org.omg.PortableServer.POA in project ACS by ACS-Community.

the class ManagerImplSerializationTest method testClientDie.

public void testClientDie() {
    // should be something else then deafault because
    // the default is in use by the Manager
    Properties table = new Properties();
    table.put("OAPort", "12121");
    // new ORB instance
    ORB ourOrb = ORB.init(new String[0], table);
    try {
        POA rootPOA = POAHelper.narrow(ourOrb.resolve_initial_references("RootPOA"));
        // activate POA
        POAManager manager = rootPOA.the_POAManager();
        manager.activate();
    } catch (Exception e) {
        e.printStackTrace();
    }
    ClientProxyImpl client = new ClientProxyImpl(clientName, myManager.getManagerEngine().getLogger());
    client.login(ourOrb, manager);
    // just destroy its ORB
    ourOrb.shutdown(true);
    // get object as it is stored in recovery store
    ManagerImpl newManager = (ManagerImpl) deserializeManager(new ManagerImpl());
    HandleDataStore clients = newManager.getClients();
    // the client now is still in stored data
    assertEquals(clients.first(), 1);
    newManager.initialize(null, null, null, null, null);
    // now wait for timer task to remove client
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
        fail();
    }
    // since the client died the menager automaticaly log it out    
    clients = newManager.getClients();
    // not any more
    assertEquals(clients.first(), 0);
}
Also used : POA(org.omg.PortableServer.POA) POAManager(org.omg.PortableServer.POAManager) ManagerImpl(com.cosylab.acs.maci.manager.ManagerImpl) ClientProxyImpl(com.cosylab.acs.maci.plug.ClientProxyImpl) HandleDataStore(com.cosylab.acs.maci.manager.HandleDataStore) Properties(java.util.Properties) ORB(org.omg.CORBA.ORB)

Aggregations

POA (org.omg.PortableServer.POA)33 ORB (org.omg.CORBA.ORB)11 POAManager (org.omg.PortableServer.POAManager)10 AcsJContainerEx (alma.JavaContainerError.wrappers.AcsJContainerEx)6 Properties (java.util.Properties)5 ClientPOA (si.ijs.maci.ClientPOA)5 Servant (org.omg.PortableServer.Servant)4 ManagerImpl (com.cosylab.acs.maci.manager.ManagerImpl)3 AcsJUnexpectedExceptionEx (alma.ACSErrTypeCommon.wrappers.AcsJUnexpectedExceptionEx)2 AcsJContainerServicesEx (alma.JavaContainerError.wrappers.AcsJContainerServicesEx)2 AcsJException (alma.acs.exceptions.AcsJException)2 AcsLogger (alma.acs.logging.AcsLogger)2 AcsORBProfilerImplBase (alma.acs.profiling.orb.AcsORBProfilerImplBase)2 CDBFieldDoesNotExistEx (alma.cdbErrType.CDBFieldDoesNotExistEx)2 WrongCDBDataTypeEx (alma.cdbErrType.WrongCDBDataTypeEx)2 DummyComponent (alma.jconttest.DummyComponent)2 DummyComponentPOATie (alma.jconttest.DummyComponentPOATie)2 WDAOPOA (com.cosylab.CDB.WDAOPOA)2 HandleDataStore (com.cosylab.acs.maci.manager.HandleDataStore)2 FileWriter (java.io.FileWriter)2