KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DiningPhilosophers > cif > ForkSegImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@objectweb.org
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 any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Christophe Demarey.
23 Contributor(s): ______________________________.
24
25 ====================================================================*/

26
27 package DiningPhilosophers.cif;
28
29 import DiningPhilosophers.*;
30
31 /**
32  * This is the implementation of the fatet 'the_fork'.
33  *
34  * This class inherits from the skeleton
35  * generated by the OpenCCM's CIF to Java mapping generator.
36  *
37  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</A>
38  */

39
40 public class ForkSegImpl
41      extends DiningPhilosophers.ForkManagerSessionComposition.ForkSeg
42 {
43     // ==================================================================
44
//
45
// Internal state.
46
//
47
// ==================================================================
48

49     /** Tells if the fork is available. */
50     private boolean available_;
51
52     // ==================================================================
53
//
54
// Constructor.
55
//
56
// ==================================================================
57

58     /** The default constructor. */
59     public
60     ForkSegImpl()
61     {
62         available_ = true;
63     }
64
65     // ==================================================================
66
//
67
// Internal methods.
68
//
69
// ==================================================================
70

71     // ==================================================================
72
//
73
// Public methods.
74
//
75
// ==================================================================
76

77     // ==================================================================
78
//
79
// Methods for OMG IDL DiningPhilosophers::Fork
80
//
81
// ==================================================================
82

83     /**
84      * Obtain the fork.
85      *
86      * @exception InUse
87      * Thrown if the fork has already used by another philosopher.
88      */

89     public void
90     get()
91     throws InUse
92     {
93         // Check if there is no current philosopher.
94
if (! available_)
95         {
96             throw new InUse();
97         }
98
99         // The philosopher is now the current fork user.
100
available_ = false;
101     }
102
103     /**
104      * Release the fork.
105      */

106     public void
107     release()
108     {
109         // Check if the philosopher is the current one.
110
if (available_)
111         {
112             return;
113         }
114
115         // There is no current fork user.
116
available_ = true;
117     }
118 }
119
Popular Tags