diff --git a/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/VmChannel.java b/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/VmChannel.java index 4336ca8..47917e6 100644 --- a/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/VmChannel.java +++ b/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/VmChannel.java @@ -27,11 +27,13 @@ import org.jgrapes.core.Subchannel.DefaultSubchannel; /** * A subchannel used to send the events related to a specific VM. */ +@SuppressWarnings("PMD.DataClass") public class VmChannel extends DefaultSubchannel { private final EventPipeline pipeline; private final ApiClient client; private JsonObject vmDefinition; + private long generation = -1; /** * Instantiates a new watch channel. @@ -68,6 +70,31 @@ public class VmChannel extends DefaultSubchannel { 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. * diff --git a/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/VmWatcher.java b/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/VmWatcher.java index f20c52e..61c23f0 100644 --- a/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/VmWatcher.java +++ b/org.jdrupes.vmoperator.manager/src/org/jdrupes/vmoperator/manager/VmWatcher.java @@ -244,6 +244,15 @@ public class VmWatcher extends Component { 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 .valueOf(item.type), vmsCrd, item.object), channel); }