Search in sources :

Example 6 with DaemonThreadFactory

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 + ".");
}
Also used : DaemonThreadFactory(alma.acs.concurrent.DaemonThreadFactory) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Manager(com.cosylab.acs.maci.Manager) Random(java.util.Random) TimerTask(java.util.TimerTask) AlarmSourceImpl(alma.acs.alarmsystem.source.AlarmSourceImpl) Client(com.cosylab.acs.maci.Client) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) ReentrantLock(java.util.concurrent.locks.ReentrantLock) ComponentSpec(com.cosylab.acs.maci.ComponentSpec) ArrayDeque(java.util.ArrayDeque) Deque(java.util.Deque) LinkedList(java.util.LinkedList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Timer(java.util.Timer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ComponentInfo(com.cosylab.acs.maci.ComponentInfo)

Example 7 with DaemonThreadFactory

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);
}
Also used : DaemonThreadFactory(alma.acs.concurrent.DaemonThreadFactory) ExecutorService(java.util.concurrent.ExecutorService)

Example 8 with DaemonThreadFactory

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;
}
Also used : HashMap(java.util.HashMap) ProcessStreamGobbler(alma.acs.util.ProcessStreamGobbler) DaemonThreadFactory(alma.acs.concurrent.DaemonThreadFactory) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Aggregations

DaemonThreadFactory (alma.acs.concurrent.DaemonThreadFactory)8 ExecutorService (java.util.concurrent.ExecutorService)3 ProcessStreamGobbler (alma.acs.util.ProcessStreamGobbler)2 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AlarmSourceImpl (alma.acs.alarmsystem.source.AlarmSourceImpl)1 CleaningDaemonThreadFactory (alma.acs.container.CleaningDaemonThreadFactory)1 LogConfig (alma.acs.logging.config.LogConfig)1 DaemonCallback (alma.acsdaemon.DaemonCallback)1 Client (com.cosylab.acs.maci.Client)1 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)1 ComponentSpec (com.cosylab.acs.maci.ComponentSpec)1 Manager (com.cosylab.acs.maci.Manager)1 IOException (java.io.IOException)1 ArrayDeque (java.util.ArrayDeque)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1 Deque (java.util.Deque)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1