Class EventBusHelper


  • public class EventBusHelper
    extends VertxHelperBase
    A helper class for the Vert.x event bus API. An instance of this class is associated with a VertxBus JavaScript object, defined in the eventbus module, that can publish or subscribe to events on the event bus event. The VertxBus object is passed in as a constructor argument and is expected to implement the event emitter pattern, for example by inheriting from EventEmitter class of the events module using util.inherits().

    For information about the Vert.x event bus, see http://vertx.io/core_manual_java.html#the-event-bus.

    Since:
    Ptolemy II 11.0
    Version:
    $Id$
    Author:
    Patricia Derler and Edward A. Lee
    Pt.AcceptedRating:
    Red (pd)
    Pt.ProposedRating:
    Yellow (pd)
    • Constructor Detail

      • EventBusHelper

        public EventBusHelper​(java.lang.Object actor,
                              jdk.nashorn.api.scripting.ScriptObjectMirror vertxBusJS,
                              int clusterPort,
                              java.lang.String clusterHostname)
        Create an EventBusHelper for the specified actor and VertxBus JavaScript object for the event bus at the specified network interface (port and hostname).

        If the clusterHostname is null, then this will use an unclustered instance of Vertx whose event bus will not communicate with any other instances of Vertx. The clusterHostname is something like "localhost" or "10.0.0.4", and it specifies a local network device over which to listen for cluster connections (e.g. WiFi or Ethernet).

        The clusterPort is the tcp/ip port to which to listen for cluster connections. The default for clusterPort for Vertx is 25500. If clusterHostname is null, then the default clusterPort value is used.

        Parameters:
        actor - The actor that will publish or subscribe to the event bus.
        vertxBusJS - The VertxBus JavaScript object that will publish and subscribe to the event bus.
        clusterPort - The port over which to listen for cluster connections.
        clusterHostname - The host interface over which to listen for cluster connections, or null to create an unclustered EventBusHelper.
    • Method Detail

      • publish

        public void publish​(java.lang.String address,
                            java.lang.String message)
        Publish text data onto the Vertx event bus.
        Parameters:
        address - The address, (topic, channel name, stream ID,...)
        message - A message to be published, as a string.
      • send

        public void send​(java.lang.String address,
                         java.lang.String message)
        Send text data to exactly one recipient on the Vertx event bus. According to the Vert.x documentation, the recipient is choosen in a loosely round-robin fashion. If a reply has been set via setReply(String), then if an when the reply is received, the associated JavaScript object's reply() function will be invoked.
        Parameters:
        address - The address, (topic, channel name, stream ID,...)
        message - A message to be published, as a string.
      • send

        public void send​(java.lang.String address,
                         java.lang.String message,
                         java.lang.Object replyHandler)
        Send text data to exactly one recipient on the Vertx event bus and handle the reply by invoking the specified function. According to the Vert.x documentation, the recipient is choosen in a loosely round-robin fashion. If a reply has been set via setReply(String), then if an when the reply is received, the associated JavaScript object's reply() function will be invoked.
        Parameters:
        address - The address, (topic, channel name, stream ID,...)
        message - A message to be published, as a string.
        replyHandler - The handler for the reply.
      • setReply

        public void setReply​(java.lang.String reply)
        Set the reply to send in response to any point-to-point events received in the future.
        Parameters:
        reply - A reply to send when an event is received, or null to not send any replies.
      • subscribe

        public void subscribe​(java.lang.String address)
        Subscribe to the specified address on the event bus. Whenever an event is published to this address by some client in the event bus cluster, this method will cause an event with the same name as address to be emitted on the associated JavaScript object with the message body as the value of the event. If this object is already subscribed to this address, then do nothing.
        Parameters:
        address - The address on the bus to subscribe to.
        See Also:
        unsubscribe(String)
      • unsubscribe

        public void unsubscribe​(java.lang.String address)
        Unsubscribe the associated JavaScript object as a subscriber to the specified address on the event bus.
        Parameters:
        address - The address on the bus to unsubscribe to, or null to unsubscribe to all addresses.
        See Also:
        subscribe(String)