~ubuntu-branches/ubuntu/precise/jcsp/precise

« back to all changes in this revision

Viewing changes to src/jcsp-demos/commstime/SeqDelta2Int.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
 
 
30
import org.jcsp.lang.*;
 
31
 
 
32
/**
 
33
 * This process broadcasts integers arriving on its input channel <I>in sequence</I>
 
34
 * to its two output channels.
 
35
 *
 
36
 * <H2>Process Diagram</H2>
 
37
 * <!-- INCORRECT DIAGRAM: <p><IMG SRC="doc-files/Delta2Int1.gif"></p> -->
 
38
 * <PRE>
 
39
 *         ___________  out0 
 
40
 *    in  |           |--->---
 
41
 *   -->--| Delta2Int | out1
 
42
 *        |___________|--->---
 
43
 * </PRE>
 
44
 * <H2>Description</H2>
 
45
 * <TT>Delta2Int</TT> is a process that broadcasts (<I>in parallel</I>) on its two output channels
 
46
 * everything that arrives on its input channel.
 
47
 * <H2>Channel Protocols</H2>
 
48
 * <TABLE BORDER="2">
 
49
 *   <TR>
 
50
 *     <TH COLSPAN="3">Input Channels</TH>
 
51
 *   </TR>
 
52
 *   <TR>
 
53
 *     <TH>in</TH>
 
54
 *     <TD>int</TD>
 
55
 *     <TD>
 
56
 *       All channels in this package carry integers.
 
57
 *     </TD>
 
58
 *   </TR>
 
59
 *   <TR>
 
60
 *     <TH COLSPAN="3">Output Channels</TH>
 
61
 *   </TR>
 
62
 *   <TR>
 
63
 *     <TH>out0, out1</TH>
 
64
 *     <TD>int</TD>
 
65
 *     <TD>
 
66
 *       The output Channels will carry a broadcast of whatever
 
67
 *       integers are sent down the in Channel.
 
68
 *     </TD>
 
69
 *   </TR>
 
70
 * </TABLE>
 
71
 *
 
72
 * @author P.H. Welch and P.D. Austin
 
73
 */
 
74
 
 
75
public final class SeqDelta2Int implements CSProcess
 
76
{
 
77
   /** The input Channel */
 
78
   private final ChannelInputInt  in;
 
79
   
 
80
   /** The first output Channel */
 
81
   private final ChannelOutputInt out0;
 
82
   
 
83
   /** The second output Channel */
 
84
   private final ChannelOutputInt out1;
 
85
   
 
86
   /**
 
87
    * Construct a new Delta2Int process with the input Channel in and the output
 
88
    * Channels out0 and out1. The ordering of the Channels out0 and out1 make
 
89
    * no difference to the functionality of this process.
 
90
    *
 
91
    * @param in the input channel
 
92
    * @param out0 an output Channel
 
93
    * @param out1 an output Channel
 
94
    */
 
95
   public SeqDelta2Int(final ChannelInputInt in, final ChannelOutputInt out0, final ChannelOutputInt out1)
 
96
   {
 
97
      this.in   = in;
 
98
      this.out0 = out0;
 
99
      this.out1 = out1;
 
100
   }
 
101
   
 
102
   /**
 
103
    * The main body of this process.
 
104
    */
 
105
   public void run()
 
106
   {
 
107
      while (true)
 
108
      {
 
109
         int value = in.read();
 
110
         out0.write(value);
 
111
         out1.write(value);
 
112
      }
 
113
   }
 
114
}