Search in sources :

Example 1 with MasterComponentReadOnly

use of alma.ACS.MasterComponentReadOnly 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)

Aggregations

StateChangeListener (alma.ACS.MasterComponentImpl.StateChangeListener)1 MasterComponentReadOnly (alma.ACS.MasterComponentReadOnly)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1