Package com.unitesk.aspectrace
Class MessageStream
- java.lang.Object
-
- com.unitesk.aspectrace.MessageStream
-
- Direct Known Subclasses:
TraceToStream
public abstract class MessageStream extends java.lang.Object
A source of stream data represented byraw messages
. Depending on realization may or may not have the beginning and end, work either in model PUSH or PULL. Messages that appear in message stream are being send to all connectedlisteners
.May be used as common data bus of application or application group. Can be converted to
aspect message trace
viaStreamTraceProvider
.Note: Realizations of methods
fireStreamStart()
,fireStreamMessage(AbstractTraceMessage)
andfireStreamEnd(boolean)
are madesynchronized
, but notfinal
.@author Sergey Groshev
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<MessageStreamListener>
listeners
-
Constructor Summary
Constructors Modifier Constructor Description protected
MessageStream()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(MessageStreamListener msl)
Adds listener to the list.protected void
fireStreamEnd(boolean normal)
Sends stream end message to all listeners.protected void
fireStreamMessage(AbstractTraceMessage msg)
Sends message to all listeners.protected void
fireStreamStart()
Sends stream begin message to all listeners.void
process()
Begin message stream processing loop in case of an active stream working in model PULL.void
removeListener(MessageStreamListener msl)
Adds listener to the list.
-
-
-
Field Detail
-
listeners
protected java.util.List<MessageStreamListener> listeners
-
-
Method Detail
-
addListener
public void addListener(MessageStreamListener msl)
Adds listener to the list.
-
removeListener
public void removeListener(MessageStreamListener msl)
Adds listener to the list.
-
process
public void process() throws java.io.IOException, java.lang.IllegalStateException, java.lang.IllegalArgumentException
Begin message stream processing loop in case of an active stream working in model PULL. In this case the realization must call methodfireStreamStart()
at the beginning of processing then extract messages from it's source and call for each of them methodfireStreamMessage(AbstractTraceMessage)
, and in case of stream end (stream may never end) - methodfireStreamEnd(boolean)
with the flag marking either a normal end or abort. Method returns when all messages are extracted and processed or when the message stream closure is not normal.The method realization is empty by default which corresponds with the model PUSH. For the streams working in this model and processing messages from other active sources the corresponding calls must be done in the same order in the corresponding listeners.
- Throws:
java.io.IOException
- Input-Output error.java.lang.IllegalStateException
- Processing has already begun.java.lang.IllegalArgumentException
- Error in stream.
-
fireStreamStart
protected void fireStreamStart()
Sends stream begin message to all listeners. Exceptions from the listeners are being ignored.
-
fireStreamMessage
protected void fireStreamMessage(AbstractTraceMessage msg)
Sends message to all listeners. Exceptions from the listeners are being ignored.
-
fireStreamEnd
protected void fireStreamEnd(boolean normal)
Sends stream end message to all listeners. Exceptions from the listeners are being ignored.
-
-