Search in sources :

Example 1 with AcsJContainerEx

use of alma.JavaContainerError.wrappers.AcsJContainerEx in project ACS by ACS-Community.

the class AcsContainer method registerWithCorba.

/**
	 * To be called only once from the ctor.
	 * 
	 * @throws AcsJContainerEx
	 */
private void registerWithCorba() throws AcsJContainerEx {
    // activate the Container as a CORBA object.
    org.omg.CORBA.Object obj = m_acsCorba.activateContainer(this, m_containerName);
    if (obj == null) {
        AcsJContainerEx ex = new AcsJContainerEx();
        ex.setContextInfo("failed to register this AcsContainer with the ORB.");
        throw ex;
    }
    Container container;
    try {
        container = ContainerHelper.narrow(obj);
        if (container == null) {
            throw new NullPointerException("Container CORBA-narrow returned a null.");
        }
    } catch (Throwable thr) {
        AcsJContainerEx ex = new AcsJContainerEx();
        ex.setContextInfo("failed to narrow the AcsContainer to CORBA type Container.");
        throw ex;
    }
    m_logger.finer("AcsContainer successfully registered with the ORB as a Container");
}
Also used : AcsJContainerEx(alma.JavaContainerError.wrappers.AcsJContainerEx) Container(si.ijs.maci.Container)

Example 2 with AcsJContainerEx

use of alma.JavaContainerError.wrappers.AcsJContainerEx in project ACS by ACS-Community.

the class ContainerSealant method createContainerSealant.

/**
	 * Creates a ContainerSealant and uses it as the invocation handler for the returned dynamic proxy
	 * which implements <code>corbaInterface</code>.
	 * 
	 * @param corbaInterface  the interface that the created sealant will implement;
	 *                         this should be the component's or offshoot's xxxOperations interface.
	 * @param component  the component/offshoot implementation class, or any translator class
	 *                    in front of the component implementation.
	 *                    <code>componentImpl</code> must implement <code>corbaInterface</code>
	 *                    so that the sealant can forward calls to the component. <br>
	 *                    Note about usage of java generics: Ideally this would be declared "T" instead of "Object", 
	 *                    but did not get it to work with that...
	 * @param name  the component instance name (used for logging) 
	 * @param isOffShoot true if the <code>component</code> object is actually an offshoot of a component
	 * @param logger  logger to be used by this class 
	 * @param componentContextCL  classloader used for {@link Thread#setContextClassLoader(java.lang.ClassLoader setContextClassLoader)}
	 *        before component method gets invoked. (after the call, the old context CL will be restored.)
	 * @param methodNamesExcludedFromInvocationLogging  
	 * @return  an instance of <code>corbaInterface</code> that intercepts calls to
	 *           <code>componentImpl</code> and forwards them if restrictions allow this.
	 * @throws ContainerException if the given <code>component</code> Object does not implement the given <code>corbaInterface</code>. 
	 */
public static <T> T createContainerSealant(Class<T> corbaInterface, Object component, String name, boolean isOffShoot, Logger logger, ClassLoader componentContextCL, String[] methodNamesExcludedFromInvocationLogging) throws AcsJContainerEx {
    if (!corbaInterface.isInstance(component)) {
        AcsJContainerEx ex = new AcsJContainerEx();
        ex.setContextInfo("sealant factory: component " + component.getClass().getName() + " must implement the sealant interface " + corbaInterface.getClass().getName());
        throw ex;
    }
    InterceptionHandlerFactory interceptionHandlerFactory = new ComponentInterceptionHandlerFactory(name, isOffShoot, logger, methodNamesExcludedFromInvocationLogging);
    return DynamicInterceptor.createDynamicInterceptor(corbaInterface, component, logger, componentContextCL, interceptionHandlerFactory);
}
Also used : AcsJContainerEx(alma.JavaContainerError.wrappers.AcsJContainerEx) InterceptionHandlerFactory(alma.acs.monitoring.DynamicInterceptor.InterceptionHandlerFactory)

