Package com.groiss.notification
Class NotificationSuite
java.lang.Object
com.groiss.notification.NotificationSuite
A facade to the Notification framework. The primary entry point to send messages to clients.
-
Method Summary
Modifier and TypeMethodDescriptionstatic NotificationEvent
createEvent
(NotificationItem ni, short type, Agent a) Create a NotificationEvent from a NotificationItem.static void
Disables sending of notification for this transaction Default is enabled.static void
Enables sending of notification for this transaction.static boolean
Determine if Notifications are enabled for this transaction.static void
notifySession
(HttpSession session, String topic, Map<String, ?> payload) Send a message to smartclients.static void
notifyUser
(User user, String messageTopic, Map<String, ?> payload) Send a message to smartclients.static void
Publish an event.static void
publish
(NotificationItem ni, short type) Publish a NotificationItem.static void
publish
(NotificationItem ni, short type, Agent a) Publish a NotificationItem.static void
Publish an event immediately.static void
publishImmediate
(NotificationItem ni, short type) Publish a NotificationItem immediately.static void
publishImmediate
(NotificationItem ni, short type, Agent a) Publish a NotificationItem immediately.static void
setAvoidAutoNotification
(boolean avoidAutoNotification) Avoid sending of notifications to originating session.static void
setMeToo
(boolean meToo) Send notifications also to originating session.
-
Method Details
-
disableNotification
public static void disableNotification()Disables sending of notification for this transaction Default is enabled. After commit or rollback, it is enabled again. The state is checked only at commit time. This means that the last disable or enable operation is the relevant one. You cannot disable or enable single notifications within one transaction. -
enableNotification
public static void enableNotification()Enables sending of notification for this transaction. Default is enabled. After commit or rollback, it is enabled again. The state is checked only at commit time. This means that the last disable or enable operation is the relevant one. You cannot disable or enable single notifications within one transaction. -
isNotificationEnabled
public static boolean isNotificationEnabled()Determine if Notifications are enabled for this transaction.- Returns:
- true, if Notifications are enabled for this transactions, false otherwise.
-
createEvent
Create a NotificationEvent from a NotificationItem. Usually, its not needed to explicitly create the event since NotificationItems can be published too.- Parameters:
ni
- the item to be contained in the event objecttype
- the event typeNames
a
- the agent for which the event is destined- Returns:
-
publish
Publish a NotificationItem. The item is published after the current transaction commits (and suppressed if the transaction is rolled back). The agent to publish to is determined byNotificationItem.getAgent()
- Parameters:
ni
- the item to publishtype
- the event typeNames
-
publish
Publish a NotificationItem. The item is published after the current transaction commits (and suppressed if the transaction is rolled back).- Parameters:
ni
- the item to publishtype
- the event typeNames
a
- the agent to sent the event to.
-
publish
Publish an event. Events are only needed in special cases. Usually, NotificationItems should be published. The event is published after the current transaction commits (and suppressed if the transaction is rolled back).- Parameters:
e
-
-
publishImmediate
Publish an event immediately. Events are only needed in special cases. Usually, NotificationItems should be published. The event is published instantaneously.- Parameters:
e
-- Throws:
Exception
-
publishImmediate
Publish a NotificationItem immediately. The item is published instantaneously. The agent to publish to is determined byNotificationItem.getAgent()
-
publishImmediate
Publish a NotificationItem immediately. The item is published instantaneously. -
setMeToo
public static void setMeToo(boolean meToo) Send notifications also to originating session. Normally, the originating CometD session does not receive the events via notification but rather synchronously via the initiating thread.This behavior can be changed (for all events in the current transaction), by setting meToo to true.
N.B.:
meToo
is ignored, whenavoidAutoNotification
is set.meToo
is automatically set to true if the changing function has not been called from the main window.- Parameters:
meToo
- true when notifications should also be send to the originating session.
-
setAvoidAutoNotification
public static void setAvoidAutoNotification(boolean avoidAutoNotification) Avoid sending of notifications to originating session. Normally, the originating CometD session does receive the events from itself if the the changing function has not been called from the main window.This behavior can be avoided (for all events in the current transaction), by setting avoidAutoNotification to true. Then,
N.B.:
avoidAutoNotification
is stronger thanmeToo
.- Parameters:
avoidAutoNotification
- true when sending to current session should be avoided.
-
notifyUser
public static void notifyUser(User user, String messageTopic, Map<String, ?> payload) throws ExceptionSend a message to smartclients. Sends a JSONObject in a CometD message to all sessions of the specified user instantly. At the client, the JSONObject is accessible under the key "payload".- Parameters:
user
- the user to notifymessageTopic
- the topic of the messagepayload
- a map that will be used to create the JSONObject. Elements must be Serializable.- Throws:
Exception
-
notifySession
public static void notifySession(HttpSession session, String topic, Map<String, ?> payload) throws ExceptionSend a message to smartclients. Sends a JSONObject in a CometD message to a specific HttpSession instantly. At the client, the JSONObject is accessible under the key "payload". The session must be properly authenticated.- Parameters:
session
- the session (on this node)topic
- the topic of the messagepayload
- a map that will be used to create the JSONObject. Elements must be Serializable.- Throws:
Exception
-