Search in sources :

Example 1 with AcsORBProfilerImplBase

use of alma.acs.profiling.orb.AcsORBProfilerImplBase in project ACS by ACS-Community.

the class HibernateServer method run.

public void run(String[] args) {
    String iorFileName = null;
    final AcsLogger sharedLogger = AcsLoggerHelper.getInstance().getSharedLogger();
    try {
        Properties properties = System.getProperties();
        // default is JDK ORB
        boolean useJacORB = false;
        boolean profiler = 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("-profiler")) {
                profiler = true;
            }
            if (args[i].equals("-o")) {
                if (i < args.length - 1) {
                    iorFileName = args[++i];
                } else {
                    iorFileName = "DAL.ior";
                }
            }
        }
        if (useJacORB) {
            if (Integer.getInteger("ACS.logstdout", 4) < 4) {
                sharedLogger.log(AcsLogLevel.INFO, "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);
        // activate profiling
        if (orb instanceof AcsProfilingORB) {
            // This profiler will log ORB resource statistics every 10 seconds,
            // and will print every callback to requestStarted / requestFinished to stdout if the "-profiler" option is set (see above) 
            final boolean printIndividualCalls = profiler;
            AcsORBProfiler orbProfiler = new AcsORBProfilerImplBase(sharedLogger) {

                {
                    if (printIndividualCalls) {
                        debugRequestStarted = true;
                        debugRequestFinished = true;
                    }
                }
            };
            ((AcsProfilingORB) orb).registerAcsORBProfiler(orbProfiler);
        }
        // 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
        //DALImpl DALImpl = new DALImpl(args, orb, dalpoa);
        //org.omg.PortableServer.Servant servant = new WDALImpl(args, orb, dalpoa);
        org.omg.PortableServer.Servant servant = new HibernateWDALImpl(args, orb, dalpoa, sharedLogger);
        //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 = WDALHelper.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);
        } 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 (servant instanceof Recoverer) {
            ((Recoverer) servant).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 ...");
        // wait for invocations from clients
        orb.run();
        sharedLogger.log(AcsLogLevel.INFO, "JDAL exiting ORB loop ...");
    } catch (Exception e) {
        sharedLogger.log(AcsLogLevel.SEVERE, "Top level exception ", e);
    }
}
Also used : NameComponent(org.omg.CosNaming.NameComponent) FileWriter(java.io.FileWriter) Properties(java.util.Properties) NamingContext(org.omg.CosNaming.NamingContext) AcsORBProfiler(org.jacorb.orb.acs.AcsORBProfiler) AcsProfilingORB(org.jacorb.orb.acs.AcsProfilingORB) PrintWriter(java.io.PrintWriter) AcsORBProfilerImplBase(alma.acs.profiling.orb.AcsORBProfilerImplBase) POA(org.omg.PortableServer.POA) AcsProfilingORB(org.jacorb.orb.acs.AcsProfilingORB) ORB(org.omg.CORBA.ORB) AcsLogger(alma.acs.logging.AcsLogger)

Example 2 with AcsORBProfilerImplBase

use of alma.acs.profiling.orb.AcsORBProfilerImplBase in project ACS by ACS-Community.

the class AlarmSystemCorbaServer method internalInitialize.

/**
	 * Initializes the CORBA.
	 * 
	 * @param args The command line arguments
	 */
private void internalInitialize(String[] args) throws Exception {
    Properties properties = System.getProperties();
    int portNumber = Integer.parseInt(ACSPorts.getAlarmServicePort());
    // default is JDK ORB
    boolean useJacORB = false;
    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")) {
            m_logger.log(AcsLogLevel.NOTICE, "ORBacus is no longer supported, switching to JacORB.");
            useJacORB = true;
        }
        if (args[i].equals("-jacorb")) {
            useJacORB = true;
        }
    }
    if (useJacORB) {
        if (Integer.getInteger("ACS.logstdout", 4) < 4) {
            m_logger.log(AcsLogLevel.INFO, "ACS alarm service 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 alma.alarmsystem.AlarmServiceName.value, so more readable corbaloc URLs
			 * can be used
			 */
        properties.put("jacorb.orb.objectKeyMap." + alma.alarmsystem.AlarmServiceName.value, "ORB/asPOA/" + alma.alarmsystem.AlarmServiceName.value);
    } else {
        properties.put("com.sun.CORBA.POA.ORBPersistentServerPort", Integer.toString(portNumber));
    }
    orb = ORB.init(args, properties);
    // ORB profiler
    if (orb instanceof AcsProfilingORB) {
        // This profiler will log ORB resource statistics every 10 seconds,
        AcsORBProfiler orbProfiler = new AcsORBProfilerImplBase(m_logger) {

            {
            //	currently no additional call logging, could be added though via a new property
            //					debugRequestStarted = true;
            //					debugRequestFinished = true;
            }
        };
        ((AcsProfilingORB) orb).registerAcsORBProfiler(orbProfiler);
    }
    // POA stanza, use rootPOA
    // resolve RootPOA
    rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
    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);
    asPOA = rootPOA.create_POA("asPOA", rootPOA.the_POAManager(), policies);
    for (int i = 0; i < policies.length; i++) policies[i].destroy();
    // activate POA
    poaManager = rootPOA.the_POAManager();
    poaManager.activate();
    // Initialize remote logging
    try {
        ClientLogManager.getAcsLogManager().initRemoteLoggingForService(orb, true);
        m_logger.log(AcsLogLevel.DEBUG, "Remote logging initialized");
    } catch (Throwable t) {
        m_logger.log(AcsLogLevel.ERROR, "Error connecting to the remote log service");
    }
}
Also used : AcsORBProfilerImplBase(alma.acs.profiling.orb.AcsORBProfilerImplBase) AcsORBProfiler(org.jacorb.orb.acs.AcsORBProfiler) Properties(java.util.Properties) AcsProfilingORB(org.jacorb.orb.acs.AcsProfilingORB)

