Search in sources :

Example 1 with StateChangeListener

use of alma.ACS.MasterComponentImpl.StateChangeListener in project ACS by ACS-Community.

the class MastercompBundle method checkCurrentMasterComponents.

private void checkCurrentMasterComponents() throws Exception {
    Map aliveMasterComps = new HashMap();
    try {
        String[] curls = getContainerServices().findComponents(null, "IDL:alma/ACS/MasterComponent:1.0");
        for (int i = 0; i < curls.length; i++) {
            String curl = curls[i];
            MastercompBundle bundle = new MastercompBundle();
            if (!mastercompNameToObject.containsKey(curl)) {
                // new mastercomponent found
                org.omg.CORBA.Object compObj = getContainerServices().getComponent(curl);
                MasterComponentReadOnly mcomp = alma.ACS.MasterComponentReadOnlyHelper.narrow(compObj);
                StateChangeListener listener = attachListener(mcomp);
                System.out.println("found new mastercomponent '" + curl + "'.");
                bundle.masterComp = mcomp;
                bundle.stateChangeListener = listener;
                aliveMasterComps.put(curl, bundle);
            } else {
                // got one we had already
                bundle = (MastercompBundle) mastercompNameToObject.get(curl);
                aliveMasterComps.put(curl, bundle);
                // remove from old map so that we learn about dead components
                mastercompNameToObject.remove(curl);
            }
        }
    } catch (Exception e) {
        m_logger.log(Level.WARNING, "exception occured while updating list of master components: ", e);
        throw e;
    }
    // deal with dead components
    for (Iterator iter = mastercompNameToObject.keySet().iterator(); iter.hasNext(); ) {
        String deadCurl = (String) iter.next();
        m_logger.info("master component '" + deadCurl + "' no longer there.");
        MastercompBundle deadBundle = (MastercompBundle) mastercompNameToObject.get(deadCurl);
        deadBundle.stateChangeListener.destroyMonitor();
    }
    // only discard old map when all was cleaned up well
    mastercompNameToObject = aliveMasterComps;
}
Also used : HashMap(java.util.HashMap) StateChangeListener(alma.ACS.MasterComponentImpl.StateChangeListener) MasterComponentReadOnly(alma.ACS.MasterComponentReadOnly) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with StateChangeListener

use of alma.ACS.MasterComponentImpl.StateChangeListener in project ACS by ACS-Community.

the class MastercompBundle method attachListener.

/**
     * @param mcomp
     * @throws Exception
     */
private StateChangeListener attachListener(MasterComponentReadOnly mcomp) throws Exception {
    ROstringSeq statesProperty = mcomp.currentStateHierarchy();
    StateChangeListener listener = new MyStateChangeListener(m_logger);
    listener.createMonitor(statesProperty, getContainerServices());
    return listener;
}
Also used : ROstringSeq(alma.ACS.ROstringSeq) StateChangeListener(alma.ACS.MasterComponentImpl.StateChangeListener)

Example 3 with StateChangeListener

use of alma.ACS.MasterComponentImpl.StateChangeListener in project ACS by ACS-Community.

the class SpecialTestMasterComponentTest method testHealthySubsystemLifecycle.

/**
	 * Sends the normally expected events <code>SUBSYSEVENT_INITPASS1</code>,
	 * <code>SUBSYSEVENT_INITPASS2</code>, <code>SUBSYSEVENT_START</code>,  
	 * <code>SUBSYSEVENT_STOP</code>, <code>SUBSYSEVENT_SHUTDOWNPASS1</code>,
	 * <code>SUBSYSEVENT_SHUTDOWNPASS2</code>
	 * to our test master component.
	 * Uses state change notification to synchronize sending the next event.
	 * 
	 * @throws Exception
	 */
public void testHealthySubsystemLifecycle() throws Exception {
    ROstringSeq statesProperty = m_masterComp.currentStateHierarchy();
    assertNotNull(statesProperty);
    StateChangeListener listener = new StateChangeListener(m_logger);
    listener.createMonitor(statesProperty, getContainerServices());
    StateChangeSemaphore sync = listener.getStateChangeSemaphore();
    sync.reset();
    m_masterComp.doTransition(SubsystemStateEvent.SUBSYSEVENT_INITPASS1);
    sync.waitForStateChanges(2);
    sync.reset();
    m_masterComp.doTransition(SubsystemStateEvent.SUBSYSEVENT_INITPASS2);
    sync.waitForStateChanges(2);
    sync.reset();
    m_masterComp.doTransition(SubsystemStateEvent.SUBSYSEVENT_START);
    sync.waitForStateChanges(1);
    sync.reset();
    m_masterComp.doTransition(SubsystemStateEvent.SUBSYSEVENT_STOP);
    sync.waitForStateChanges(1);
    sync.reset();
    m_masterComp.doTransition(SubsystemStateEvent.SUBSYSEVENT_SHUTDOWNPASS1);
    sync.waitForStateChanges(2);
    sync.reset();
    m_masterComp.doTransition(SubsystemStateEvent.SUBSYSEVENT_SHUTDOWNPASS2);
    sync.waitForStateChanges(2);
    listener.destroyMonitor();
}
Also used : ROstringSeq(alma.ACS.ROstringSeq) StateChangeSemaphore(alma.ACS.MasterComponentImpl.StateChangeSemaphore) StateChangeListener(alma.ACS.MasterComponentImpl.StateChangeListener)

Aggregations

StateChangeListener (alma.ACS.MasterComponentImpl.StateChangeListener)3 ROstringSeq (alma.ACS.ROstringSeq)2 StateChangeSemaphore (alma.ACS.MasterComponentImpl.StateChangeSemaphore)1 MasterComponentReadOnly (alma.ACS.MasterComponentReadOnly)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1