Package com.isomorphic.messaging
Class ISCMessageDispatcher
java.lang.Object
com.isomorphic.messaging.ISCMessageDispatcher
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 TypeMethodDescriptionabstract voidCloses the underlying broker connection held by this dispatcher without releasing other resources first.static ISCMessageDispatcherinstance()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.static ISCMessageDispatcherinstance(RequestContext context) Equivalent toinstance(); thecontextparameter is ignored.booleanisSubscribed(ISubscriber subscriber, String channel) Check to see if a given subscriber is subscribed to a given channel.voidregister(ISubscriber subscriber) register this subscribervoidsend(ISCMessage msg) send a messageabstract voidstop()Releases all resources held by this dispatcher.voidsubscribe(ISubscriber subscriber, String channel) subscribe a given subscriber to a given channelabstract voidsubscribe(ISubscriber subscriber, String channel, String selector) subscribe a given subscriber to a given channelvoidunregister(ISubscriber subscriber) unregister this subscriberabstract voidunsubscribe(ISubscriber subscriber, String channel) unsubscribe a given subscriber from a given channel
-
Method Details
-
instance
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 aServletContextListener.contextDestroyedcallback), callstop().- Returns:
- a new concrete ISCMessageDispatcher for sending/receiving Realtime Messages.
- Throws:
Exception
-
instance
Equivalent toinstance(); thecontextparameter 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
register this subscriber- Parameters:
subscriber-- Throws:
Exception
-
unregister
unregister this subscriber- Parameters:
subscriber-- Throws:
Exception
-
subscribe
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
unsubscribe a given subscriber from a given channel- Parameters:
subscriber-channel-- Throws:
Exception
-
send
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 aServletContextListener.contextDestroyedcallback — 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 nextsend()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. Preferstop(), 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
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
-