org.codehaus.gpars

groovyx.gpars.dataflow
[Java] Class Select

java.lang.Object
  groovyx.gpars.dataflow.Select

@java.lang.SuppressWarnings({"OverloadedVarargsMethod"})
public class Select

A Select allows the user to select a value from multiple channels, which have a value available for read at the moment. It can either pick a channel randomly, when using the plain select method, or with precedence towards channels with lower position indexes, when the prioritySelect method is used. If a value is not available immediately in any of the channels, Select will wait for the first value to arrive in any of the channels.

Both 'select' and 'prioritySelect' methods come in two flavours - blocking, which wait till a value is available in a channel, and messaging, which send out a message to the specified message handler, as soon as a message is available. Optionally, all methods allow the user to specify a boolean mask, assigning each select 's input channel a flag indicating, whether it should be included in the select operation. This is useful when handling state to selectively block some inputs in some states.

Authors:
Vaclav Pech Date: 30th Sep 2010


Field Summary
static java.lang.String TIMEOUT

@param pGroup The group, the thread pool of which should be used for notification message handlers

private SelectBase selectBase

 
Constructor Summary
Select(PGroup pGroup, SelectableChannel... channels)

Select(PGroup pGroup, java.util.List channels)

 
Method Summary
SelectResult call()

SelectResult call(java.util.List mask)

Selects a value from a single randomly chosen input channel, which has a value available for read.

void call(MessageStream messageStream)

void call(MessageStream messageStream, java.util.List mask)

Invokes the internal select base with a SelectRequest instance ensuring a message is sent, once a value has been selected

static DataflowReadChannel createTimeout(long timeout)

SelectResult prioritySelect()

SelectResult prioritySelect(java.util.List mask)

Selects a value from a single input channel, which has a value available for read.

void prioritySelect(MessageStream messageStream)

void prioritySelect(MessageStream messageStream, java.util.List mask)

Selects asynchronously a value from a single input channel, which has a value available for read.

Promise prioritySelectToPromise()

Promise prioritySelectToPromise(java.util.List mask)

SelectResult select()

Selects a value from a single randomly chosen input channel, which has a value available for read.

SelectResult select(java.util.List mask)

Creates a timeout channel (DataflowVariable) that will bind a Select.TIMEOUT value after the specified timeout.

void select(MessageStream messageStream)

Selects a value from a single randomly chosen input channel, which has a value available for read.

void select(MessageStream messageStream, java.util.List mask)

Selects asynchronously a value from a single randomly chosen input channel, which has a value available for read.

private void select(MessageStream messageStream, int startIndex, java.util.List mask)

Invokes the internal select base with a SelectRequest instance ensuring the current thread can continue returning the correct value, once a value has been selected

private SelectResult select(int startIndex, java.util.List mask)

Promise selectToPromise()

Promise selectToPromise(java.util.List mask)

Selects a value from a single input channel, which has a value available for read.

private Promise selectToPromise(int startIndex, java.util.List mask)

Invokes the internal select base with a SelectRequest instance ensuring a message is sent, once a value has been selected

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

TIMEOUT

public static final java.lang.String TIMEOUT
Parameters:
pGroup - The group, the thread pool of which should be used for notification message handlers
channels - The list of input channels to select from


selectBase

private final SelectBase selectBase


 
Constructor Detail

Select

@java.lang.SuppressWarnings* Selects a value from a single randomly chosen input channel, which has a value available for read.
public Select(PGroup pGroup, SelectableChannel... channels)


Select

public Select(PGroup pGroup, java.util.List channels)


 
Method Detail

call

public final SelectResult call()


call

public final SelectResult call(java.util.List mask)
Selects a value from a single randomly chosen input channel, which has a value available for read. The read value is send to the supplied messageStream
throws:
InterruptedException If the current thread gets interrupted
Parameters:
messageStream - A message stream accepting the selected value. The message will be of SelectResult type, holding the actual value as well as the channel index.


call

public final void call(MessageStream messageStream)


call

public final void call(MessageStream messageStream, java.util.List mask)
Invokes the internal select base with a SelectRequest instance ensuring a message is sent, once a value has been selected


createTimeout

public static DataflowReadChannel createTimeout(long timeout)


prioritySelect

public SelectResult prioritySelect()


prioritySelect

public SelectResult prioritySelect(java.util.List mask)
Selects a value from a single input channel, which has a value available for read. Channels with lower position index are preferred. The read value is send to the supplied messageStream
throws:
InterruptedException If the current thread gets interrupted
Parameters:
messageStream - A message stream accepting the selected value. The message will be of SelectResult type, holding the actual value as well as the channel index.


prioritySelect

public void prioritySelect(MessageStream messageStream)


prioritySelect

public void prioritySelect(MessageStream messageStream, java.util.List mask)
Selects asynchronously a value from a single input channel, which has a value available for read. Channels with lower position index are preferred. The returned Promise will eventually get bound to the selected value (wrapped inside s SelectResult instance)
throws:
InterruptedException If the current thread gets interrupted


prioritySelectToPromise

public Promise prioritySelectToPromise()


prioritySelectToPromise

public Promise prioritySelectToPromise(java.util.List mask)


select

public SelectResult select()
Selects a value from a single randomly chosen input channel, which has a value available for read. Only the channels marked with 'true' in the supplied mask will be considered.
throws:
InterruptedException If the current thread gets interrupted
Parameters:
mask - A list of boolean values indicating, whether the input channel with the same position index should be included in the selection or not
Returns:
The read value. It will be of SelectResult type, holding the actual value as well as the channel index.


select

public SelectResult select(java.util.List mask)
Creates a timeout channel (DataflowVariable) that will bind a Select.TIMEOUT value after the specified timeout.
Parameters:
timeout - The delay in milliseconds to wait before the value gets bound
Returns:
A DataflowVariable instance that will have the Select.TIMEOUT value bound after the specified number of milliseconds elapse


select

public void select(MessageStream messageStream)
Selects a value from a single randomly chosen input channel, which has a value available for read. The read value is send to the supplied messageStream
throws:
InterruptedException If the current thread gets interrupted
Parameters:
messageStream - A message stream accepting the selected value. The message will be of SelectResult type, holding the actual value as well as the channel index.
mask - A list of boolean values indicating, whether the input channel with the same position index should be included in the selection or not


select

public void select(MessageStream messageStream, java.util.List mask)
Selects asynchronously a value from a single randomly chosen input channel, which has a value available for read. The returned Promise will eventually get bound to the selected value (wrapped inside s SelectResult instance)
throws:
InterruptedException If the current thread gets interrupted


select

private void select(MessageStream messageStream, int startIndex, java.util.List mask)
Invokes the internal select base with a SelectRequest instance ensuring the current thread can continue returning the correct value, once a value has been selected


select

private SelectResult select(int startIndex, java.util.List mask)


selectToPromise

public Promise selectToPromise()


selectToPromise

public Promise selectToPromise(java.util.List mask)
Selects a value from a single input channel, which has a value available for read. Channels with lower position index are preferred.
throws:
InterruptedException If the current thread gets interrupted
Returns:
The read value. It will be of SelectResult type, holding the actual value as well as the channel index.


selectToPromise

private Promise selectToPromise(int startIndex, java.util.List mask)
Invokes the internal select base with a SelectRequest instance ensuring a message is sent, once a value has been selected


 

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