Example 3 with AcsJContainerEx

use of alma.JavaContainerError.wrappers.AcsJContainerEx in project ACS by ACS-Community.

the class AcsContainerRunner method setOptions.

/**
	 * Parses commandline and property options.
	 * 
	 * @param args		as received by main()
	 */
void setOptions(String[] args) throws AcsJContainerEx {
    // -- prepare arg parser
    CmdLineArgs cmdArgs = new CmdLineArgs();
    // container name
    CmdLineRegisteredOption optContainerName = new CmdLineRegisteredOption("-containerName", 1);
    cmdArgs.registerOption(optContainerName);
    // container port; TODO unify port argument / property with CDB, C++, etc., abstract from ORB option
    CmdLineRegisteredOption optContainerPort = new CmdLineRegisteredOption("-OAPort", "-OAport", 1);
    cmdArgs.registerOption(optContainerPort);
    // CmdLineRegisteredOption optContainerPort2 = new CmdLineRegisteredOption("-OAport", 1);
    // cmdArgs.registerOption(optContainerPort2);
    // manager reference
    CmdLineRegisteredOption optManagerLoc = new CmdLineRegisteredOption("-manager", "-m", 1);
    cmdArgs.registerOption(optManagerLoc);
    // recovery mode
    CmdLineRegisteredOption optRecoveryMode = new CmdLineRegisteredOption("-recovery", "-r", 0);
    cmdArgs.registerOption(optRecoveryMode);
    // no-recovery mode
    CmdLineRegisteredOption optNoRecoveryMode = new CmdLineRegisteredOption("-norecovery", "-nr", 0);
    cmdArgs.registerOption(optNoRecoveryMode);
    // -- parse and set args
    try {
        cmdArgs.parseArgs(args);
        // -- container name
        if (cmdArgs.isSpecified(optContainerName)) {
            m_containerName = cmdArgs.getValues(optContainerName)[0].trim();
        } else {
            m_containerName = System.getProperty(CONTAINER_NAME_PROPERTYNAME);
        }
        // -- container port
        if (cmdArgs.isSpecified(optContainerPort)) {
            m_containerPort = Integer.parseInt(cmdArgs.getValues(optContainerPort)[0]);
        } else {
            // default port -- C++ container uses -ORBEndpoint, default 3 0 5 0
            m_containerPort = OrbConfigurator.ORB_DEFAULT_PORT;
        }
        // -- manager
        if (cmdArgs.isSpecified(optManagerLoc)) {
            m_managerLoc = cmdArgs.getValues(optManagerLoc)[0].trim();
        } else if (System.getProperty(MANAGER_PROPERTYNAME) != null) {
            m_managerLoc = System.getProperty(MANAGER_PROPERTYNAME).trim();
        } else {
            // default = localhost
            m_managerLoc = AcsManagerProxy.getLocalManagerCorbaloc();
        }
        if (cmdArgs.isSpecified(optRecoveryMode)) {
            m_recoveryModeOverride = Boolean.TRUE;
            if (cmdArgs.isSpecified(optNoRecoveryMode)) {
                m_logger.warning("Conflicting command line options for recovery mode: both -r and -nr are specified. Will use -r.");
            }
        } else if (cmdArgs.isSpecified(optNoRecoveryMode)) {
            m_recoveryModeOverride = Boolean.FALSE;
        }
        Integer starttimeDelayMillisProperty = Integer.getInteger(CONTAINER_STARTTIME_DELAY_MILLIS_PROPERTYNAME);
        if (starttimeDelayMillisProperty != null) {
            initialSleeptimeMillis = starttimeDelayMillisProperty.intValue();
        }
    } catch (Throwable thr) {
        AcsJContainerEx ex = new AcsJContainerEx(thr);
        ex.setContextInfo("incorrect or missing arguments.");
        throw ex;
    }
}
Also used : AcsJContainerEx(alma.JavaContainerError.wrappers.AcsJContainerEx) CmdLineRegisteredOption(alma.acs.util.CmdLineRegisteredOption) CmdLineArgs(alma.acs.util.CmdLineArgs)

