Package org.djutils.event
Class AbstractEventType
- java.lang.Object
-
- org.djutils.event.AbstractEventType
-
- All Implemented Interfaces:
Serializable
,EventTypeInterface
- Direct Known Subclasses:
EventType
,TimedEventType
public abstract class AbstractEventType extends Object implements EventTypeInterface
Reference implementation of the EventType. The AbstractEventType is the description of a topic used for the subscription to asynchronous events. Event types are used by EventProducers to show which events they potentially fire. EventTypes are typically defined as static final fields. In order to prevent name clashes for the EventType, the full name of the class from which the EventType was defined (usually in the <clinit>) is added to the equals() and hashCode() methods of the EventType. In that way, EventTypes that are the same will be unique, but EventTypes with just the same name but defined in different classes will be different. This is the abstract class that can be tailored to any event type. Subclasses that extend the AbstractEventType are the EventType for regular events, and TimedEventType for timed events.
Note: the reason why this is important is because remote events that use EventTypes can have multiple versions of the same public static final EventType: one the is defined in the client, and one that is defined via the network. These will have different addresses in memory but they share the same class and name info, so equals() will yield true.Copyright (c) 2002-2021 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djutils.org. The DJUTILS project is distributed under a three-clause BSD-style license, which can be found at https://djutils.org/docs/license.html. This class was originally part of the DSOL project, see https://simulation.tudelft.nl/dsol/manual.
- Author:
- Peter Jacobs , Alexander Verbraeck
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AbstractEventType(String name, MetaData metaData, Class<? extends EventInterface> validEventType)
Construct a new EventType with an explicit type of event that is considered to be a valid event when the event is verified.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
MetaData
getMetaData()
Retrieve the MetaData that describes the payload of events of this EventType.String
getName()
Return the event type name.Class<? extends EventInterface>
getValidEventType()
Retrieve the event type that defines valid events of this EventType, e.g., to indicate a TimedEvent is expected.int
hashCode()
String
toString()
-
-
-
Constructor Detail
-
AbstractEventType
public AbstractEventType(String name, MetaData metaData, Class<? extends EventInterface> validEventType)
Construct a new EventType with an explicit type of event that is considered to be a valid event when the event is verified. This can, for instance, be used to verify that a TimedEvent is fired instead of an ordinary event.- Parameters:
name
- String; the name of the new eventType. Two values are not appreciated: null and the empty string.metaData
- MetaData; describes the payload of events of the new EventType;validEventType
- Class<? extends EventInterface>; the valid class of events
-
-
Method Detail
-
getName
public String getName()
Return the event type name.- Specified by:
getName
in interfaceEventTypeInterface
- Returns:
- String; the event type name
-
getMetaData
public MetaData getMetaData()
Retrieve the MetaData that describes the payload of events of this EventType.- Specified by:
getMetaData
in interfaceEventTypeInterface
- Returns:
- MetaData; describes the payload of events of this EventType
-
getValidEventType
public Class<? extends EventInterface> getValidEventType()
Retrieve the event type that defines valid events of this EventType, e.g., to indicate a TimedEvent is expected.- Specified by:
getValidEventType
in interfaceEventTypeInterface
- Returns:
- Class<EventTypeInterface>; the class of valid events of this event type
-
-