KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DiningPhilosophers > monolithic > ForkManagerImpl


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): Philippe Merle, Sylvain Leblanc.
23 Contributor(s): Christophe Demarey.
24
25 ====================================================================*/

26
27 package DiningPhilosophers.monolithic;
28
29 import DiningPhilosophers.*;
30
31 /**
32  * This is the implementation of the OMG IDL3
33  * DiningPhilosophers::ForkManager component type.
34  *
35  * This class inherits from the local CCM_ForkManager interface
36  * generated by the OpenCCM's IDL3 to IDL2 mapping generator.
37  *
38  * The provided the_fork facet is directly implemented by the
39  * component class by implementing the DiningPhilosophers::Fork interface.
40  *
41  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
42  * @author <a HREF="mailto:Sylvain.Leblanc@lifl.fr">Sylvain Leblanc</a>
43  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
44  *
45  * @version 2.0
46  */

47
48 public class ForkManagerImpl
49      extends org.omg.CORBA.LocalObject JavaDoc
50   implements CCM_ForkManager,
51              CCM_Fork,
52              org.omg.Components.SessionComponent
53 {
54     // ==================================================================
55
//
56
// Internal state.
57
//
58
// ==================================================================
59

60     /** Tells if the fork is available. */
61     private boolean available_;
62
63     /** The fork manager CCM context. */
64     private CCM_ForkManager_Context the_context_;
65
66     // ==================================================================
67
//
68
// Constructor.
69
//
70
// ==================================================================
71

72     /** The default constructor. */
73     public
74     ForkManagerImpl()
75     {
76         available_ = true;
77     }
78
79     // ==================================================================
80
//
81
// Internal methods.
82
//
83
// ==================================================================
84

85     // ==================================================================
86
//
87
// Public methods.
88
//
89
// ==================================================================
90

91     // ==================================================================
92
//
93
// Methods for OMG IDL Components::EnterpriseComponent
94
//
95
// ==================================================================
96

97     /**
98      * Complete the component configuration.
99      *
100      * @exception org.omg.Components.InvalidConfiguration
101      * Thrown if the configuration is invalid.
102      */

103     public void
104     configuration_complete()
105     throws org.omg.Components.InvalidConfiguration
106     {
107         // Nothing to do.
108
}
109
110     // ==================================================================
111
//
112
// Methods for the OMG IDL org.omg.Components.SessionComponent
113
//
114
// ==================================================================
115

116     /**
117      * Setting the session component context.
118      *
119      * @param context The session component context.
120      */

121     public void
122     set_session_context(org.omg.Components.SessionContext context)
123     throws org.omg.Components.CCMException
124     {
125         the_context_ = (CCM_ForkManager_Context)context;
126     }
127
128     /**
129      * Container callback to signal that the component is activated.
130      *
131      * @throw org.omg.Components.CCMException For any problems.
132      */

133     public void
134     ccm_activate()
135     throws org.omg.Components.CCMException
136     {
137         // Nothing to do currently.
138
}
139
140     /**
141      * Container callback to signal that the component is activated.
142      *
143      * @throw org.omg.Components.CCMException For any problems.
144      */

145     public void
146     ccm_passivate()
147     throws org.omg.Components.CCMException
148     {
149         // Nothing to do currently.
150
}
151
152     /**
153      * Container callback to signal that the component is removed.
154      *
155      * @throw org.omg.Components.CCMException For any problems.
156      */

157     public void
158     ccm_remove()
159     throws org.omg.Components.CCMException
160     {
161         // Nothing to do currently.
162
}
163
164     // ==================================================================
165
//
166
// Methods for OMG IDL DiningPhilosophers::CCM_ForkManager
167
//
168
// ==================================================================
169

170     /**
171      * The component must provide the executor object implementing
172      * the the_fork Facet.
173      */

174     public CCM_Fork
175     get_the_fork()
176     {
177         // Returns the component because it implements the Fork facet.
178
return this;
179     }
180
181     // ==================================================================
182
//
183
// Methods for OMG IDL DiningPhilosophers::Fork
184
//
185
// ==================================================================
186

187     /**
188      * Obtain the fork.
189      *
190      * @exception InUse
191      * Thrown if the fork has already used by another philosopher.
192      */

193     public void
194     get()
195     throws InUse
196     {
197         // Check if there is no current philosopher.
198
if (! available_)
199         {
200             throw new InUse();
201         }
202
203         // The philosopher is now the current fork user.
204
available_ = false;
205     }
206
207     /**
208      * Release the fork.
209      */

210     public void
211     release()
212     {
213         // Check if the philosopher is the current one.
214
if (available_)
215         {
216             return;
217         }
218
219         // There is no current fork user.
220
available_ = true;
221     }
222 }
223
Popular Tags