use of alma.acs.logging.AcsLogger in project ACS by ACS-Community.
the class JacorbLoggerHelper method getLogger.
/**
* @see ACSLoggerFactory#getLogger(String)
*/
public Logger getLogger(String name) {
if (jdkAdapter == null) {
// reuse one acs logger for all jacorb loggers
AcsLogger acsLoggerDelegate = ClientLogManager.getAcsLogManager().getLoggerForCorba(JACORB_LOGGER_NAME, true);
acsLoggerDelegate.addLoggerClass(JDK14LoggerAdapter.class);
JacORBFilter logFilter = new JacORBFilter();
// AcsLogger will later update the filter log level if there are changes
logFilter.setLogLevel(acsLoggerDelegate.getLevel());
acsLoggerDelegate.setFilter(logFilter);
jdkAdapter = new JDK14LoggerAdapter(acsLoggerDelegate);
}
return jdkAdapter;
}
use of alma.acs.logging.AcsLogger 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);
}
}
use of alma.acs.logging.AcsLogger 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.logging.AcsLogger in project ACS by ACS-Community.
the class Slf4jAcsLoggerTest method validateSlf4jLogger.
private void validateSlf4jLogger(org.slf4j.Logger logger, String expectedName) {
assertNotNull(logger);
JDK14LoggerAdapter adapter = (JDK14LoggerAdapter) logger;
Logger delegateLogger = adapter.logger;
assertNotNull(delegateLogger);
assertTrue(delegateLogger instanceof AcsLogger);
assertEquals(expectedName, delegateLogger.getName());
}
use of alma.acs.logging.AcsLogger in project ACS by ACS-Community.
the class ShutdownHookTest method main.
/**
* Creates the ComponentClient "ShutdownHookTestClient" and tests its cleanup
* using calls to tearDown coming both from the shutdown hook and from explicit invocations.
* <p>
* In the <code>tearDown</code> method, it enables FINE logs for stdout
* before calling {@link ComponentClient#tearDown()},
* in order to not miss the "duplicate call" log that the base class creates
* if <code>tearDown</code> is called more than once.
* <p>
* Meaning of the 3 int args:
* <ol>
* <li> <code>0</code>: tearDown calls super.tearDown and exits. <br>
* <code>!=0</code>: tearDown sleeps 10 seconds after calling super.tearDown
* <li> Sleep time in seconds after creating the ComponentClient, before returning from this main method call.
* <li> Number of additional calls to the ComponentClient's tearDown method.
* </ol>
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
AcsLogger logger;
ComponentClient m_client;
logger = ClientLogManager.getAcsLogManager().getLoggerForApplication("ShutdownHookTestClient", false);
if (Integer.parseInt(args[0]) == 0)
m_client = new ComponentClient(logger, AcsLocations.figureOutManagerLocation(), "ShutdownHookTestClient") {
public void tearDown() throws Exception {
for (Handler h : m_logger.getHandlers()) {
if (h instanceof StdOutConsoleHandler) {
// to get the "duplicate call" log
h.setLevel(Level.FINE);
}
}
super.tearDown();
}
};
else
m_client = new ComponentClient(logger, AcsLocations.figureOutManagerLocation(), "ShutdownHookTestClient") {
public void tearDown() throws Exception {
for (Handler h : m_logger.getHandlers()) if (h instanceof StdOutConsoleHandler) {
// to get the "duplicate call" log
h.setLevel(Level.FINE);
}
super.tearDown();
Thread.sleep(10 * 1000);
}
};
// Sleep a little bit... depending on the amount of time, we might want to kill
// this baby from the outside, who knows
Thread.sleep(Integer.parseInt(args[1]) * 1000);
// We may want to call tearDown() as many times as we want
int iterations = Integer.parseInt(args[2]);
for (int i = 0; i != iterations; i++) {
m_client.tearDown();
}
}
Aggregations