Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add series of meta effectors for composite operations #605

Open
wants to merge 43 commits into
base: master
Choose a base branch
from

Conversation

grkvlt
Copy link
Member

@grkvlt grkvlt commented Mar 22, 2017

Adds ComposeEffector, SequenceEffector, TransformEffector and LoopEffector for orchestrating effector calls in blueprints.

Also ScheduledEffectorPolicy and PeriodicEffectorPolicy policies to execute an effector at a scheduled time or periodically.

TODO Add tests for each new effector type and basic documentation

@Override
public void apply(EntityLocal entity) {
Maybe<Effector<?>> effectorMaybe = entity.getEntityType().getEffectorByName(effector.getName());
if (!effectorMaybe.isAbsentOrNull()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the logic in this has been commented out! If none is required, makes overriding the entire method superfluous.

throw new IllegalArgumentException("Effector parameter cannot be parsed: " + effectorDetails);
}
effectorName = Iterables.getOnlyElement(keys);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about instanceof List?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the individual effector elements of the list of effectors, they can only be a String or a Map

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean what if someone passes a list - effectorName = Strings.toString(effectorDetails); does not feel like the right way to handle that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why would they do that? They would be creating a list of lists, as in the third option below, and if someone does that, then I'm happy for things to just break...

compose:
  - name1 # string
  - name2: # map
      key: value
  - [ whyWouldYouDoThis ] # list

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it would clearly be a mistake - prefer to fail fast, so perhaps throwing an exception rather than allowing it to pass by calling toString()

@geomacy
Copy link
Contributor

geomacy commented Mar 23, 2017

@grkvlt there should be some unit tests at least along with these, can you add some?


public Body(Effector<?> eff, ConfigBag params) {
super(eff, params);
Preconditions.checkNotNull(params.getAllConfigRaw().get(COMPOSE.getName()), "Effector names must be supplied when defining this effector");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be Preconditions.checkNotNull(params.get(COMPOSE), "compose must be supplied when defining a compose effector: %s", params)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll fix all of these to have better error messages.


public Body(Effector<?> eff, ConfigBag params) {
super(eff, params);
Preconditions.checkNotNull(params.getAllConfigRaw().get(LOOP.getName()), "Effector names must be supplied when defining this effector");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be Preconditions.checkNotNull(params.get(LOOP), "loop must be supplied when defining a loop effector: %s", params)?


public Body(Effector<?> eff, ConfigBag params) {
super(eff, params);
Preconditions.checkNotNull(params.getAllConfigRaw().get(SEQUENCE.getName()), "Effector names must be supplied when defining this effector");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be Preconditions.checkNotNull(params.get(SEQUENCE), "sequence must be supplied when defining a sequence effector: %s", params)?


public Body(Effector<?> eff, ConfigBag params) {
super(eff, params);
Preconditions.checkNotNull(params.getAllConfigRaw().get(FUNCTION.getName()), "Function must be supplied when defining this effector");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be Preconditions.checkNotNull(params.get(FUNCTION), "function must be supplied when defining a function effector: %s", params)?

Also what about INPUT?

@grkvlt grkvlt force-pushed the feature/composite-effectors branch 2 times, most recently from b60b332 to e3a936f Compare March 27, 2017 10:47

protected long delay;

private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to inherit the ScheduledExecutorService of the parent class and use that?

@grkvlt grkvlt force-pushed the feature/composite-effectors branch 8 times, most recently from ca62777 to de72251 Compare April 6, 2017 02:40
@grkvlt grkvlt force-pushed the feature/composite-effectors branch 4 times, most recently from caac7c4 to 9413b4b Compare April 11, 2017 15:16
@Graeme-Miller
Copy link
Contributor

@grkvlt this PR is rather large, and missing tests. I suggest it is closed for now and we work out a way to break this down.

Some ideas for how to break it down:
*) Separate PR's per effector would be nice
*) New sensor types as separate PRs (e.g. AbstractCompositeEffector/PeriodicEffectorPolicy.java)
*) Refactors as separate PRs (Moving AddSensor)

This should make it easier to review and merge.

What are your thoughts on this?

@grkvlt
Copy link
Member Author

grkvlt commented May 5, 2017

@Graeme-Miller I think once the tests are added it should be OK, as the individual effectors are all reliant on a single parent abstract class, so they fit together. I will work with @robertgmoss on getting this done and reviewed.

@grkvlt grkvlt force-pushed the feature/composite-effectors branch from d6a09d1 to 8f88cfb Compare May 15, 2017 12:41
@grkvlt grkvlt force-pushed the feature/composite-effectors branch 2 times, most recently from 6ac8152 to 17f7e0f Compare June 5, 2017 15:31
grkvlt and others added 28 commits June 29, 2017 15:47
@grkvlt grkvlt force-pushed the feature/composite-effectors branch from 17f7e0f to 7f28d19 Compare June 29, 2017 14:48
@nakomis
Copy link
Contributor

nakomis commented Nov 26, 2019

@grkvlt Unfortunately it looks like this branch has gone stale since you updated it. Can you have a look to see if it is still relevant (I suspect it is), and rebase against master

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants