use of alma.acs.concurrent.DaemonThreadFactory in project ACS by ACS-Community.
the class ManagerImpl method initialize.
/**
* Initializes Manager.
* @param prevayler implementation of prevayler system
* @param context remote directory implementation
*/
public void initialize(Prevayler prevayler, CDBAccess cdbAccess, Context context, final Logger logger, ManagerContainerServices managerContainerServices) {
this.prevayler = prevayler;
this.remoteDirectory = context;
this.logger = logger;
// needs to be done here, since deserialization is used
initializeDefaultConfiguration();
if (cdbAccess != null)
setCDBAccess(cdbAccess);
readManagerConfiguration();
componentsLock = (ProfilingReentrantLock.isProfilingEnabled ? new ProfilingReentrantLock("componentsLock") : new ReentrantLock());
random = new Random();
heartbeatTask = new Timer(true);
delayedDeactivationTask = new Timer(true);
containerLoggedInMonitor = new Object();
activationSynchronization = new HashMap<String, ReferenceCountingLock>();
activationPendingRWLock = new ReaderPreferenceReadWriteLock();
shutdown = new AtomicBoolean(false);
threadPool = new ThreadPoolExecutor(poolThreads, poolThreads, Long.MAX_VALUE, TimeUnit.NANOSECONDS, new LinkedBlockingQueue(), new DaemonThreadFactory("managerThreadPool"));
managerCache = new HashMap<String, Manager>();
pendingActivations = new HashMap<String, ComponentInfo>();
pendingContainerShutdown = Collections.synchronizedSet(new HashSet<String>());
pendingContainerAsyncRequests = new HashMap<String, Deque<ComponentInfoCompletionCallback>>();
clientMessageQueue = new HashMap<Client, LinkedList<ClientMessageTask>>();
groupedNotifyTaskMap = new HashMap<Object, GroupedNotifyTask>();
threadsUsedPercentage = new AtomicInteger(0);
// create threads
threadPool.prestartAllCoreThreads();
// read CDB startup
try {
String componentSpec = System.getProperty(NAME_CDB_COMPONENTSPEC);
if (componentSpec != null) {
cdbActivation = new ComponentSpec(componentSpec);
logger.log(Level.INFO, "Using CDB component specification: '" + cdbActivation + "'.");
}
} catch (Throwable t) {
logger.log(Level.WARNING, "Failed to parse '" + NAME_CDB_COMPONENTSPEC + "' variable, " + t.getMessage(), t);
}
// check load balancing strategy
checkLoadBalancingStrategy();
// establish connect to the alarm system
try {
alarmSource = new AlarmSourceImpl(managerContainerServices);
alarmSource.start();
} catch (Throwable ex) {
logger.log(Level.SEVERE, "Failed to initialize Alarm System Interface " + ex.getMessage(), ex);
alarmSource = null;
}
// register ping tasks
initializePingTasks();
// handle monitoring removal task
final long timeInMs = enableHandleMonitoringDurationMins * 60L * 1000;
if (enableHandleMonitoring && enableHandleMonitoringDurationMins > 0) {
heartbeatTask.schedule(new TimerTask() {
@Override
public void run() {
try {
logHandleCleanup(timeInMs);
} catch (Throwable th) {
logger.log(Level.SEVERE, "Unexpected exception in handle log cleanup task.", th);
}
}
}, 0, timeInMs);
}
// start topology sort manager
topologySortManager = new ComponentInfoTopologicalSortManager(components, containers, activationPendingRWLock, pendingContainerShutdown, threadPool, logger);
if (prevayler == null)
statePersitenceFlag.set(false);
String enDis = statePersitenceFlag.get() ? "enabled" : "disabled";
logger.info("Manager initialized with state persistence " + enDis + ".");
}
use of alma.acs.concurrent.DaemonThreadFactory in project ACS by ACS-Community.
the class AcsContainerRunner method initAcsLogging.
/**
* Asynchronously connects to the log service so that after some time the locally collected log records
* will be sent over the wire.
*/
protected void initAcsLogging(final AcsManagerProxy managerProxy) {
Runnable cmd = new Runnable() {
public void run() {
m_logger.finer("asynchronously calling ClientLogManager#initRemoteLogging()...");
boolean gotLogService = false;
try {
gotLogService = ClientLogManager.getAcsLogManager().initRemoteLogging(m_acsCorba.getORB(), managerProxy.getManager(), managerProxy.getManagerHandle(), true);
} catch (Exception e) {
// just log below
}
if (gotLogService) {
m_logger.finer("done ClientLogManager#initRemoteLogging");
} else {
m_logger.log(Level.WARNING, "ACS central logging not available!");
}
}
};
ExecutorService executor = Executors.newSingleThreadExecutor(new DaemonThreadFactory("InitRemoteLogging"));
executor.execute(cmd);
}
use of alma.acs.concurrent.DaemonThreadFactory in project ACS by ACS-Community.
the class ProcessUtil method getJavaPIDs.
/**
* Gets a map with key=(running java main classes) and value=(list of the process IDs).
* Filters out sun.tools.jps.Jps which is the tool used to get the processes.
* @return Map<classname, pid-list>
* @throws IOException
* @throws InterruptedException
*/
protected Map<String, List<String>> getJavaPIDs() throws IOException {
// The following command returns lines of the format
// 23551 com.cosylab.acs.maci.manager.app.Manager
// 29113 sun.tools.jps.Jps
String command = "jps -l";
Process proc = Runtime.getRuntime().exec(command);
ProcessStreamGobbler gob = new ProcessStreamGobbler(proc, new DaemonThreadFactory(), true);
gob.setDebug(DEBUG);
try {
// read stdout and stderr
if (!gob.gobble(10, TimeUnit.SECONDS)) {
throw new IOException("Failed to execute command '" + command + "' within 10 seconds");
}
if (gob.hasStreamReadErrors()) {
throw new IOException("Failed to read output of command '" + command + "'");
}
} catch (InterruptedException ex) {
throw new IOException("Thread reading output of command '" + command + "' got interrupted.");
}
// evaluate jps output
Map<String, List<String>> pidMap = new HashMap<String, List<String>>();
List<String> outlines = gob.getStdout();
String[] splitLine = null;
for (String line : outlines) {
if (line.length() > 0 && (splitLine = line.split(" ")).length == 2) {
String cname = splitLine[1];
if (!"sun.tools.jps.Jps".equals(cname)) {
String pid = splitLine[0];
List<String> pidList = pidMap.containsKey(cname) ? pidMap.get(cname) : new ArrayList<String>();
pidList.add(pid);
pidMap.put(cname, pidList);
}
} else {
logger.info("jps returned unexpected line '" + line + "'");
}
}
return pidMap;
}
Aggregations