mil.dod.th.ose.core/src/mil/dod/th/ose/core/impl/mp/MissionProgramManagerImpl.java
@Activate
    public void activate(final BundleContext context) throws IllegalArgumentException
    {
        m_MisPrgEvntHandler = new MissionProgramManagerEventHandler();
        m_MisPrgEvntHandler.registerEvents(context);
        
        m_BaseBindings.put(BUNDLE_CONTEXT, context);
        m_BaseBindings.put(ASSET_DIRECTORY_SERVICE, m_AssetDirectoryService);
        m_BaseBindings.put(CUSTOM_COMMS_SERVICE,    m_CustomCommsService);
        m_BaseBindings.put(ADDRESS_MANAGER_SERVICE, m_AddressManagerService);
        m_BaseBindings.put(OBSERVATION_STORE,       m_ObservationStore);
        m_BaseBindings.put(PERSISTENT_DATA_STORE,   m_PersistentDataStore);
        m_BaseBindings.put(LOGGING_SERVICE,         m_Logging);
        m_BaseBindings.put(EVENT_HANDLER_HELPER,    m_EventHandlerHelper);
        m_BaseBindings.put(MANAGED_EXECUTORS,       m_ManagedExecutors);
        m_BaseBindings.put(MISSION_PROGRAM_MANAGER, this);
        m_BaseBindings.put(TERRA_HARVEST_CONTROLLER, m_TerraHarvestController);
        m_BaseBindings.put(TERRA_HARVEST_SYSTEM,    m_TerraHarvestSystem);
        m_BaseBindings.put(XML_MARSHAL_SERVICE,    m_XMLMarshalService);
        m_BaseBindings.put(XML_UNMARSHAL_SERVICE,    m_XMLUnmarshalService);
        m_BaseBindings.put(TEMPLATE_PROGRAM_MANAGER,    m_TemplateManager);
        
        // add all base bindings to the script engine (only used by execute())
        for (String key : m_BaseBindings.keySet())
        {
            m_ScriptEngine.put(key, m_BaseBindings.get(key));
        }
       
        // Load upgrade script
        final Bundle bundle = context.getBundle();
        final String upgradeScript = "nashornUpgrade.js";
        m_UpgradeSource = bundle.getEntry(upgradeScript);

        if (m_UpgradeSource == null)
        {            
            throw new IllegalStateException("Unable to find mission programming upgrade script, "
                    + "cannot activate MissionProgramManager.");            
        }
        
        // load saved programs
        final Collection<? extends PersistentData> query = m_PersistentDataStore.query(this.getClass());
        if (query.isEmpty())
        {
            // programs not persisted
            m_Logging.info("No mission programs found to restore");
        }
        else
        {
            //get all known template names
            final Set<String> templateNames = m_TemplateManager.getMissionTemplateNames();
            for (PersistentData dataEntity : query)
            {
                final byte[] byteData = (byte[])dataEntity.getEntity();
                //load the parameters                
                final MissionProgramParameters params = (MissionProgramParameters)(XmlUtils.fromXML(byteData, 
                    MissionProgramParameters.class));
                //check that parameters contain the expected variable types
                m_Logging.debug("Mission parameters retrieved from the data store%n%s", params);
                final String name = params.getTemplateName();
                if (templateNames.contains(name))
                {
                    final ProgramImpl program = new ProgramImpl(this, m_EventAdmin, m_TemplateManager.
                            getTemplate(params.getTemplateName()), params, dataEntity.getUUID());
                    program.setLoadedAfterReset(true);
                    //add program to set of managed programs
                    m_Programs.add(program);
                }
                else
                {
                    m_Logging.error("Template not found with name: %s", params.getTemplateName());
                }
            }
            m_Logging.info("Restored the following mission programs: %s",  getActiveProgramTemplateNames());
        }
          
        // try to execute each restart program as long as at least one ran as it could be a trigger for 
        // another program
        for (ProgramImpl program : m_Programs)
        {
            synchronized (program)
            {
                //check if the program is active and set to start at restart
                if (program.getScheduleFlag(ScheduleEnum.START_AT_RESTART) 
                        && program.getScheduleFlag(ScheduleEnum.IS_ACTIVE)
                        && program.getProgramStatus() == ProgramStatus.UNSATISFIED)
                {
                    m_Logging.debug("checking if program [%s] is ready to execute at activation", 
                            program.getProgramName());
                    
                    execReadyProgram(program);
                }
            }
        }
    }
