org.codehaus.gpars

groovyx.gpars.dataflow
[Java] Class SyncDataflowVariable

java.lang.Object
  groovyx.gpars.serial.WithSerialId
      groovyx.gpars.dataflow.expression.DataflowExpression
          groovyx.gpars.dataflow.DataflowVariable
              groovyx.gpars.dataflow.SyncDataflowVariable

public final class SyncDataflowVariable
extends DataflowVariable

A synchronous variant of DataflowVariable, which blocks the writer as well as the readers. The synchronous variable ensures a specified number of readers must ask for a value before the writer as well as the readers can continue.

Authors:
Vaclav Pech


Field Summary
private static java.lang.String ERROR_READING_A_SYNCHRONOUS_CHANNEL

private ResizeableCountDownLatch parties

 
Fields inherited from class DataflowVariable
serialVersionUID
 
Fields inherited from class DataflowExpression
ATTACHMENT, RESULT, S_INITIALIZED, S_INITIALIZING, S_NOT_INITIALIZED, dummyWaitingThread, error, eventManager, metaClass, serialVersionUID, state, value, waiting
 
Fields inherited from class WithSerialId
serialHandle, serialVersionUID
 
Constructor Summary
SyncDataflowVariable()

Creates a new variable, which will never block writers.

SyncDataflowVariable(int parties)

Creates a new variable blocking the specified number of readers.

 
Method Summary
private void awaitParties()

boolean awaitingParties()

Reports whether the variable is still waiting for parties to arrive for the rendezvous.

DataflowReadChannel chainWith(PGroup group, groovy.lang.Closure closure)

void decrementParties()

Decreases the number of parties required to perform data exchange by one

protected void doBindImpl(java.lang.Object value)

java.lang.Object getVal()

Reads the value of the variable.

java.lang.Object getVal(long timeout, java.util.concurrent.TimeUnit units)

Reads the value of the variable.

void incrementParties()

Increases the number of parties required to perform data exchange by one.

DataflowReadChannel merge(PGroup group, java.util.List others, groovy.lang.Closure closure)

private void readerIsReady()

private boolean readerIsReady(long timeout)

protected void scheduleCallback(java.lang.Object attachment, MessageStream callback)

boolean shouldThrowTimeout()

DataflowReadChannel tap(PGroup group, DataflowWriteChannel target)

 
Methods inherited from class DataflowVariable
bindDFV, get, get, getError, getRemoteClass, isError, leftShift, leftShift, shouldThrowTimeout, then, then, then
 
Methods inherited from class DataflowExpression
DataflowExpression, binaryChoice, binaryChoice, binaryChoice, binaryChoice, binaryChoice, binaryChoice, bind, bindError, bindSafely, bindUnique, chainWith, chainWith, chainWith, chainWith, chainWith, chainWith, choice, choice, choice, choice, choice, choice, doBind, doBindImpl, doBindRemote, evaluate, filter, filter, filter, filter, filter, filter, fireOnMessage, getEventManager, getMetaClass, getProperty, getVal, getVal, getValAsync, getValAsync, handleInterruption, into, into, into, into, into, into, invokeMethod, isBound, join, join, length, merge, merge, merge, merge, merge, merge, merge, merge, merge, merge, merge, merge, notifyRemote, or, or, poll, rightShift, scheduleCallback, separate, separate, separate, separate, separate, separate, setMetaClass, setProperty, split, split, split, split, split, split, split, split, split, split, split, split, subscribe, subscribe, tap, tap, tap, tap, tap, tap, then, then, then, toString, transform, whenBound, whenBound, whenBound, whenBound, wheneverBound, wheneverBound
 
Methods inherited from class WithSerialId
createRemoteHandle, getOrCreateSerialHandle, getRemoteClass, writeReplace
 

Field Detail

ERROR_READING_A_SYNCHRONOUS_CHANNEL

private static final java.lang.String ERROR_READING_A_SYNCHRONOUS_CHANNEL


parties

private final ResizeableCountDownLatch parties


 
Constructor Detail

SyncDataflowVariable

public SyncDataflowVariable()
Creates a new variable, which will never block writers.


SyncDataflowVariable

public SyncDataflowVariable(int parties)
Creates a new variable blocking the specified number of readers.
Parameters:
parties - Number of readers that have to match a writer before the message gets transferred


 
Method Detail

awaitParties

private void awaitParties()


awaitingParties

public boolean awaitingParties()
Reports whether the variable is still waiting for parties to arrive for the rendezvous.
Returns:
True if not all parties have shown yet


chainWith

@Override
public DataflowReadChannel chainWith(PGroup group, groovy.lang.Closure closure)


decrementParties

public void decrementParties()
Decreases the number of parties required to perform data exchange by one


doBindImpl

@Override
protected void doBindImpl(java.lang.Object value)


getVal

@Override
public java.lang.Object getVal()
Reads the value of the variable. Blocks, if the value has not been assigned yet.
throws:
InterruptedException If the current thread gets interrupted while waiting for the variable to be bound
Returns:
The actual value


getVal

@Override
public java.lang.Object getVal(long timeout, java.util.concurrent.TimeUnit units)
Reads the value of the variable. Blocks up to given timeout, if the value has not been assigned yet.
throws:
InterruptedException If the current thread gets interrupted while waiting for the variable to be bound
Parameters:
timeout - The timeout value
units - Units for the timeout
Returns:
The actual value


incrementParties

public void incrementParties()
Increases the number of parties required to perform data exchange by one.


merge

@Override
public DataflowReadChannel merge(PGroup group, java.util.List others, groovy.lang.Closure closure)


readerIsReady

private void readerIsReady()


readerIsReady

private boolean readerIsReady(long timeout)


scheduleCallback

@Override
protected void scheduleCallback(java.lang.Object attachment, MessageStream callback)


shouldThrowTimeout

@Override
boolean shouldThrowTimeout()


tap

@Override
public DataflowReadChannel tap(PGroup group, DataflowWriteChannel target)


 

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