IManagerLifeCycle

To achieve application start-up, every application must implement an IManagerLifeCycle plugin. This is a plugin interface that Beatrix expects but cannot implement itself:


public interface IManagerLifeCycle
{
    /**
     *  Applications must implement this to define cold start behaviour. 
     *  ColdStart is the primary boot process initiated by the
     *  application administrator. 
     *
     *  @param args  Application specific properties defined
     *               by the bootstrap process,
     *               including perhaps the console commandline on launch. 
     *  @return      A warrant which will be made available to the application
     *               owner. If this application is to be launched via the
     *               launcher then the warrant's service should provide an
     *               IConsoleFacet.
     *  @throws BeatrixException  If the application cannot cold-start.
     */
    public Warrant coldStart(IPropertyCollection args) throws BeatrixException;

    /**
     *  Applications must implement this to define warm start behaviour.
     *  Will be called by the hosting service when it notices the application
     *  has died.
     *  @param arg   An application specific argument defined using
     *               setWarmStartArgument() from a previous manager.
     */
    public void warmStart(Serializable arg);

    /**
     *  Called when this manager is created by another manager.  
     *  @param arg   The argument from the createManager call.
     */
    public void join(Serializable arg);

    /**
     *  Called when the application leadership changes.
     * Not called on start-up, since the leader has not changed.
     */
    public void changeLeaderMode(boolean you_are_leader);

    /** Utility class helping lookup */
    public static class Get
    {
        /** Get the only instance of this plugin in the given manager.
         * Only the first such plugin is returned. If there isn't one then
         * an ArrayIndexOutOfBoundsException is thrown.
         */
        public static IManagerLifeCycle one(IPluginManager pm)
        {
            return ((IManagerLifeCycle)pm.lookup(IManagerLifeCycle.class)[0]);
        } 
    }
}

A sample implementation is found above in skeleton's LifeCyclePlugin (Section [*]). Notice that this class's coldStart() method chooses to call its changeLeaderMode() method. This is because, as stated above, Beatrix does not call changeChangeLeaderMode() on start-up.

The coldStart() method enters with a collection of properties set by the launch descriptor and the administrator on launch. Properties are worth getting to grips with--see Section [*] on properties and the next section on the the IPropertyCollection argument of coldStart(). The coldStart() method has to deploy managers and workers. Finally it must also return a warrant to an admin service, so whoever launched the application can control it. That is usually achieved with something like this:


IManagerSupport ms = (IManagerSupport)_plugin_manager.lookup(IManagerSupport.class)[0];
return ms.getWarrant("admin", null);

which returns a warrant using Beatrix's own IManagerSupport plugin, and assumes our admin service is called admin. See Section [*] for more on services and warrants.

If our IManagerLifeCycle plugin extends AbstractPlugin then this can be achieved in a single step:


return managerSupport().getWarrant("admin", null);

Actually, the warrant returned from the coldStart() method does not have to be admin warrant; it can be any warrant for a service which provides an IConsoleFacet. This allows the launcher to provide console access to the application. However, since the application administrator is the one who launched the application then we shall in general assume it is an admin warrant.

The warmStart() method allows the application to pick up when previously it was running but then died. Its argument is whatever was set via the ILeaderSupport plugin (Section [*]). There is no need to for a warm start to return a warrant, because that was given to the application's administrator when they cold-started it previously. Warm start is just for reviving an application automatically.

The join() method is called in a new manager when it joins an already-running application. Its argument is also set via the ILeaderSupport plugin (Section [*]), and again there is no need to return a value.

Nik Silver 2002-03-09