> For the complete documentation index, see [llms.txt](https://fluxtion.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fluxtion.gitbook.io/docs/examples/reference/child-2/clean-node-monitoring.md).

# Clean node conditional branching

## Introduction

The goal is to only let the execution path propagate if a node does not mark itself as being dirty. This is the inverse of [dirty node monitoring](/docs/examples/reference/child-2/dirty-node-monitoring.md).

Sometimes we want to know if a node did not issue a dirty notification after processing an update. Taking the example of the breach indicator we may want to trigger an execution path branch when the limit is not breached.&#x20;

An OnEvent method with a boolean return type is monitored as a dirty status flag by Fluxtion with the following rules:

* A true value marks the node as dirty Fluxtion swallows the event wave and no child OnEvent methods are invoked.
* A false value marks the node as clean and the event wave propagates to child nodes.

The child node indicates it wants to be notified on clean status by adding the dirty = true attribute to its OnEvent annotation:&#x20;

```java
@OnEvent(dirty = false)
```

## Example

We create an event handler that issues a change notification flag. We connect three listener to this each with different behaviours depending upon the dirty flag status of the parent. The listeners are:

| Node               | Behaviour                                                                                                                                                                                |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DirtyListener      | changeUpdate() invoked when the parent indicates a change                                                                                                                                |
| CleanListener      | noChangeUpdate() invoked when parent indicates no change                                                                                                                                 |
| DirtyCleanListener | <p>Combines clean and dirty listeners into one class:</p><p>changeUpdate() invoked when the parent indicates a change</p><p>noChangeUpdate() invoked when parent indicates no change</p> |

The nodes CleanListener and DirtyCleanListener use the dirty flag = false on the OnEvent annotation to indicate they are interested in receiving clean notifications.

the code for the example is located [here](https://github.com/v12technology/fluxtion/tree/master/examples/documentation-examples/src/main/java/com/fluxtion/example/core/events/clean).

### Node classes

```java
public class CleanListener {

    private final Object parent;
    
    @OnEvent(dirty = false)
    public void noChangeUpdate() {}
}

public class DirtyListener {
   
    private final Object parent;

    @OnEvent
    public void changeUpdate() {} 
}

public class DirtyCleanListener {
       
    private final Object parent;

    @OnEvent
    public void changeUpdate() {} 
    
    @OnEvent(dirty = false)
    public void noChangeUpdate() {}
}
```

### Generated SEP

The dispatch method inverts the return type from the parent node when the child is listening for "clean" parents. As we expect there are four callback methods in the dispatch.

```java
public class SampleProcessor implements EventHandler, BatchHandler, Lifecycle {

  //Node declarations
  private final ConditioningHandler conditioningHandler_1 = new ConditioningHandler();
  private final CleanListener cleanListener_3 = new CleanListener(conditioningHandler_1);
  private final DirtyCleanListener dirtyCleanListener_7 =
      new DirtyCleanListener(conditioningHandler_1);
  private final DirtyListener dirtyListener_5 = new DirtyListener(conditioningHandler_1);
  //Dirty flags
  private boolean isDirty_conditioningHandler_1 = false;
  //Filter constants

  public SampleProcessor() {}

  public void handleEvent(MyEvent typedEvent) {
    //Default, no filter methods
    isDirty_conditioningHandler_1 = conditioningHandler_1.onEvent(typedEvent);
    if (!isDirty_conditioningHandler_1) {
      cleanListener_3.noChangeUpdate();
    }
    if (isDirty_conditioningHandler_1) {
      dirtyCleanListener_7.changeUpdate();
    }
    if (!isDirty_conditioningHandler_1) {
      dirtyCleanListener_7.noChangeUpdate();
    }
    if (isDirty_conditioningHandler_1) {
      dirtyListener_5.changeUpdate();
    }
    //event stack unwind callbacks
    afterEvent();
  }

  @Override
  public void afterEvent() {

    isDirty_conditioningHandler_1 = false;
  }

}
```

### Generated png&#x20;

The graphical representation of this execution graph as generated by Fluxtion ESC:

![Sample SEP for clean and dirty listeners](/files/-LU-C2O2QtVtEMgQ_hta)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fluxtion.gitbook.io/docs/examples/reference/child-2/clean-node-monitoring.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
