brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdowner <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: allow parameters for restart effe...
Date Fri, 24 Oct 2014 12:51:34 GMT
Github user rdowner commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/260#discussion_r19336588
  
    --- Diff: core/src/main/java/brooklyn/entity/trait/Startable.java ---
    @@ -51,30 +56,68 @@
                 parameters.put(LOCATIONS, entity().getManagementContext().getLocationRegistry().resolveList(parameters.get(LOCATIONS)));
                 return new MethodEffector<Void>(Startable.class, "start").call(entity(),
parameters.getAllConfig());
             }
    -    };
    -    
    +    }
    +
    +    public static class StopEffectorBody extends EffectorBody<Void> {
    +        private static final Logger log = LoggerFactory.getLogger(Startable.class);
    +        
    +        @Override public Void call(ConfigBag parameters) {
    +            if (!parameters.isEmpty()) {
    +                log.warn("Parameters "+parameters+" not supported for call to "+entity()+"
- "+Tasks.current());
    +            }
    +            
    +            return new MethodEffector<Void>(Startable.class, "stop").call(entity(),
parameters.getAllConfig());
    +        }
    +    }
    +
    +    public static class RestartEffectorBody extends EffectorBody<Void> {
    +        private static final Logger log = LoggerFactory.getLogger(Startable.class);
    +
    +        @Override public Void call(ConfigBag parameters) {
    +            if (!parameters.isEmpty()) {
    +                log.warn("Parameters "+parameters+" not supported for call to "+entity()+"
- "+Tasks.current());
    +            }
    +            return new MethodEffector<Void>(Startable.class, "restart").call(entity(),
parameters.getAllConfig());
    +        }
    +    }
    +
         brooklyn.entity.Effector<Void> START = Effectors.effector(new MethodEffector<Void>(Startable.class,
"start"))
             // override start to take strings etc
             .parameter(StartEffectorBody.LOCATIONS)
             .impl(new StartEffectorBody())
             .build();
    -    brooklyn.entity.Effector<Void> STOP = new MethodEffector<Void>(Startable.class,
"stop");
    -    brooklyn.entity.Effector<Void> RESTART = new MethodEffector<Void>(Startable.class,"restart");
    +    
    +    brooklyn.entity.Effector<Void> STOP = Effectors.effector(new MethodEffector<Void>(Startable.class,
"stop"))
    +        .impl(new StopEffectorBody())
    +        .build();
    +    
    +    brooklyn.entity.Effector<Void> RESTART = Effectors.effector(new MethodEffector<Void>(Startable.class,
"restart"))
    +        .impl(new RestartEffectorBody())
    +        .build();
    --- End diff --
    
    Have to agree with @sjcorbett on this one. Seems like this is adding a lot of SLOC just
to check and warn about one condition.
    
    It looks like it should be possible to refactor `StopEffectorBody` and `RestartEffectorBody`
into a general-purpose `WarnIfParametersGivenEffectorWrapper`? It seems that these are trying
to wrap another effector body, so it would be informative to put `Wrapper` into the class
name somewhere. I can then see a static class `EffectorWrapper` or `EffectorBodies` that holds
a useful library of effector bodies, along the line of `Predicates` or `Functions`.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message