All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.terheyden.event.EventRouter Maven / Gradle / Ivy

The newest version!
package com.terheyden.event;

import java.util.UUID;

/**
 * A classic publish-subscribe event router.
 * Sends events to all subscribers using a thread pool.
 *
 * @see EventQuery
 * @see ModifiableEventRouter
 */
public interface EventRouter extends EventSubscriber {

    /**
     * When an event of type {@code eventClass} is published, {@code eventHandler} will be called.
     *
     * @return A UUID that can later be used to unsubscribe.
     */
    UUID subscribe(CheckedConsumer eventHandler);

    /**
     * Publish the given event to all subscribers of the event object's type.
     * This is a non-blocking call; events are always published asynchronously.
     * 

* Example: *

     * {@code
     * // Subscribe to all String events:
     * eventRouter.subscribe(System.out::println);
     * // Publish a String event:
     * eventRouter.publish("Hello World!");
     * }
     * 
* * @param eventObj The event to send to all subscribers */ void publish(T eventObj); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy