groovyx.gpars.dataflow
Class SyncDataflowBroadcast<T>

java.lang.Object
  extended by groovyx.gpars.dataflow.stream.DataflowStreamWriteAdapter<T>
      extended by groovyx.gpars.dataflow.SyncDataflowBroadcast<T>
Type Parameters:
T - The type of messages to pass through the stream
All Implemented Interfaces:
DataflowWriteChannel<T>

public final class SyncDataflowBroadcast<T>
extends DataflowStreamWriteAdapter<T>

Offers a synchronous deterministic one-to-many and many-to-many messaging alternative to SyncDataflowQueue. Internally it wraps a SyncDataflowStream class with a DataflowStreamWriteAdapter and so synchronizes all writes to the underlying stream allowing multiple threads accessing the stream concurrently. On demand through the createReadChannel() method it will return an DataflowReadChannel through which the reader will receive all messages written to the channel since then.

Typical use:

DataflowWriteChannel broadcastStream = new DataflowBroadcast() DataflowReadChannel stream1 = broadcastStream.createReadChannel() DataflowReadChannel stream2 = broadcastStream.createReadChannel() broadcastStream << 'Message' assert stream1.val == stream2.val

Author:
Vaclav Pech

Constructor Summary
SyncDataflowBroadcast()
          Creates a new instance
 
Method Summary
 DataflowReadChannel<T> createReadChannel()
          Retrieves an implementation of DataflowReadChannel to read all messages submitted to the broadcast chanel.
 java.lang.String toString()
           
 void unsubscribeReadChannel(DataflowReadChannel<T> channel)
          Un-registers the supplied read channel from the broadcast.
 
Methods inherited from class groovyx.gpars.dataflow.stream.DataflowStreamWriteAdapter
bind, getHead, leftShift, leftShift
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SyncDataflowBroadcast

public SyncDataflowBroadcast()
Creates a new instance

Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class DataflowStreamWriteAdapter<T>

createReadChannel

public DataflowReadChannel<T> createReadChannel()
Retrieves an implementation of DataflowReadChannel to read all messages submitted to the broadcast chanel. Since multiple parties (threads/tasks/actors/...) may ask for read channels independently, the submitted messages are effectively broadcast to all the subscribers.

Returns:
A read channel to receive messages submitted to the broadcast channel from now on.

unsubscribeReadChannel

public void unsubscribeReadChannel(DataflowReadChannel<T> channel)
                            throws java.lang.InterruptedException
Un-registers the supplied read channel from the broadcast. The number of parties that have to meet at data exchange is reduced by one.

Parameters:
channel - The channel to unsubscribe. The channel won't be able to read further messages.
Throws:
java.lang.InterruptedException - If the thread got interrupted

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