Brooklyn

brooklyn.entity.software
[Java] Class MachineLifecycleEffectorTasks

java.lang.Object
  brooklyn.entity.software.MachineLifecycleEffectorTasks

@Beta
public abstract class MachineLifecycleEffectorTasks

Default skeleton for start/stop/restart tasks on machines. Knows how to provision machines, making use of ProvidesProvisioningFlags#obtainProvisioningFlags(MachineProvisioningLocation)#obtainProvisioningFlags(MachineProvisioningLocation), and provides hooks for injecting behaviour at common places. Methods are designed for overriding, with the convention that *Async methods should queue (and not block). The following methods are commonly overridden (and you can safely queue tasks, block, or return immediately in these):

  • startProcessesAtMachine(Supplier) (required)
  • stopProcessesAtMachine() (required, but can be left blank if you assume the VM will be destroyed)
  • preStartCustom(MachineLocation)
  • postStartCustom(MachineLocation)
  • preStopCustom(MachineLocation) Note methods at this level typically look after the Attributes#SERVICE_STATE#SERVICE_STATE sensor.
    Since:
    0.6.0


    Field Summary
    static ConfigKey LOCATIONS

     
    Method Summary
    void attachLifecycleEffectors(Entity entity)

    attaches lifecycle effectors (start, restart, stop) to the given entity (post-creation)

    protected EntityInternal entity()

    protected Location getLocation(java.util.Collection locations)

    Effector newRestartEffector()

    as newStartEffector()

    EffectorBody newRestartEffectorTask()

    as newStartEffectorTask(), calling restart()

    Effector newStartEffector()

    returns an effector suitable for setting in a public static final or attaching dynamically; the effector overrides the corresponding effector from Startable with the behaviour in this lifecycle class instance

    EffectorBody newStartEffectorTask()

    returns the TaskFactory which supplies the implementation for this effector, calling the relevant method in this class (start(Collection)

    Effector newStopEffector()

    as newStartEffector()

    EffectorBody newStopEffectorTask()

    as newStartEffectorTask(), calling stop()

    protected java.util.Map obtainProvisioningFlags(MachineProvisioningLocation location)

    protected void postStartAtMachineAsync()

    protected void postStartCustom()

    default post-start hooks, can be extended by subclasses, and typically will wait for confirmation of start (the service not set to running until after this); also invoked following a restart

    protected void preStartAtMachineAsync(Supplier machineS)

    wraps a call to preStartCustom(MachineLocation), after setting the hostname and address

    protected void preStartCustom(MachineLocation machine)

    default pre-start hooks, can be extended by subclasses if needed

    protected void preStopCustom()

    can run synchronously (or not) -- caller will submit/queue as needed, and will block on any submitted tasks.

    protected Task provisionAsync(MachineProvisioningLocation location)

    returns a queued _task_ which provisions a machine in the given location and returns that machine, so the task can be used as a supplier to subsequent methods

    void restart()

    default restart impl, stops processes if possible, then starts the entity again

    void start(java.util.Collection locations)

    runs the tasks needed to start, wrapped by setting Attributes#SERVICE_STATE#SERVICE_STATE appropriately

    protected void startInLocation(Location location)

    dispatches to the appropriate method(s) to start in the given location

    protected void startInLocations(java.util.Collection locations)

    asserts there is a single location and calls startInLocation(Location) with that location

    protected java.lang.String startProcessesAtMachine(Supplier machineS)

    void stop()

    default stop impl, aborts if already stopped, otherwise sets state STOPPING then invokes preStopCustom(), stopProcessesAtMachine(), then finally stopAnyProvisionedMachines() and sets state STOPPED

    protected java.lang.String stopAnyProvisionedMachines()

    protected java.lang.String stopProcessesAtMachine()

    can run synchronously (or not) -- caller will submit/queue as needed, and will block on any submitted tasks.

     
    Methods inherited from class java.lang.Object
    java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
     

    Field Detail

    LOCATIONS

    public static final ConfigKey LOCATIONS


     
    Method Detail

    attachLifecycleEffectors

    public void attachLifecycleEffectors(Entity entity)
    attaches lifecycle effectors (start, restart, stop) to the given entity (post-creation)


    entity

    protected EntityInternal entity()


    getLocation

    protected Location getLocation(@Nullable java.util.Collection locations)


    newRestartEffector

    public Effector newRestartEffector()
    as newStartEffector()


    newRestartEffectorTask

    public EffectorBody newRestartEffectorTask()
    as newStartEffectorTask(), calling restart()


    newStartEffector

    public Effector newStartEffector()
    returns an effector suitable for setting in a public static final or attaching dynamically; the effector overrides the corresponding effector from Startable with the behaviour in this lifecycle class instance


    newStartEffectorTask

    public EffectorBody newStartEffectorTask()
    returns the TaskFactory which supplies the implementation for this effector, calling the relevant method in this class (start(Collection)


    newStopEffector

    public Effector newStopEffector()
    as newStartEffector()


    newStopEffectorTask

    public EffectorBody newStopEffectorTask()
    as newStartEffectorTask(), calling stop()


    obtainProvisioningFlags

    protected java.util.Map obtainProvisioningFlags(MachineProvisioningLocation location)


    postStartAtMachineAsync

    protected void postStartAtMachineAsync()


    postStartCustom

    protected void postStartCustom()
    default post-start hooks, can be extended by subclasses, and typically will wait for confirmation of start (the service not set to running until after this); also invoked following a restart


    preStartAtMachineAsync

    protected void preStartAtMachineAsync(Supplier machineS)
    wraps a call to preStartCustom(MachineLocation), after setting the hostname and address


    preStartCustom

    protected void preStartCustom(MachineLocation machine)
    default pre-start hooks, can be extended by subclasses if needed


    preStopCustom

    protected void preStopCustom()
    can run synchronously (or not) -- caller will submit/queue as needed, and will block on any submitted tasks.
    Returns:
    string message of result


    provisionAsync

    protected Task provisionAsync(MachineProvisioningLocation location)
    returns a queued _task_ which provisions a machine in the given location and returns that machine, so the task can be used as a supplier to subsequent methods


    restart

    public void restart()
    default restart impl, stops processes if possible, then starts the entity again


    start

    public void start(java.util.Collection locations)
    runs the tasks needed to start, wrapped by setting Attributes#SERVICE_STATE#SERVICE_STATE appropriately


    startInLocation

    protected void startInLocation(Location location)
    dispatches to the appropriate method(s) to start in the given location


    startInLocations

    protected void startInLocations(java.util.Collection locations)
    asserts there is a single location and calls startInLocation(Location) with that location


    startProcessesAtMachine

    protected java.lang.String startProcessesAtMachine(Supplier machineS)


    stop

    public void stop()
    default stop impl, aborts if already stopped, otherwise sets state STOPPING then invokes preStopCustom(), stopProcessesAtMachine(), then finally stopAnyProvisionedMachines() and sets state STOPPED


    stopAnyProvisionedMachines

    protected java.lang.String stopAnyProvisionedMachines()


    stopProcessesAtMachine

    protected java.lang.String stopProcessesAtMachine()
    can run synchronously (or not) -- caller will submit/queue as needed, and will block on any submitted tasks.
    Returns:
    string message of result


     

    Brooklyn Multi-Cloud Application Management Platform
    brooklyncentral.github.com. Apache License. © 2012.