/**
     * Activate this component by initializing the base bindings.
     * 
     * @param context
     *      context for the bundle containing this component  
     * @throws IllegalArgumentException 
     *     if a mission template or parameters can not be united correctly to create a program
     */
Activate this component by initializing the base bindings.

@param context
context for the bundle containing this component
@throws IllegalArgumentException
if a mission template or parameters can not be united correctly to create a program
Activate this component by initializing the base bindings . @param context context for the bundle containing this component @throws IllegalArgumentException if a mission template or parameters can not be united correctly to create a program
@Activate
    public void activate(final BundleContext context) throws IllegalArgumentException
    {
        m_MisPrgEvntHandler = new MissionProgramManagerEventHandler();
        m_MisPrgEvntHandler.registerEvents(context);
        m_BaseBindings.put(BUNDLE_CONTEXT, context);
        m_BaseBindings.put(ASSET_DIRECTORY_SERVICE, m_AssetDirectoryService);
        m_BaseBindings.put(CUSTOM_COMMS_SERVICE,    m_CustomCommsService);
        m_BaseBindings.put(ADDRESS_MANAGER_SERVICE, m_AddressManagerService);
        m_BaseBindings.put(OBSERVATION_STORE,       m_ObservationStore);
        m_BaseBindings.put(PERSISTENT_DATA_STORE,   m_PersistentDataStore);
        m_BaseBindings.put(LOGGING_SERVICE,         m_Logging);
        m_BaseBindings.put(EVENT_HANDLER_HELPER,    m_EventHandlerHelper);
        m_BaseBindings.put(MANAGED_EXECUTORS,       m_ManagedExecutors);
        m_BaseBindings.put(MISSION_PROGRAM_MANAGER, this);
        m_BaseBindings.put(TERRA_HARVEST_CONTROLLER, m_TerraHarvestController);
        m_BaseBindings.put(TERRA_HARVEST_SYSTEM,    m_TerraHarvestSystem);
        m_BaseBindings.put(XML_MARSHAL_SERVICE,    m_XMLMarshalService);
        m_BaseBindings.put(XML_UNMARSHAL_SERVICE,    m_XMLUnmarshalService);
        m_BaseBindings.put(TEMPLATE_PROGRAM_MANAGER,    m_TemplateManager);
        for (String key : m_BaseBindings.keySet())
        {
            m_ScriptEngine.put(key, m_BaseBindings.get(key));
        }
        final Bundle bundle = context.getBundle();
        final String upgradeScript = "nashornUpgrade.js";
        m_UpgradeSource = bundle.getEntry(upgradeScript);
        if (m_UpgradeSource == null)
        {            
            throw new IllegalStateException("Unable to find mission programming upgrade script, "
                    + "cannot activate MissionProgramManager.");            
        }
        final Collection<? extends PersistentData> query = m_PersistentDataStore.query(this.getClass());
        if (query.isEmpty())
        {
            m_Logging.info("No mission programs found to restore");
        }
        else
        {
            final Set<String> templateNames = m_TemplateManager.getMissionTemplateNames();
            for (PersistentData dataEntity : query)
            {
                final byte[] byteData = (byte[])dataEntity.getEntity();
                final MissionProgramParameters params = (MissionProgramParameters)(XmlUtils.fromXML(byteData, 
                    MissionProgramParameters.class));
                m_Logging.debug("Mission parameters retrieved from the data store%n%s", params);
                final String name = params.getTemplateName();
                if (templateNames.contains(name))
                {
                    final ProgramImpl program = new ProgramImpl(this, m_EventAdmin, m_TemplateManager.
                            getTemplate(params.getTemplateName()), params, dataEntity.getUUID());
                    program.setLoadedAfterReset(true);
                    m_Programs.add(program);
                }
                else
                {
                    m_Logging.error("Template not found with name: %s", params.getTemplateName());
                }
            }
            m_Logging.info("Restored the following mission programs: %s",  getActiveProgramTemplateNames());
        }
        for (ProgramImpl program : m_Programs)
        {
            synchronized (program)
            {
                if (program.getScheduleFlag(ScheduleEnum.START_AT_RESTART) 
                        && program.getScheduleFlag(ScheduleEnum.IS_ACTIVE)
                        && program.getProgramStatus() == ProgramStatus.UNSATISFIED)
                {
                    m_Logging.debug("checking if program [%s] is ready to execute at activation", 
                            program.getProgramName());
                    execReadyProgram(program);
                }
            }
        }
    }
