Filter duplicate events.
This commit is contained in:
parent
a3bbeafdf6
commit
0d5e680318
2 changed files with 36 additions and 0 deletions
|
|
@ -27,11 +27,13 @@ import org.jgrapes.core.Subchannel.DefaultSubchannel;
|
||||||
/**
|
/**
|
||||||
* A subchannel used to send the events related to a specific VM.
|
* A subchannel used to send the events related to a specific VM.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("PMD.DataClass")
|
||||||
public class VmChannel extends DefaultSubchannel {
|
public class VmChannel extends DefaultSubchannel {
|
||||||
|
|
||||||
private final EventPipeline pipeline;
|
private final EventPipeline pipeline;
|
||||||
private final ApiClient client;
|
private final ApiClient client;
|
||||||
private JsonObject vmDefinition;
|
private JsonObject vmDefinition;
|
||||||
|
private long generation = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new watch channel.
|
* Instantiates a new watch channel.
|
||||||
|
|
@ -68,6 +70,31 @@ public class VmChannel extends DefaultSubchannel {
|
||||||
return vmDefinition;
|
return vmDefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the last processed generation. Returns -1 if no
|
||||||
|
* definition has been processed yet.
|
||||||
|
*
|
||||||
|
* @return the generation
|
||||||
|
*/
|
||||||
|
public long generation() {
|
||||||
|
return generation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the last processed generation.
|
||||||
|
*
|
||||||
|
* @param generation the generation to set
|
||||||
|
* @return true if value has changed
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("PMD.LinguisticNaming")
|
||||||
|
public boolean setGeneration(long generation) {
|
||||||
|
if (this.generation == generation) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.generation = generation;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the pipeline.
|
* Returns the pipeline.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -244,6 +244,15 @@ public class VmWatcher extends Component {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (channel == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter duplicates
|
||||||
|
if (!"DELETED".equals(item.type) && !channel
|
||||||
|
.setGeneration(item.object.getMetadata().getGeneration())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
channel.pipeline().fire(new VmDefChanged(VmDefChanged.Type
|
channel.pipeline().fire(new VmDefChanged(VmDefChanged.Type
|
||||||
.valueOf(item.type), vmsCrd, item.object), channel);
|
.valueOf(item.type), vmsCrd, item.object), channel);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue