Class AbstractEventFactory

    • Constructor Detail

      • AbstractEventFactory

        public AbstractEventFactory​(Set<String> supportedEventTypes)
        Must be called in subclass constructor to define the supported event types.
        Parameters:
        supportedEventTypes - the supported event types
    • Method Detail

      • createEvent

        public Event createEvent​(String eventType,
                                 String topic,
                                 String payload,
                                 @Nullable String source)
                          throws Exception
        Description copied from interface: EventFactory
        Create a new event instance of a specific event type.
        Specified by:
        createEvent in interface EventFactory
        Parameters:
        eventType - the event type
        topic - the topic
        payload - the payload
        source - the source (can be null)
        Returns:
        the created event instance (not null)
        Throws:
        IllegalArgumentException - if eventType, topic or payload is null or empty
        Exception - if the creation of the event has failed
      • getSupportedEventTypes

        public Set<String> getSupportedEventTypes()
        Description copied from interface: EventFactory
        Returns a list of all supported event types of this factory.
        Specified by:
        getSupportedEventTypes in interface EventFactory
        Returns:
        the supported event types (not null)
      • createEventByType

        protected abstract Event createEventByType​(String eventType,
                                                   String topic,
                                                   String payload,
                                                   @Nullable String source)
                                            throws Exception
        Create a new event instance based on the event type.
        Parameters:
        eventType - the event type
        topic - the topic
        payload - the payload
        source - the source, can be null
        Returns:
        the created event instance
        Throws:
        Exception - if the creation of the event fails
      • serializePayload

        protected static String serializePayload​(Object payloadObject)
        Serializes the payload object into its equivalent Json representation.
        Parameters:
        payloadObject - the payload object to serialize
        Returns:
        a serialized Json representation
      • deserializePayload

        protected static <T> T deserializePayload​(String payload,
                                                  Class<T> classOfPayload)
        Deserializes the Json-payload into an object of the specified class.
        Type Parameters:
        T - the type of the returned object
        Parameters:
        payload - the payload from which the object is to be deserialized
        classOfPayload - the class T of the payload object
        Returns:
        an object of type T from the payload
      • getTopicElements

        protected String[] getTopicElements​(String topic)
        Gets the elements of the topic (splitted by '/').
        Parameters:
        topic - the topic
        Returns:
        the topic elements
      • checkNotNull

        protected static void checkNotNull​(@Nullable Object object,
                                           String argumentName)
      • checkNotNullOrEmpty

        protected static void checkNotNullOrEmpty​(@Nullable String string,
                                                  String argumentName)