Class ISCMessageDispatcher

java.lang.Object
com.isomorphic.messaging.ISCMessageDispatcher

public abstract class ISCMessageDispatcher extends Object
This is the base local dispatcher - it is an abstract class that provides same-jvm registration management and channel subscriptions. Use it to obtain a concrete message dispatcher class.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    Closes the underlying broker connection held by this dispatcher without releasing other resources first.
    Returns a new instance of the configured concrete ISCMessageDispatcher class - scan the client-side documentation for "messaging.dispatcherImplementer" for details of how this is configured.
    Equivalent to instance(); the context parameter is ignored.
    boolean
    isSubscribed(ISubscriber subscriber, String channel)
    Check to see if a given subscriber is subscribed to a given channel.
    void
    register(ISubscriber subscriber)
    register this subscriber
    void
    send a message
    abstract void
    Releases all resources held by this dispatcher.
    void
    subscribe(ISubscriber subscriber, String channel)
    subscribe a given subscriber to a given channel
    abstract void
    subscribe(ISubscriber subscriber, String channel, String selector)
    subscribe a given subscriber to a given channel
    void
    unregister(ISubscriber subscriber)
    unregister this subscriber
    abstract void
    unsubscribe(ISubscriber subscriber, String channel)
    unsubscribe a given subscriber from a given channel
  • Method Details

    • instance

      public static ISCMessageDispatcher instance() throws Exception
      Returns a new instance of the configured concrete ISCMessageDispatcher class - scan the client-side documentation for "messaging.dispatcherImplementer" for details of how this is configured. NOTE: This method is a factory, not a singleton accessor: it creates a fresh dispatcher - and, on first use, a new broker connection - on every call.

      For server-side publishing (e.g. from a DMI method), callers must cache and reuse the returned dispatcher across calls rather than invoking instance() on each send. Creating a new dispatcher per send will open a new broker connection each time and never close it, leaking connections and their associated threads until the application is restarted. The recommended pattern is a lazily-initialised static reference:

           private static ISCMessageDispatcher dispatcher;
      
           private static synchronized ISCMessageDispatcher getDispatcher() throws Exception {
               if (dispatcher == null) dispatcher = ISCMessageDispatcher.instance();
               return dispatcher;
           }
       
      To release the dispatcher and its underlying resources (e.g. in a ServletContextListener.contextDestroyed callback), call stop().
      Returns:
      a new concrete ISCMessageDispatcher for sending/receiving Realtime Messages.
      Throws:
      Exception
    • instance

      public static ISCMessageDispatcher instance(RequestContext context) throws Exception
      Equivalent to instance(); the context parameter is ignored. This overload exists for backwards compatibility only.
      Parameters:
      context - ignored
      Returns:
      a new concrete ISCMessageDispatcher for sending/receiving Realtime Messages.
      Throws:
      Exception
    • register

      public void register(ISubscriber subscriber) throws Exception
      register this subscriber
      Parameters:
      subscriber -
      Throws:
      Exception
    • unregister

      public void unregister(ISubscriber subscriber) throws Exception
      unregister this subscriber
      Parameters:
      subscriber -
      Throws:
      Exception
    • subscribe

      public void subscribe(ISubscriber subscriber, String channel) throws Exception
      subscribe a given subscriber to a given channel
      Parameters:
      subscriber -
      channel -
      Throws:
      Exception
    • subscribe

      public abstract void subscribe(ISubscriber subscriber, String channel, String selector) throws Exception
      subscribe a given subscriber to a given channel
      Parameters:
      subscriber -
      channel -
      selector -
      Throws:
      Exception
    • unsubscribe

      public abstract void unsubscribe(ISubscriber subscriber, String channel) throws Exception
      unsubscribe a given subscriber from a given channel
      Parameters:
      subscriber -
      channel -
      Throws:
      Exception
    • send

      public void send(ISCMessage msg) throws Exception
      send a message
      Parameters:
      msg -
      Throws:
      Exception
    • stop

      public abstract void stop()
      Releases all resources held by this dispatcher. You can call this when the dispatcher is no longer needed — for example in a ServletContextListener.contextDestroyed callback — to ensure that the underlying broker connection and its threads are shut down cleanly.

      You can also use this method to reset the existing connection when the underlying broker throws an Exception or otherwise reports a problem on send(ISCMessage). stop() closes and deletes its connection reference, which causes the next send() on the dispatcher to create a new connection.

    • closeConnection

      public abstract void closeConnection()
      Closes the underlying broker connection held by this dispatcher without releasing other resources first. Prefer stop(), which releases all resources in the correct order. This method is provided for advanced use cases such as forcing a reconnect after a configuration change.
    • isSubscribed

      public boolean isSubscribed(ISubscriber subscriber, String channel) throws Exception
      Check to see if a given subscriber is subscribed to a given channel. Note: not applicable to JMS (meaningless in a distributed context)
      Parameters:
      subscriber -
      channel -
      Returns:
      true if subscribed, false if not
      Throws:
      Exception