groovyx.gpars.actor.impl
Class MessageStream

java.lang.Object
  extended by groovyx.gpars.serial.WithSerialId
      extended by groovyx.gpars.actor.impl.MessageStream
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Actor, DataCallback, DataCallbackWithPool, DataflowExpression.DataflowExpressionsCollector, MessageStream.RemoteMessageStream, MessageStream.ResultWaiter

public abstract class MessageStream
extends WithSerialId

Represents a stream of messages and forms the base class for actors

Author:
Alex Tkachman, Vaclav Pech, Dierk Koenig
See Also:
Serialized Form

Nested Class Summary
static class MessageStream.RemoteMessageStream
           
private static class MessageStream.ResultWaiter<V>
          Represents a pending request for a reply from an actor.
static class MessageStream.SendTo
           
 
Field Summary
private static long serialVersionUID
           
 
Fields inherited from class groovyx.gpars.serial.WithSerialId
serialHandle
 
Constructor Summary
MessageStream()
           
 
Method Summary
<T> MessageStream
call(T message)
          Same as send
 java.lang.Class<MessageStream.RemoteMessageStream> getRemoteClass()
          Class of remote object to be created
<T> MessageStream
leftShift(T message)
          Same as send
(package private) static void reInterrupt()
           
 MessageStream send()
          Convenience method for send(new Object()).
abstract  MessageStream send(java.lang.Object message)
          Send message to stream and return immediately
<T> MessageStream
send(T message, MessageStream replyTo)
          Send message to stream and return immediately.
<T,V> V
sendAndWait(T message)
          Sends a message and waits for a reply.
<T> java.lang.Object
sendAndWait(T message, groovy.time.Duration duration)
          Sends a message and waits for a reply.
<T> java.lang.Object
sendAndWait(T message, long timeout, java.util.concurrent.TimeUnit units)
          Sends a message and waits for a reply.
 
Methods inherited from class groovyx.gpars.serial.WithSerialId
createRemoteHandle, getOrCreateSerialHandle, writeReplace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

MessageStream

public MessageStream()
Method Detail

send

public abstract MessageStream send(java.lang.Object message)
Send message to stream and return immediately

Parameters:
message - message to send
Returns:
always return message stream itself

send

public final MessageStream send()
Convenience method for send(new Object()).

Returns:
always return message stream itself

send

public final <T> MessageStream send(T message,
                                    MessageStream replyTo)
Send message to stream and return immediately. Allows to specify an arbitrary actor to send replies to. By default replies are sent to the originator (sender) of each message, however, when a different actor is specified as the optional second argument to the send() method, this supplied actor will receive the replies instead.

Type Parameters:
T - type of message accepted by the stream
Parameters:
message - message to send
replyTo - where to send reply
Returns:
always return message stream itself

leftShift

public final <T> MessageStream leftShift(T message)
Same as send

Parameters:
message - to send
Returns:
original stream

call

public final <T> MessageStream call(T message)
Same as send

Parameters:
message - to send
Returns:
original stream

sendAndWait

public final <T,V> V sendAndWait(T message)
                    throws java.lang.InterruptedException
Sends a message and waits for a reply. Returns the reply or throws an IllegalStateException, if the target actor cannot reply.

Parameters:
message - message to send
Returns:
The message that came in reply to the original send.
Throws:
java.lang.InterruptedException - if interrupted while waiting

sendAndWait

public final <T> java.lang.Object sendAndWait(T message,
                                              long timeout,
                                              java.util.concurrent.TimeUnit units)
                                   throws java.lang.InterruptedException
Sends a message and waits for a reply. Timeouts after the specified timeout. In case of timeout returns null. Returns the reply or throws an IllegalStateException, if the target actor cannot reply.

Parameters:
message - message to send
timeout - timeout
units - units
Returns:
The message that came in reply to the original send.
Throws:
java.lang.InterruptedException - if interrupted while waiting

sendAndWait

public final <T> java.lang.Object sendAndWait(T message,
                                              groovy.time.Duration duration)
                                   throws java.lang.InterruptedException
Sends a message and waits for a reply. Timeouts after the specified timeout. In case of timeout returns null. Returns the reply or throws an IllegalStateException, if the target actor cannot reply.

Parameters:
message - message to send
duration - timeout
Returns:
The message that came in reply to the original send.
Throws:
java.lang.InterruptedException - if interrupted while waiting

getRemoteClass

public java.lang.Class<MessageStream.RemoteMessageStream> getRemoteClass()
Description copied from class: WithSerialId
Class of remote object to be created

Overrides:
getRemoteClass in class WithSerialId
Returns:
Throws UnsupportedOperationException

reInterrupt

static void reInterrupt()
                 throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

Copyright © 2008–2012 Václav Pech. All Rights Reserved.