Example 3 with AcsORBProfilerImplBase

use of alma.acs.profiling.orb.AcsORBProfilerImplBase in project ACS by ACS-Community.

the class ACSRemoteAccess method initialize.

/**
	 * Initialize the connection.
	 * 
	 * @param theORB The ORB. 
	 *               If it is null then a new CORBA connection is initialized.
	 * @param manager A reference to the Manager
	 *                If it is null a reference is built by reading the properties.
	 */
public void initialize(ORB theORB, Manager manager) {
    isExternalORB = (theORB != null);
    this.orb = theORB;
    if (orb == null) {
        listenersDispatcher.publishReport("Initializing CORBA...");
        // ORB stanza
        java.util.Properties orbprops = java.lang.System.getProperties();
        orb = ORB.init(new String[0], orbprops);
        // POA stanza -- use RootPOA
        POA rootPOA = null;
        try {
            rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
        } catch (org.omg.CORBA.ORBPackage.InvalidName in) {
            throw new IllegalStateException("Cannot resolve RootPOA: " + in);
        }
        POAManager poaManager = rootPOA.the_POAManager();
        try {
            poaManager.activate();
        } catch (Exception e) {
            throw new IllegalStateException("POAManager activation failed." + e);
        }
        // setup ORB profiling
        try {
            if (orb instanceof AcsProfilingORB) {
                AcsORBProfiler profiler = new AcsORBProfilerImplBase(logger);
                ((AcsProfilingORB) orb).registerAcsORBProfiler(profiler);
                logger.finer("Orb profiling set up, using class " + AcsORBProfilerImplBase.class.getName());
            }
        } catch (Throwable th) {
            logger.log(Level.WARNING, "Failed to setup ORB profiling.", th);
        }
        // end of CORBA stanza
        listenersDispatcher.publishReport("CORBA initialized.");
    }
    Manager maciManager = manager;
    if (maciManager == null) {
        maciManager = resolveManagerReference();
        if (maciManager == null) {
            // HSO: Ale, should this not throw an exception?
            return;
        }
    }
    NamingContext namingContext = resolveNamingServiceContext(maciManager);
    if (namingContext == null) {
        return;
    }
    if (!resolveNotifyChannel(LOGGING_XML_CHANNEL, namingContext)) {
        return;
    }
    boolean isConsumerAdminCreated = createConsumerAdmin();
    if (!isConsumerAdminCreated) {
        return;
    }
    isInitialized = createStructuredPushConsumer();
}
Also used : AcsORBProfilerImplBase(alma.acs.profiling.orb.AcsORBProfilerImplBase) POA(org.omg.PortableServer.POA) POAManager(org.omg.PortableServer.POAManager) Manager(si.ijs.maci.Manager) NamingContext(org.omg.CosNaming.NamingContext) AcsORBProfiler(org.jacorb.orb.acs.AcsORBProfiler) POAManager(org.omg.PortableServer.POAManager) AcsProfilingORB(org.jacorb.orb.acs.AcsProfilingORB)

Aggregations

AcsORBProfilerImplBase (alma.acs.profiling.orb.AcsORBProfilerImplBase)3 AcsORBProfiler (org.jacorb.orb.acs.AcsORBProfiler)3 AcsProfilingORB (org.jacorb.orb.acs.AcsProfilingORB)3 Properties (java.util.Properties)2 NamingContext (org.omg.CosNaming.NamingContext)2 POA (org.omg.PortableServer.POA)2 AcsLogger (alma.acs.logging.AcsLogger)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 ORB (org.omg.CORBA.ORB)1 NameComponent (org.omg.CosNaming.NameComponent)1 POAManager (org.omg.PortableServer.POAManager)1 Manager (si.ijs.maci.Manager)1