Example 4 with AcsJContainerEx

use of alma.JavaContainerError.wrappers.AcsJContainerEx in project ACS by ACS-Community.

the class AcsContainer method initialize.

/**
	 * Container initialization such as logging in to the manager, configuring logging, initializing the alarm system.
	 * This is taken out of the ctor just to keep is lean and be able to instantiate a minimum container for testing.
	 * @throws AcsJContainerServicesEx for any serious issue that should make container start fail.
	 */
void initialize() throws AcsJContainerEx {
    // CDB ref 
    try {
        org.omg.CORBA.Object dalObj = m_managerProxy.get_service("CDB", false);
        sharedCdbRef = DALHelper.narrow(dalObj);
    } catch (Exception ex) {
        m_logger.log(Level.SEVERE, "Failed to access the CDB.", ex);
        throw new AcsJContainerEx(ex);
    }
    if (sharedCdbRef == null) {
        m_logger.log(Level.SEVERE, "Failed to access the CDB.");
        throw new AcsJContainerEx();
    }
    // CDB container config (must be done before manager login)
    initFromCdb(true);
    // TODO: sharedCdbRef.add_change_listener / listen_for_changes and call initFromCdb(false) on change.
    // manager login
    System.out.println(ContainerOperations.ContainerStatusMgrInitBeginMsg);
    // TODO: Use CDB attributes ManagerRetry and Recovery for manager login.
    loginToManager(m_managerRetry);
    System.out.println(ContainerOperations.ContainerStatusMgrInitEndMsg);
    // init logging 
    logConfig = ClientLogManager.getAcsLogManager().getLogConfig();
    // logConfig.setInternalLogger(m_logger);
    logConfig.setCDBLoggingConfigPath("MACI/Containers/" + m_containerName);
    logConfig.setCDB(sharedCdbRef);
    try {
        logConfig.initialize(false);
    } catch (LogConfigException ex) {
        // if the CDB can't be read, we still want to run the container, thus we only log the problem here
        m_logger.log(Level.FINE, "Failed to configure logging (default values will be used).", ex);
    }
    // init the alarm system
    //
    // TODO: clean up the construction of CS which is ad-hoc implemented right before ACS 7.0
    // in order to allow CERN alarm libs to get their static field for ContainerServices set.
    // Currently the alarm system acts under the container name.
    // Setting of static fields in the AS classes should be removed altogether.
    // TODO: maybe we should pass a alarms@container logger instead of the normal one
    m_alarmContainerServices = new ContainerServicesImpl(m_managerProxy, sharedCdbRef, m_acsCorba.createPOAForComponent("alarmSystem"), m_acsCorba, m_logger, 0, m_containerName, null, containerThreadFactory) {

        private AcsLogger alarmLogger;

        public AcsLogger getLogger() {
            if (alarmLogger == null) {
                // @TODO perhaps get a container logger "alarms@containername"
                alarmLogger = ClientLogManager.getAcsLogManager().getLoggerForContainer(getName());
            }
            return alarmLogger;
        }
    };
    try {
        ACSAlarmSystemInterfaceFactory.init(m_alarmContainerServices);
    } catch (Throwable thr) {
        AcsJContainerEx ex = new AcsJContainerEx(thr);
        ex.setContextInfo("Error initializing the alarm system factory");
        throw ex;
    }
    // enable (throttle) alarms from the logging subsystem
    ClientLogManager.LogAlarmHandler logAlarmHandler = new ClientLogManager.LogAlarmHandler() {

        @Override
        public void raiseAlarm(String faultFamily, String faultMember, int faultCode) throws AcsJCouldntPerformActionEx {
            m_alarmContainerServices.getAlarmSource().raiseAlarm(faultFamily, faultMember, faultCode);
        }

        @Override
        public void clearAlarm(String faultFamily, String faultMember, int faultCode) throws AcsJCouldntPerformActionEx {
            m_alarmContainerServices.getAlarmSource().clearAlarm(faultFamily, faultMember, faultCode);
        }
    };
    ClientLogManager.getAcsLogManager().enableLoggingAlarms(logAlarmHandler);
    // init the BACI framework
    try {
        Class<?> clazz = Class.forName("alma.ACS.jbaci.BACIFramework");
        Object baciFramework = clazz.getField("INSTANCE").get(null);
        clazz.getMethod("initialize", ThreadFactory.class).invoke(baciFramework, containerThreadFactory);
    } catch (Exception e) {
        AcsJContainerEx ex = new AcsJContainerEx(e);
        ex.setContextInfo("Error initializing the BACI framework");
        // TODO: This is temporary, just to avoid test crashes. The exception should be actually thrown
        m_logger.log(AcsLogLevel.WARNING, "Error initializing the BACI framework, container will run withouth the BACI Framework initialized", ex);
    //throw ex;
    }
    // unleash any waiting ORB threads that were held until container init has finished
    containerStartOrbThreadGate.countDown();
}
Also used : AcsJContainerEx(alma.JavaContainerError.wrappers.AcsJContainerEx) ThreadFactory(java.util.concurrent.ThreadFactory) ClientLogManager(alma.acs.logging.ClientLogManager) LogConfigException(alma.acs.logging.config.LogConfigException) AcsJException(alma.acs.exceptions.AcsJException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) LogConfigException(alma.acs.logging.config.LogConfigException) AcsLogger(alma.acs.logging.AcsLogger)

