X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fsal%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Faction%2FAction.java;h=981b175e197242a0e4347b3407ad3cfc86cb3576;hp=8fc8fc16bf59b9f7248b093070783657f834c066;hb=73e969cf365dd78772596c71e940ae44fe2f22d3;hpb=b8bb7db7c6133e00046e85ead70426eb1e05184d diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/Action.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/Action.java index 8fc8fc16bf..981b175e19 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/Action.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/Action.java @@ -8,45 +8,45 @@ package org.opendaylight.controller.sal.action; -import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ConcurrentHashMap; + +import org.opendaylight.controller.sal.core.Property; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlSeeAlso; -import javax.xml.bind.annotation.XmlTransient; +import java.io.Serializable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + /** * Represents the generic action to be applied to the matched * frame/packet/message */ @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) -@XmlSeeAlso({ Controller.class, Drop.class, Flood.class, FloodAll.class, HwPath.class, Loopback.class, Output.class, - PopVlan.class, PushVlan.class, SetDlDst.class, SetDlSrc.class, SetDlType.class, SetNwDst.class, SetNwSrc.class, - SetNwTos.class, SetTpDst.class, SetTpSrc.class, SetVlanCfi.class, SetVlanId.class, SetVlanPcp.class, - SwPath.class }) public abstract class Action implements Serializable { private static final long serialVersionUID = 1L; private static final Logger logger = LoggerFactory.getLogger(Action.class); private static boolean debug = false; // Enable to find where in the code an // invalid assignment is made - @XmlTransient + @XmlElement protected ActionType type; private transient boolean isValid = true; + private ConcurrentMap props; /* Dummy constructor for JAXB */ public Action() { } - /* - * public Action (ActionType type, Object value) { this.type = type; - * this.value = value; this.isValid = true; } - */ - /** * Checks if the passed value is in the valid range for this action * @@ -93,6 +93,81 @@ public abstract class Action implements Serializable { } } + /** + * Gets the list of metadata currently registered with this match + * + * @return List of metadata currently registered + */ + public List getMetadatas() { + if (this.props != null) { + // Return all the values in the map + Collection res = this.props.values(); + if (res == null) { + return Collections.emptyList(); + } + return new ArrayList(res); + } + return Collections.emptyList(); + } + + /** + * Gets the metadata registered with a name if present + * + * @param name the name of the property to be extracted + * + * @return List of metadata currently registered + */ + public Property getMetadata(String name) { + if (name == null) { + return null; + } + if (this.props != null) { + // Return the Property associated to the name + return this.props.get(name); + } + return null; + } + + /** + * Sets the metadata associated to a name. If the name or prop is NULL, + * an exception NullPointerException will be raised. + * + * @param name the name of the property to be set + * @param prop, property to be set + */ + public void setMetadata(String name, Property prop) { + if (this.props == null) { + props = new ConcurrentHashMap(); + } + + if (this.props != null) { + this.props.put(name, prop); + } + } + + /** + * Remove the metadata associated to a name. If the name is NULL, + * nothing will be removed. + * + * @param name the name of the property to be set + * @param prop, property to be set + * + * @return List of metadata currently registered + */ + public void removeMetadata(String name) { + if (this.props == null) { + return; + } + + if (this.props != null) { + this.props.remove(name); + } + // It's intentional to keep the this.props still allocated + // till the parent data structure will be alive, so to avoid + // unnecessary allocation/deallocation, even if it's holding + // nothing + } + /** * Returns the type of this action * @@ -124,7 +199,7 @@ public abstract class Action implements Serializable { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((type == null) ? 0 : type.hashCode()); + result = prime * result + ((type == null) ? 0 : type.calculateConsistentHashCode()); return result; }