use of alma.acs.container.CleaningDaemonThreadFactory in project ACS by ACS-Community.
the class ComponentClientTestCase method setUp.
/**
* Starts CORBA in the client process and connects to the manager and logger.
* <p>
* <b>Subclasses that override this method must call <code>super.setUp()</code>,
* likely before any other code in that method.</b>
*
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception {
m_logger = ClientLogManager.getAcsLogManager().getLoggerForApplication(getFullName(), true);
m_logger.info("-------------------------------");
m_logger.info("ComponentClientTestCase#setUp()");
POA rootPOA = null;
try {
acsCorba = new AcsCorba(m_logger);
rootPOA = acsCorba.initCorbaForClient(false);
connectToManager();
DAL cdb = DALHelper.narrow(m_acsManagerProxy.get_service("CDB", false));
m_threadFactory = new CleaningDaemonThreadFactory(m_namePrefix, m_logger);
m_containerServices = new ContainerServicesImpl(m_acsManagerProxy, cdb, rootPOA, acsCorba, m_logger, m_acsManagerProxy.getManagerHandle(), this.getClass().getName(), null, m_threadFactory) {
public AcsLogger getLogger() {
return m_logger;
}
};
managerClientImpl.setContainerServices(m_containerServices);
initRemoteLogging();
ACSAlarmSystemInterfaceFactory.init(m_containerServices);
} catch (Exception ex1) {
m_logger.log(Level.SEVERE, "failed to initialize the ORB, or connect to the ACS Manager, " + "or to set up the container services.", ex1);
if (acsCorba != null) {
try {
acsCorba.shutdownORB(true, false);
acsCorba.doneCorba();
} catch (Exception ex2) {
// to JUnit we want to forward the original exception ex1,
// not any other exception from cleaning up the orb
// which we would not have done without the first exception.
// Thus we simply print ex2 but let ex1 fly
ex2.printStackTrace();
}
}
throw ex1;
}
}
use of alma.acs.container.CleaningDaemonThreadFactory in project ACS by ACS-Community.
the class AdvancedComponentClient method createContainerServices.
/**
* Factory method for additional container service instances. This method should only be used by specialized clients
* such as the OMC GUI which needs independent ContainerServices instances for the plug-ins it runs.
* <p>
* Make sure to call {@link #destroyContainerServices(ContainerServices)} when done with the new CS.
*
* @param clientName
* name for {@link ContainerServices#getName()}
* @param csLogger
* logger to be used internally by the new ContainerServices instance (which is different from the Logger
* returned in {@link ContainerServices#getLogger()}).
* Since ACS 8.0 it is recommended to supply an {@link AcsLogger} instead of a plain JDK Logger because a
* plain Logger will have to be wrapped inside this method.
*/
public ContainerServices createContainerServices(String clientName, Logger csLogger) throws AcsJContainerServicesEx {
if (clientName == null) {
throw new IllegalArgumentException("clientName must not be null");
}
if (csLogger == null) {
throw new IllegalArgumentException("csLogger must not be null");
}
try {
// wrap csLogger if necessary
AcsLogger acsLogger = AcsLogger.fromJdkLogger(csLogger, null);
ThreadFactory threadFactory = new CleaningDaemonThreadFactory(clientName, csLogger);
// separately log in to the manager to get a new client handle.
// TODO: if this does not work, then we need a way to get a new handle from manager without logging in separately.
// Note that when activating components, the container receives the new handle directly from the manager.
AcsManagerProxy acsManagerProxy = m_acsManagerProxy.createInstance();
ManagerClient clImpl = new ManagerClient(clientName, acsLogger);
Client managerClient = clImpl._this(acsCorba.getORB());
acsManagerProxy.loginToManager(managerClient, 0);
int clientHandle = acsManagerProxy.getManagerHandle();
DAL cdb = DALHelper.narrow(m_acsManagerProxy.get_service("CDB", false));
ContainerServicesImpl cs = new ContainerServicesImpl(acsManagerProxy, cdb, acsCorba.getRootPOA(), acsCorba, acsLogger, clientHandle, clientName, null, threadFactory);
additionalContainerServices.put(cs, acsManagerProxy);
return cs;
} catch (Throwable thr) {
throw new AcsJContainerServicesEx(thr);
}
}
use of alma.acs.container.CleaningDaemonThreadFactory in project ACS by ACS-Community.
the class AdvancedComponentClient method destroyContainerServices.
/**
* "un-factory" method which inverts {@link #createContainerServices(String, Logger)}.
* @param cs ContainerServices instance created by {@link #createContainerServices(String, Logger)}.
*/
public void destroyContainerServices(ContainerServices cs) throws AcsJContainerServicesEx {
if (!additionalContainerServices.containsKey(cs)) {
AcsJContainerServicesEx ex = new AcsJContainerServicesEx();
ex.setContextInfo("The given ContainerServices object was not created by this AdvancedComponentClient!");
throw ex;
}
try {
ContainerServicesImpl csImpl = (ContainerServicesImpl) cs;
AcsManagerProxy acsManagerProxy = additionalContainerServices.get(cs);
acsManagerProxy.shutdownNotify();
csImpl.releaseAllComponents();
((CleaningDaemonThreadFactory) csImpl.getThreadFactory()).cleanUp();
acsManagerProxy.logoutFromManager();
additionalContainerServices.remove(cs);
csImpl.cleanUp();
} catch (Throwable thr) {
AcsJContainerServicesEx ex = new AcsJContainerServicesEx();
ex.setContextInfo("Failed to destroy additional container services instance");
throw ex;
}
}
use of alma.acs.container.CleaningDaemonThreadFactory in project ACS by ACS-Community.
the class SubsysResourceMonitorTest method setUp.
protected void setUp() throws Exception {
logger = ClientLogManager.getAcsLogManager().getLoggerForApplication(getName(), false);
logger.info("-------------------- setUp " + getName() + " --------------------");
threadFactory = new CleaningDaemonThreadFactory("monitor", logger) {
public Thread newThread(Runnable command) {
Thread newThread = super.newThread(command);
logger.info("Created thread '" + newThread.getName() + "'.");
return newThread;
}
};
// create a monitor that checks every 5 seconds
subsysResourceMonitor = new SubsysResourceMonitor(logger, threadFactory, checkDelaySeconds);
}
use of alma.acs.container.CleaningDaemonThreadFactory in project ACS by ACS-Community.
the class ComponentClient method initAcs.
private void initAcs(String managerLoc, POA rootPOA) throws Exception {
try {
ManagerClient clImpl = new ManagerClient(m_clientName, m_logger) {
public void disconnect() {
m_logger.info("disconnected from manager");
m_acsManagerProxy.logoutFromManager();
m_acsManagerProxy = null;
throw new RuntimeException("disconnected from the manager");
}
};
m_managerClient = clImpl._this(acsCorba.getORB());
m_acsManagerProxy = new AcsManagerProxy(managerLoc, acsCorba.getORB(), m_logger);
m_acsManagerProxy.loginToManager(m_managerClient, 1);
DAL cdb = DALHelper.narrow(m_acsManagerProxy.get_service("CDB", false));
m_threadFactory = new CleaningDaemonThreadFactory(m_clientName, m_logger);
m_containerServices = new ContainerServicesImpl(m_acsManagerProxy, cdb, rootPOA, acsCorba, m_logger, 0, m_clientName, null, m_threadFactory);
clImpl.setContainerServices(m_containerServices);
initAlarmSystem();
} catch (Exception ex) {
// "or to set up the container services.", ex);
if (acsCorba.getORB() != null) {
acsCorba.getORB().destroy();
}
throw ex;
}
}
Aggregations