1
//////////////////////////////////////////////////////////////////////
3
// JCSP ("CSP for Java") Libraries //
4
// Copyright (C) 1996-2008 Peter Welch and Paul Austin. //
5
// 2001-2004 Quickstone Technologies Limited. //
7
// This library is free software; you can redistribute it and/or //
8
// modify it under the terms of the GNU Lesser General Public //
9
// License as published by the Free Software Foundation; either //
10
// version 2.1 of the License, or (at your option) any later //
13
// This library is distributed in the hope that it will be //
14
// useful, but WITHOUT ANY WARRANTY; without even the implied //
15
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
16
// PURPOSE. See the GNU Lesser General Public License for more //
19
// You should have received a copy of the GNU Lesser General //
20
// Public License along with this library; if not, write to the //
21
// Free Software Foundation, Inc., 59 Temple Place, Suite 330, //
22
// Boston, MA 02111-1307, USA. //
24
// Author contact: P.H.Welch@kent.ac.uk //
27
//////////////////////////////////////////////////////////////////////
29
package org.jcsp.lang;
31
import org.jcsp.util.*;
34
* This implements an any-to-any object channel with user-definable buffering,
35
* safe for use by many writers and many readers.
36
* <H2>Description</H2>
37
* <TT>BufferedOne2AnyChannel</TT> implements a one-to-any object channel with
38
* user-definable buffering. It is safe for use by any number of reading
39
* processes but ony one writer. Reading processes compete with each other
40
* to use the channel. Only one reader and the writer will actually be using
41
* the channel at any one time. This is taken care of by
42
* <TT>BufferedOne2AnyChannel</TT> -- user processes just read from or write to it.
44
* <I>Please note that this is a safely shared channel and not
45
* a multicaster. Currently, multicasting has to be managed by
46
* writing active processes (see {@link org.jcsp.plugNplay.DynamicDelta}
47
* for an example of broadcasting).</I>
49
* All reading processes and writing processes commit to the channel
50
* (i.e. may not back off). This means that the reading processes
51
* <I>may not</I> {@link Alternative <TT>ALT</TT>} on this channel.
53
* The constructor requires the user to provide
54
* the channel with a <I>plug-in</I> driver conforming to the
55
* {@link org.jcsp.util.ChannelDataStore <TT>ChannelDataStore</TT>}
56
* interface. This allows a variety of different channel semantics to be
57
* introduced -- including buffered channels of user-defined capacity
58
* (including infinite), overwriting channels (with various overwriting
60
* Standard examples are given in the <TT>org.jcsp.util</TT> package, but
61
* <I>careful users</I> may write their own.
63
* <H3><A NAME="Caution">Implementation Note and Caution</H3>
64
* <I>Fair</I> servicing of readers to this channel depends on the <I>fair</I>
65
* servicing of requests to enter a <TT>synchronized</TT> block (or method) by
66
* the underlying Java Virtual Machine (JVM). Java does not specify how threads
67
* waiting to synchronize should be handled. Currently, Sun's standard JDKs queue
68
* these requests - which is <I>fair</I>. However, there is at least one JVM
69
* that puts such competing requests on a stack - which is legal but <I>unfair</I>
70
* and can lead to infinite starvation. This is a problem for <I>any</I> Java system
71
* relying on good behaviour from <TT>synchronized</TT>, not just for these
72
* <I>1-any</I> channels.
74
* @see org.jcsp.lang.BufferedOne2OneChannel
75
* @see org.jcsp.lang.BufferedOne2AnyChannel
76
* @see org.jcsp.lang.BufferedAny2AnyChannel
77
* @see org.jcsp.util.ChannelDataStore
83
class BufferedOne2AnyChannel extends One2AnyImpl
86
* Constructs a new BufferedOne2AnyChannel with the specified ChannelDataStore.
88
* @param data The ChannelDataStore used to store the data for the channel
90
public BufferedOne2AnyChannel(ChannelDataStore data)
92
super(new BufferedOne2OneChannel(data));