Package org.appng.api.messaging
Class Messaging
- java.lang.Object
-
- org.appng.api.messaging.Messaging
-
-
Field Summary
Fields Modifier and Type Field Description static String
APPNG_NODE_ID
Name of a system property used to identify the node
-
Constructor Summary
Constructors Constructor Description Messaging()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Sender
createMessageSender(Environment env, ExecutorService executor)
static Sender
createMessageSender(Environment env, ExecutorService executor, String nodeId, EventHandler<? extends Event> defaultHandler, Iterable<EventHandler<? extends Event>> handlers)
static Sender
getMessageSender(Environment env)
Retrieves the previously createdSender
from theEnvironment
.static String
getNodeId(Environment env)
Determines the node id for this node.protected static Properties
getPlatformConfig(Environment env)
static boolean
isEnabled(Environment env)
static void
shutdown(Environment env)
Shuts down the messaging system, i.e.
-
-
-
Field Detail
-
APPNG_NODE_ID
public static final String APPNG_NODE_ID
Name of a system property used to identify the node- See Also:
- Constant Field Values
-
-
Method Detail
-
getMessageSender
public static Sender getMessageSender(Environment env)
Retrieves the previously createdSender
from theEnvironment
.- Parameters:
env
- theEnvironment
to use- Returns:
- the
Sender
, if available - See Also:
createMessageSender(Environment, ExecutorService)
,createMessageSender(Environment, ExecutorService, String, EventHandler, Iterable)
-
createMessageSender
public static Sender createMessageSender(Environment env, ExecutorService executor)
Creates and returns a newSender
and a correspondingReceiver
. The class name for the receiver is taken from the platform property "messagingReceiver". Uses the system property "appng.node.id" to retrieve the node id for theSerializer
. If this property is absent, the local host name is used and the property is set.- Parameters:
env
- theEnvironment
to useexecutor
- theExecutorService
to run theReceiver
with- Returns:
- the
Sender
(if the platform property "messagingEnabled" istrue
null
if messaging is disabled or an error occurred while creating the sender
- the
-
getNodeId
public static String getNodeId(Environment env)
Determines the node id for this node. If the system property "appng.node.id" is set, this value is used. Otherwise, the local host name is used (fromjava.net.InetAddress.getLocalHost().getHostName()
}).- Parameters:
env
- theEnvironment
to use- Returns:
- the node id for this node
-
getPlatformConfig
protected static Properties getPlatformConfig(Environment env)
-
createMessageSender
public static Sender createMessageSender(Environment env, ExecutorService executor, String nodeId, EventHandler<? extends Event> defaultHandler, Iterable<EventHandler<? extends Event>> handlers)
Creates and returns a newSender
and a correspondingReceiver
. The class name for the receiver is taken from the platform property "messagingReceiver".- Parameters:
env
- theEnvironment
to useexecutor
- theExecutorService
to run theReceiver
withnodeId
- the node id for theSerializer
defaultHandler
- the defaultEventHandler
for theReceiver
(may benull
)handlers
- a list ofEventHandler
s to be registered at theReceiver
- Returns:
- the
Sender
(if the platform property "messagingEnabled" istrue
null
if messaging is disabled or an error occurred while creating the sender
- the
-
isEnabled
public static boolean isEnabled(Environment env)
-
shutdown
public static void shutdown(Environment env)
Shuts down the messaging system, i.e. callsCloseable.close()
for theSender
and theReceiver
(in case the latter do implementCloseable
)- Parameters:
env
- thenEnvironment
to use
-
-