~ubuntu-branches/ubuntu/trusty/jcsp/trusty

« back to all changes in this revision

Viewing changes to src/org/jcsp/lang/BufferedAny2OneChannel.java

  • Committer: Bazaar Package Importer
  • Author(s): Miguel Landaeta
  • Date: 2010-06-20 18:12:26 UTC
  • Revision ID: james.westby@ubuntu.com-20100620181226-8yg8d9rjjjiuy7oz
Tags: upstream-1.1-rc4
ImportĀ upstreamĀ versionĀ 1.1-rc4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
    //////////////////////////////////////////////////////////////////////
 
2
    //                                                                  //
 
3
    //  JCSP ("CSP for Java") Libraries                                 //
 
4
    //  Copyright (C) 1996-2008 Peter Welch and Paul Austin.            //
 
5
    //                2001-2004 Quickstone Technologies Limited.        //
 
6
    //                                                                  //
 
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       //
 
11
    //  version.                                                        //
 
12
    //                                                                  //
 
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     //
 
17
    //  details.                                                        //
 
18
    //                                                                  //
 
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.                                     //
 
23
    //                                                                  //
 
24
    //  Author contact: P.H.Welch@kent.ac.uk                             //
 
25
    //                                                                  //
 
26
    //                                                                  //
 
27
    //////////////////////////////////////////////////////////////////////
 
28
 
 
29
package org.jcsp.lang;
 
30
 
 
31
import org.jcsp.util.*;
 
32
 
 
33
/**
 
34
 * This implements an any-to-one object channel with user-definable buffering,
 
35
 * safe for use by many writers and one reader.
 
36
 * <H2>Description</H2>
 
37
 * <TT>BufferedAny2OneChannel</TT> implements an any-to-one object channel with
 
38
 * user-definable buffering.  It is safe for use by many writing processes
 
39
 * but only one reader.  Writing processes compete with each other to use
 
40
 * the channel.  Only the reader and one writer will
 
41
 * actually be using the channel at any one time.  This is taken care of by
 
42
 * <TT>BufferedAny2OneChannel</TT> -- user processes just read from or write to it.
 
43
 * <P>
 
44
 * The reading process may {@link Alternative <TT>ALT</TT>} on this channel.
 
45
 * The writing process is committed (i.e. it may not back off).
 
46
 * <P>
 
47
 * The constructor requires the user to provide
 
48
 * the channel with a <I>plug-in</I> driver conforming to the
 
49
 * {@link org.jcsp.util.ChannelDataStore <TT>ChannelDataStore</TT>}
 
50
 * interface.  This allows a variety of different channel semantics to be
 
51
 * introduced -- including buffered channels of user-defined capacity
 
52
 * (including infinite), overwriting channels (with various overwriting
 
53
 * policies) etc..
 
54
 * Standard examples are given in the <TT>org.jcsp.util</TT> package, but
 
55
 * <I>careful users</I> may write their own.
 
56
 *
 
57
 * <H3><A NAME="Caution">Implementation Note and Caution</H3>
 
58
 * <I>Fair</I> servicing of writers to this channel depends on the <I>fair</I>
 
59
 * servicing of requests to enter a <TT>synchronized</TT> block (or method) by
 
60
 * the underlying Java Virtual Machine (JVM).  Java does not specify how threads
 
61
 * waiting to synchronize should be handled.  Currently, Sun's standard JDKs queue
 
62
 * these requests - which is <I>fair</I>.  However, there is at least one JVM
 
63
 * that puts such competing requests on a stack - which is legal but <I>unfair</I>
 
64
 * and can lead to infinite starvation.  This is a problem for <I>any</I> Java system
 
65
 * relying on good behaviour from <TT>synchronized</TT>, not just for these
 
66
 * <I>any-1</I> channels.
 
67
 *
 
68
 * @see org.jcsp.lang.Alternative
 
69
 * @see org.jcsp.lang.BufferedOne2OneChannel
 
70
 * @see org.jcsp.lang.BufferedOne2AnyChannel
 
71
 * @see org.jcsp.lang.BufferedAny2AnyChannel
 
72
 * @see org.jcsp.util.ChannelDataStore
 
73
 *
 
74
 * @author P.D. Austin
 
75
 * @author P.H. Welch
 
76
 */
 
77
 
 
78
class BufferedAny2OneChannel extends Any2OneImpl
 
79
{
 
80
        /**
 
81
     * Constructs a new BufferedAny2OneChannel with the specified ChannelDataStore.
 
82
     *
 
83
     * @param data The ChannelDataStore used to store the data for the channel
 
84
     */
 
85
    public BufferedAny2OneChannel(ChannelDataStore data)
 
86
    {
 
87
        super(new BufferedOne2OneChannel(data));
 
88
    }
 
89
}