groovyx.gpars.dataflow.impl
Class SelectBase<T>

java.lang.Object
  extended by groovyx.gpars.dataflow.impl.SelectBase<T>

public final class SelectBase<T>
extends java.lang.Object

The implementation of the core for all selects.

Author:
Vaclav Pech Date: 29th Sep 2010

Field Summary
private  boolean[] disabledDFVs
          Since DataflowVariables should be only read once, they need to be disabled after selecting their value The array stores a boolean flag for each index, indicating, whether the channel/variable has been disabled
private  java.util.List<DataflowReadChannel<? extends T>> channels
           
private  int numberOfChannels
           
private  java.util.Collection<SelectRequest<T>> pendingRequests
          Unsatisfied requests for value, each holding a list of guards and a routine to invoke once a value is available
private  java.util.Random position
           
 
Constructor Summary
SelectBase(PGroup pGroup, java.util.List<DataflowReadChannel<? extends T>> channels)
          Stores the input channel and registers for the wheneverBound() event on each
 
Method Summary
(package private)  void boundNotification(int index, DataflowReadChannel<? extends T> channel)
          Invoked by the SelectCallback instances, potentially concurrently to inform about new values being available for read from channels.
private  void disableDFV(int currentPosition, DataflowReadChannel<? extends T> channel)
          Sets the flag in the disabledDFVs array, if the channel is a DFV
 void doSelect(int startIndex, SelectRequest<T> selectRequest)
          Invoked whenever the Select is asked for the next value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

channels

private final java.util.List<DataflowReadChannel<? extends T>> channels

numberOfChannels

private final int numberOfChannels

disabledDFVs

private final boolean[] disabledDFVs
Since DataflowVariables should be only read once, they need to be disabled after selecting their value The array stores a boolean flag for each index, indicating, whether the channel/variable has been disabled


pendingRequests

private final java.util.Collection<SelectRequest<T>> pendingRequests
Unsatisfied requests for value, each holding a list of guards and a routine to invoke once a value is available


position

private final java.util.Random position
Constructor Detail

SelectBase

public SelectBase(PGroup pGroup,
                  java.util.List<DataflowReadChannel<? extends T>> channels)
Stores the input channel and registers for the wheneverBound() event on each

Parameters:
pGroup - The group, the thread pool of which should be used for notification message handlers
channels - All the input channels to select on
Method Detail

boundNotification

void boundNotification(int index,
                       DataflowReadChannel<? extends T> channel)
                 throws java.lang.InterruptedException
Invoked by the SelectCallback instances, potentially concurrently to inform about new values being available for read from channels.

Parameters:
index - The index of the ready channel
channel - The channel itself
Throws:
java.lang.InterruptedException - If the thread is interrupted during value retrieval from the channel

doSelect

public void doSelect(int startIndex,
                     SelectRequest<T> selectRequest)
              throws java.lang.InterruptedException
Invoked whenever the Select is asked for the next value. Depending on the supplied startIndex value it scans all input channels and reads the first one found, which currently has a value available for read. If no input channel is ready, the supplied SelectRequest instance is registered to be notified by the wheneverBound() channel listeners.

Parameters:
startIndex - The index of the channel to check first for available messages, -1 if start at a random position. Continue scanning by increasing the index, once the size is reached start from 0.
selectRequest - The request that holds the guards and expects a notification once a value is selected
Throws:
java.lang.InterruptedException - If the thread gets interrupted while reading messages from the channels

disableDFV

private void disableDFV(int currentPosition,
                        DataflowReadChannel<? extends T> channel)
Sets the flag in the disabledDFVs array, if the channel is a DFV

Parameters:
currentPosition - The position to mark
channel - The channel being considered

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