Example 5 with AcsJContainerEx

use of alma.JavaContainerError.wrappers.AcsJContainerEx in project ACS by ACS-Community.

the class AcsEmbeddedContainerRunner method checkReadyToRun.

void checkReadyToRun(String otherMsg) throws AcsJContainerEx {
    String msg = "";
    if (m_managerLoc == null || m_managerLoc.trim().length() == 0) {
        msg += "no manager-location specified; ";
    }
    if (m_containerName == null || m_containerName.trim().length() == 0) {
        msg += "no container name specified; ";
    }
    if (otherMsg != null) {
        msg += otherMsg;
    }
    if (msg.length() > 0) {
        AcsJContainerEx ex = new AcsJContainerEx();
        ex.setContextInfo("can't start container because of missing information: " + msg);
        throw ex;
    }
}
Also used : AcsJContainerEx(alma.JavaContainerError.wrappers.AcsJContainerEx)

Aggregations

AcsJContainerEx (alma.JavaContainerError.wrappers.AcsJContainerEx)27 POA (org.omg.PortableServer.POA)6 Object (org.omg.CORBA.Object)4 Policy (org.omg.CORBA.Policy)4 AdapterAlreadyExists (org.omg.PortableServer.POAPackage.AdapterAlreadyExists)4 InvalidPolicy (org.omg.PortableServer.POAPackage.InvalidPolicy)4 AcsJUnexpectedExceptionEx (alma.ACSErrTypeCommon.wrappers.AcsJUnexpectedExceptionEx)3 AdapterNonExistent (org.omg.PortableServer.POAPackage.AdapterNonExistent)3 AcsJContainerServicesEx (alma.JavaContainerError.wrappers.AcsJContainerServicesEx)2 AcsJException (alma.acs.exceptions.AcsJException)2 AcsLogger (alma.acs.logging.AcsLogger)2 LogConfigException (alma.acs.logging.config.LogConfigException)2 StopWatch (alma.acs.util.StopWatch)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 Servant (org.omg.PortableServer.Servant)2 CouldntAccessComponentEx (alma.ACSErrTypeCommon.CouldntAccessComponentEx)1 CouldntAccessPropertyEx (alma.ACSErrTypeCommon.CouldntAccessPropertyEx)1 TypeNotSupportedEx (alma.ACSErrTypeCommon.TypeNotSupportedEx)1 AcsComponentClassLoader (alma.acs.classloading.AcsComponentClassLoader)1 ComponentLifecycle (alma.acs.component.ComponentLifecycle)1