Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/798#discussion_r36416514
  
    --- Diff: core/src/main/java/brooklyn/entity/basic/BasicStartableImpl.java 
---
    @@ -38,38 +39,47 @@
     public class BasicStartableImpl extends AbstractEntity implements 
BasicStartable {
     
         private static final Logger log = 
LoggerFactory.getLogger(BasicStartableImpl.class);
    -    
    -    public BasicStartableImpl() {
    -        super();
    -    }
     
         @Override
         public void start(Collection<? extends Location> locations) {
             log.info("Starting entity "+this+" at "+locations);
    -        addLocations(locations);
    -        
    -        // essentially does StartableMethods.start(this, locations),
    -        // but optionally filters locations for each child
    -        
    -        brooklyn.location.basic.Locations.LocationsFilter filter = 
getConfig(LOCATIONS_FILTER);
    -        Iterable<Entity> startables = 
filterStartableManagedEntities(getChildren());
    -        if (startables == null || Iterables.isEmpty(startables)) return;
    +        try {
    +            ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING);
    +
    +            addLocations(locations);
    +
    +            // essentially does StartableMethods.start(this, locations),
    +            // but optionally filters locations for each child
     
    -        List<Task<?>> tasks = Lists.newArrayList();
    -        for (final Entity entity : startables) {
    -            Collection<? extends Location> l2 = locations;
    -            if (filter!=null) {
    -                l2 = filter.filterForContext(new 
ArrayList<Location>(locations), entity);
    -                log.debug("Child "+entity+" of "+this+" being started in 
filtered location list: "+l2);
    +            brooklyn.location.basic.Locations.LocationsFilter filter = 
getConfig(LOCATIONS_FILTER);
    +            Iterable<Entity> startables = 
filterStartableManagedEntities(getChildren());
    +            if (!Iterables.isEmpty(startables)) {
    +                List<Task<?>> tasks = 
Lists.newArrayListWithCapacity(Iterables.size(startables));
    +                for (final Entity entity : startables) {
    +                    Collection<? extends Location> l2 = locations;
    +                    if (filter != null) {
    +                        l2 = filter.filterForContext(new 
ArrayList<Location>(locations), entity);
    +                        log.debug("Child " + entity + " of " + this + " 
being started in filtered location list: " + l2);
    +                    }
    +                    tasks.add(Entities.invokeEffectorWithArgs(this, 
entity, Startable.START, l2));
    +                }
    +                for (Task<?> t : tasks) {
    +                    t.getUnchecked();
    +                }
                 }
    -            tasks.add( Entities.invokeEffectorWithArgs(this, entity, 
Startable.START, l2) );
    +            setAttribute(Attributes.SERVICE_UP, true);
    +            ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING);
    +        } catch (Throwable t) {
    +            ServiceStateLogic.setExpectedState(this, Lifecycle.ON_FIRE);
    +            throw Exceptions.propagate(t);
             }
    -        for (Task<?> t: tasks) t.getUnchecked();
         }
     
         @Override
         public void stop() {
    +        ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPING);
             StartableMethods.stop(this);
    --- End diff --
    
    should this be wrapped in a try-catch, so that we can do 
`ServiceStateLogic.setExpectedState(this, Lifecycle.ON_FIRE);`? For example, 
see `DynamicClusterImpl.stop()` and `AbstractApplication.stop()`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to