@ Activate public void activate ( final BundleContext context ) throws IllegalArgumentException { m_MisPrgEvntHandler = new MissionProgramManagerEventHandler ( ) ; m_MisPrgEvntHandler . registerEvents ( context ) ; m_BaseBindings . put ( BUNDLE_CONTEXT , context ) ; m_BaseBindings . put ( ASSET_DIRECTORY_SERVICE , m_AssetDirectoryService ) ; m_BaseBindings . put ( CUSTOM_COMMS_SERVICE , m_CustomCommsService ) ; m_BaseBindings . put ( ADDRESS_MANAGER_SERVICE , m_AddressManagerService ) ; m_BaseBindings . put ( OBSERVATION_STORE , m_ObservationStore ) ; m_BaseBindings . put ( PERSISTENT_DATA_STORE , m_PersistentDataStore ) ; m_BaseBindings . put ( LOGGING_SERVICE , m_Logging ) ; m_BaseBindings . put ( EVENT_HANDLER_HELPER , m_EventHandlerHelper ) ; m_BaseBindings . put ( MANAGED_EXECUTORS , m_ManagedExecutors ) ; m_BaseBindings . put ( MISSION_PROGRAM_MANAGER , this ) ; m_BaseBindings . put ( TERRA_HARVEST_CONTROLLER , m_TerraHarvestController ) ; m_BaseBindings . put ( TERRA_HARVEST_SYSTEM , m_TerraHarvestSystem ) ; m_BaseBindings . put ( XML_MARSHAL_SERVICE , m_XMLMarshalService ) ; m_BaseBindings . put ( XML_UNMARSHAL_SERVICE , m_XMLUnmarshalService ) ; m_BaseBindings . put ( TEMPLATE_PROGRAM_MANAGER , m_TemplateManager ) ; for ( String key : m_BaseBindings . keySet ( ) ) { m_ScriptEngine . put ( key , m_BaseBindings . get ( key ) ) ; } final Bundle bundle = context . getBundle ( ) ; final String upgradeScript = "nashornUpgrade.js" ; m_UpgradeSource = bundle . getEntry ( upgradeScript ) ; if ( m_UpgradeSource == null ) { throw new IllegalStateException ( "Unable to find mission programming upgrade script, " + "cannot activate MissionProgramManager." ) ; } final Collection < ? extends PersistentData > query = m_PersistentDataStore . query ( this . getClass ( ) ) ; if ( query . isEmpty ( ) ) { m_Logging . info ( "No mission programs found to restore" ) ; } else { final Set < String > templateNames = m_TemplateManager . getMissionTemplateNames ( ) ; for ( PersistentData dataEntity : query ) { final byte [ ] byteData = ( byte [ ] ) dataEntity . getEntity ( ) ; final MissionProgramParameters params = ( MissionProgramParameters ) ( XmlUtils . fromXML ( byteData , MissionProgramParameters . class ) ) ; m_Logging . debug ( "Mission parameters retrieved from the data store%n%s" , params ) ; final String name = params . getTemplateName ( ) ; if ( templateNames . contains ( name ) ) { final ProgramImpl program = new ProgramImpl ( this , m_EventAdmin , m_TemplateManager . getTemplate ( params . getTemplateName ( ) ) , params , dataEntity . getUUID ( ) ) ; program . setLoadedAfterReset ( true ) ; m_Programs . add ( program ) ; } else { m_Logging . error ( "Template not found with name: %s" , params . getTemplateName ( ) ) ; } } m_Logging . info ( "Restored the following mission programs: %s" , getActiveProgramTemplateNames ( ) ) ; } for ( ProgramImpl program : m_Programs ) { synchronized ( program ) { if ( program . getScheduleFlag ( ScheduleEnum . START_AT_RESTART ) && program . getScheduleFlag ( ScheduleEnum . IS_ACTIVE ) && program . getProgramStatus ( ) == ProgramStatus . UNSATISFIED ) { m_Logging . debug ( "checking if program [%s] is ready to execute at activation" , program . getProgramName ( ) ) ; execReadyProgram ( program ) ; } } } }
Activate this component by initializing the base bindings.
Activate this component by initializing the base bindings .
// add all base bindings to the script engine (only used by execute()) // Load upgrade script // load saved programs // programs not persisted //get all known template names //load the parameters                 //check that parameters contain the expected variable types //add program to set of managed programs // try to execute each restart program as long as at least one ran as it could be a trigger for  // another program //check if the program is active and set to start at restart