Emitter factory profile settings can be changed by event consumers.
Why and when to perform this task
When sending an event, you can specify options that override
the current transaction mode, synchronization mode, or both, currently configured
for the emitter. These settings are initially defined by an administrator
in the emitter factory profile, but they can later be changed by event consumers.
An
emitter might not support all synchronization and transaction modes. The available
modes are subject to the following limitations:
- The synchronization modes supported by an emitter are defined by the emitter
factory profile. You can find out which modes are supported by a particular
emitter by calling the isSynchronizationModeSupported() method; see the Javadoc
API documentation for com.ibm.events.emitter.Emitter for more information.
- Transactions are supported only in a J2EE container.
If you attempt to use a mode that is not supported, the emitter throws
a TransactionModeNotSupportedException or SynchronizationModeNotSupportedException
exception.
Steps for this task
To override the emitter settings, use the sendEvent(CommonBaseEvent,
int, int) method. String eventId = emitter.sendEvent(event,
synchronizationMode,
transactionMode);
The
parameters are as follows:
- event
- The event object (an instance of CommonBaseEvent) you want to send.
- synchronizationMode
- An integer constant defined by the interface SynchronizationMode. This
should be one of the following constants:
- SynchronizationMode.ASYNCHRONOUS (send the event asynchronously)
- SynchronizationMode.SYNCHRONOUS (send the event synchronously)
- SynchronizationMode.DEFAULT (use the current emitter setting)
- transactionMode
- An integer constant defined by the interface TransactionMode:
- TransactionMode.NEW (send the event in a new transaction)
- TransactionMode.SAME (send the event in the current transaction)
- TransactionMode.DEFAULT (use the current emitter setting)
Result
The event is sent with the options you specify. These options apply
only to the single event being sent; no changes are made to the emitter settings,
and subsequent event submissions are not affected.
The returned value, eventId,
is the globally unique identifier of the event (the value of the globalInstanceId field
of CommonBaseEvent). If the event does not have a globalInstanceId when you
submit it, the emitter assigns one automatically.
Note: Submitting an event
to an emitter does not guarantee that the event is sent to the event server,
because the filter settings might cause the event to be discarded. A successful
call to sendEvent() means only that the event was successfully processed by
the emitter.
Example
The following example overrides the emitter setting to send an
event in a new transaction, but does not override the synchronization mode:
String eventId = sendEvent(event,
SynchronizationMode.DEFAULT,
TransactionMode.NEW);