Class Event

java.lang.Object
org.osgi.service.event.Event

public class Event extends Object
An event. Event objects are delivered to EventHandler services which subscribe to the topic of the event.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static final class 
    Dictionary to use for Filter matching.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final EventProperties
    The properties carried by this event.
    private final String
    The topic of this event.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Event(String topic, Dictionary<String,?> properties)
    Constructs an event.
    Event(String topic, Map<String,?> properties)
    Constructs an event.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicate the presence of an event property.
    boolean
    equals(Object object)
    Compares this Event object to another object.
    final Object
    Retrieve the value of an event property.
    final String[]
    Returns a list of this event's property names.
    final String
    Returns the topic of this event.
    int
    Returns a hash code value for this object.
    final boolean
    matches(org.osgi.framework.Filter filter)
    Tests this event's properties against the given filter using a case sensitive match.
    Returns the string representation of this event.
    private static void
    Called by the constructor to validate the topic name.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • topic

      private final String topic
      The topic of this event.
    • properties

      private final EventProperties properties
      The properties carried by this event. Keys are strings and values are objects
  • Constructor Details

    • Event

      public Event(String topic, Map<String,?> properties)
      Constructs an event.
      Parameters:
      topic - The topic of the event.
      properties - The event's properties (may be null). A property whose key is not of type String will be ignored. If the specified properties is an EventProperties object, then it will be directly used. Otherwise, a copy of the specified properties is made.
      Throws:
      IllegalArgumentException - If topic is not a valid topic name.
      Since:
      1.2
    • Event

      public Event(String topic, Dictionary<String,?> properties)
      Constructs an event.
      Parameters:
      topic - The topic of the event.
      properties - The event's properties (may be null). A property whose key is not of type String will be ignored. A copy of the specified properties is made.
      Throws:
      IllegalArgumentException - If topic is not a valid topic name.
  • Method Details

    • getProperty

      public final Object getProperty(String name)
      Retrieve the value of an event property. The event topic may be retrieved with the property name "event.topics".
      Parameters:
      name - The name of the property to retrieve.
      Returns:
      The value of the property, or null if not found.
    • containsProperty

      public final boolean containsProperty(String name)
      Indicate the presence of an event property. The event topic is present using the property name "event.topics".
      Parameters:
      name - The name of the property.
      Returns:
      true if a property with the specified name is in the event. This property may have a null value. false otherwise.
      Since:
      1.3
    • getPropertyNames

      public final String[] getPropertyNames()
      Returns a list of this event's property names. The list will include the event topic property name "event.topics".
      Returns:
      A non-empty array with one element per property.
    • getTopic

      public final String getTopic()
      Returns the topic of this event.
      Returns:
      The topic of this event.
    • matches

      public final boolean matches(org.osgi.framework.Filter filter)
      Tests this event's properties against the given filter using a case sensitive match.
      Parameters:
      filter - The filter to test.
      Returns:
      true If this event's properties match the filter, false otherwise.
    • equals

      public boolean equals(Object object)
      Compares this Event object to another object.

      An event is considered to be equal to another event if the topic is equal and the properties are equal. The properties are compared using the java.util.Map.equals() rules which includes identity comparison for array values.

      Overrides:
      equals in class Object
      Parameters:
      object - The Event object to be compared.
      Returns:
      true if object is a Event and is equal to this object; false otherwise.
    • hashCode

      public int hashCode()
      Returns a hash code value for this object.
      Overrides:
      hashCode in class Object
      Returns:
      An integer which is a hash code value for this object.
    • toString

      public String toString()
      Returns the string representation of this event.
      Overrides:
      toString in class Object
      Returns:
      The string representation of this event.
    • validateTopicName

      private static void validateTopicName(String topic)
      Called by the constructor to validate the topic name.
      Parameters:
      topic - The topic name to validate.
      Throws:
      IllegalArgumentException - If the topic name is invalid.