public class MessageQueue extends Object implements IDisposable
Constructor and Description |
---|
MessageQueue()
Initializes a new instance of this synchronization context
|
Modifier and Type | Method and Description |
---|---|
void |
addMessageQueueStarted(EventHandler<EventArgs> value)
Event that indicates
MessageQueue has started to receive messages. |
void |
addMessageQueueStopped(EventHandler<EventArgs> value)
Event that indicates
MessageQueue has been stopped by a call to MessageQueue.terminate() . |
void |
addMessageReceived(EventHandler<MessageEventArgs> value)
Event that indicates a generic message object was received.
|
void |
dispose()
Releases any resources associated with this instance.
|
protected void |
dispose(boolean disposing)
Releases any resources associated with this instance.
|
int |
getMaximumQueueLength()
Gets the maximum number of items that is allowed in the queue.
|
void |
post(Object message)
|
void |
post(SendOrPostCallback callbackMethod,
Object state)
Adds a delegate to the message queue and immediately returns
|
void |
removeMessageQueueStarted(EventHandler<EventArgs> value)
Event that indicates
MessageQueue has started to receive messages. |
void |
removeMessageQueueStopped(EventHandler<EventArgs> value)
Event that indicates
MessageQueue has been stopped by a call to MessageQueue.terminate() . |
void |
removeMessageReceived(EventHandler<MessageEventArgs> value)
Event that indicates a generic message object was received.
|
void |
send(Object message)
|
void |
send(SendOrPostCallback callbackMethod,
Object state)
Adds a delegate to the message queue and waits until all currently
queued delegates and the recently added delegate are executed before
returning.
|
void |
setMaximumQueueLength(int value)
Sets the maximum number of items that is allowed in the queue.
|
void |
start()
Runs the message queue in the current thread and does not return until
MessageQueue.terminate() is called |
void |
startInAnotherThread()
Runs the message queue in a separate thread and immediately returns.
|
void |
startInNewThread()
Runs the message queue in a newly spawned worker thread and immediately returns.
|
void |
startInNewThread(String name)
Runs the message queue in a newly spawned worker thread and immediately returns.
|
void |
startInThreadPoolThread()
Runs the message queue in a thread pool thread and immediately returns.
|
void |
terminate()
Terminates the message queue.
|
void |
terminateAndWait()
Terminates the message queue and waits for termination to complete.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close
public MessageQueue()
public final void dispose()
Disposing of a MessageQueue
signals the queue to stop pressing messages. If the message queue
was started with MessageQueue.start()
, the MessageQueue.start()
method will return. If the
message queue was started with MessageQueue.startInAnotherThread()
, the other thread will end.
dispose
in interface IDisposable
protected void dispose(boolean disposing)
disposing
- true
to release both managed and unmanaged resources;
false
to release only unmanaged resources.public final void addMessageReceived(EventHandler<MessageEventArgs> value)
MessageQueue
was
started with a call to MessageQueue.startInAnotherThread()
, this event will be raised in that other thread.public final void removeMessageReceived(EventHandler<MessageEventArgs> value)
MessageQueue
was
started with a call to MessageQueue.startInAnotherThread()
, this event will be raised in that other thread.public final void addMessageQueueStarted(EventHandler<EventArgs> value)
MessageQueue
has started to receive messages. If MessageQueue
was
started with a call to MessageQueue.startInAnotherThread()
, this event will be raised in that other thread.public final void removeMessageQueueStarted(EventHandler<EventArgs> value)
MessageQueue
has started to receive messages. If MessageQueue
was
started with a call to MessageQueue.startInAnotherThread()
, this event will be raised in that other thread.public final void addMessageQueueStopped(EventHandler<EventArgs> value)
MessageQueue
has been stopped by a call to MessageQueue.terminate()
. If MessageQueue
was
started with a call to MessageQueue.startInAnotherThread()
, this event will be raised in that other thread.public final void removeMessageQueueStopped(EventHandler<EventArgs> value)
MessageQueue
has been stopped by a call to MessageQueue.terminate()
. If MessageQueue
was
started with a call to MessageQueue.startInAnotherThread()
, this event will be raised in that other thread.public final int getMaximumQueueLength()
public final void setMaximumQueueLength(int value)
public final void startInThreadPoolThread()
MessageQueue.terminate()
is called.public final void startInNewThread()
MessageQueue.terminate()
is called.public final void startInNewThread(String name)
MessageQueue.terminate()
is called.name
- The name of the thread. Naming a thread can make it easier to identify while debugging.public final void startInAnotherThread()
MessageQueue.startInThreadPoolThread()
or MessageQueue.startInNewThread()
depending on the
value of ThreadSource
(get
/ set
) in the ThreadingPolicy
.public final void start()
MessageQueue.terminate()
is calledpublic final void send(SendOrPostCallback callbackMethod, Object state)
callbackMethod
- The SendOrPostCallback
delegate to call.state
- The object passed to the delegate.public final void post(SendOrPostCallback callbackMethod, Object state)
callbackMethod
- The SendOrPostCallback
delegate to call.state
- The object passed to the delegate.public final void send(Object message)
MessageReceived
(add
/ remove
).message
- Message to sendpublic final void post(Object message)
MessageReceived
(add
/ remove
).message
- Message to sendpublic final void terminate()
MessageQueue.terminateAndWait()
instead. If the queue is not running when this method is called, the termination request will
still be posted. That means that queue processing, once restarted, will terminate once it reaches
this point in the queue.public final void terminateAndWait()
MessageQueue.terminate()
, this method does not return until the message queue is terminated.
This method must not be called from the thread that is running the message queue. Doing so will
cause a dead-lock because this method cannot return until the message queue terminates and the
queue cannot terminate until this method returns.