Skip to content

Commit

Permalink
Added callback on trigger attach to fix bug on FilteredTrigger
Browse files Browse the repository at this point in the history
FilteredTrigger did not bind the ExecutionManager to the wrapped
trigger because it had no callback to do so.
  • Loading branch information
Manciukic committed Aug 9, 2019
1 parent 7996994 commit f8e543f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ public Chooser(){ }

/**
* Performs actions after the {@link ExecutionManager} is bound.
* It does nothing unless overwritten.
* It does nothing unless overridden.
*
* @see #attach(ExecutionManager)
*/
public void onAttach(){}

/**
* Performs actions before the {@link ExecutionManager} is unbound.
* It does nothing unless overwritten.
* It does nothing unless overridden.
*
* @see #detach()
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private ExecutionManager addTriggerGeneric(String dataKey, String triggerKey,
throw new StoreNotDefinedException(dataKey);

if (store.getDataType().equals(trigger.getDataType())){
trigger.bindExecutionManager(this);
trigger.attach(this);
store.addObserver(triggerKey, trigger);
map.put(triggerKey, dataKey);
} else
Expand Down Expand Up @@ -338,7 +338,7 @@ public boolean removeTriggerGeneric(String triggerKey, Map<String, String> map){
if (trigger == null)
return false;

trigger.unbindExecutionManager();
trigger.detach();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*
* @author Riccardo Mancini
*/
//TODO missing binding of the wrapped trigger with the ExecutionManager
public class FilteredTrigger<T extends Data> extends Trigger<T> {

/**
Expand Down Expand Up @@ -56,4 +55,20 @@ public void onDataStored(Store<T> store, T... data) {
if (data[0].getRequestID() == requestID)
trigger.onDataStored(store, data);
}

/**
* Calls {@link Trigger#attach(ExecutionManager)} on the wrapped {@link Trigger}.
*/
@Override
public void onAttach() {
trigger.attach(getExecutionManager());
}

/**
* Calls {@link Trigger#detach()} on the wrapped {@link Trigger}.
*/
@Override
public void onDetach() {
trigger.detach();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ protected void publishResults(S... data){

/**
* Performs actions after the {@link ExecutionManager} is bound.
* It does nothing unless overwritten.
* It does nothing unless overridden.
*
* @see #attach(ExecutionManager, Store, Store)
*/
public void onAttach(){}

/**
* Performs actions before the {@link ExecutionManager} is unbound.
* It does nothing unless overwritten.
* It does nothing unless overridden.
*
* @see #detach()
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,21 @@ public Class<T> getDataType() {
}

/**
* Binds the {@link ExecutionManager} to this {@link Trigger}.
* Attaches to the {@link ExecutionManager} and calls {@link #onAttach()}.
*
* @param executionManager the {@link ExecutionManager} that is being bound.
* @param executionManager the {@link ExecutionManager} that is being attached.
*/
public void bindExecutionManager(ExecutionManager executionManager){
public void attach(ExecutionManager executionManager){
this.executionManager = executionManager;
onAttach();
}

/**
* Unbinds the {@link ExecutionManager} previously bound to this {@link Trigger}.
* Detaches from the {@link ExecutionManager} attached to this {@link Trigger} after calling
* {@link #onDetach()}.
*/
public void unbindExecutionManager(){
public void detach(){
onDetach();
this.executionManager = null;
}

Expand All @@ -60,4 +63,20 @@ public void unbindExecutionManager(){
protected ExecutionManager getExecutionManager() {
return executionManager;
}

/**
* Performs actions after the {@link ExecutionManager} is bound.
* It does nothing unless overridden.
*
* @see #attach(ExecutionManager)
*/
public void onAttach(){}

/**
* Performs actions before the {@link ExecutionManager} is unbound.
* It does nothing unless overridden.
*
* @see #detach()
*/
public void onDetach(){}
}

0 comments on commit f8e543f

Please sign in to comment.