KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > runtime > ClientCallContextImpl


1 // ====================================================================
2
//
3
// ECM: The Extensible Container Model
4
// Copyright (C) 2004 THALES
5
// Contact: openccm-ecm@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): Mathieu Vadet.
23
// Initial Funding: IST COACH European project (IST-2001-34445)
24
// http://www.ist-coach.org
25
//
26
// ====================================================================
27

28
29
30 package org.objectweb.ccm.runtime;
31
32 import org.objectweb.corba.runtime.*;
33
34 /**
35  ** <p>Default implementation of the <tt>ECA::ClientCallContext</tt> OMG IDL interface.</p>
36  **/

37 public class ClientCallContextImpl
38 extends org.omg.CORBA.LocalObject JavaDoc
39 implements org.coach.ECA.ClientCallContext
40 {
41     //
42
static private String JavaDoc _class_name = "ClientCallContextImpl";
43     private java.util.Hashtable JavaDoc _call_infos; // (thread id, ClientCallInformation)
44
private ORBService _orb_service;
45     private ServicesSet _services_set;
46     private org.omg.CORBA.Object JavaDoc _real_stub;
47
48     // default constructor
49
public
50     ClientCallContextImpl(ORBService orbs,
51                           ServicesSet services,
52                           org.omg.CORBA.Object JavaDoc rstub)
53     {
54         _orb_service = orbs;
55         _services_set = services;
56         _real_stub = rstub;
57         _call_infos = new java.util.Hashtable JavaDoc();
58     }
59
60     //
61
// friend operations (for generated interceptor), keep public as in different packages
62
//
63

64     final public org.coach.ECA.ClientCallController
65     popController()
66     {
67         ClientCallInformation callinfo = (ClientCallInformation)_call_infos.get(Thread.currentThread().getName());
68         return (org.coach.ECA.ClientCallController)callinfo.controller_stack.pop();
69     }
70
71     final public void
72     pushController(org.coach.ECA.ClientCallController ctrl)
73     {
74         ClientCallInformation callinfo = (ClientCallInformation)_call_infos.get(Thread.currentThread().getName());
75         callinfo.controller_stack.push(ctrl);
76     }
77
78     final public boolean
79     isEmpty()
80     {
81         ClientCallInformation callinfo = (ClientCallInformation)_call_infos.get(Thread.currentThread().getName());
82         return callinfo.controller_stack.isEmpty();
83     }
84
85     final public void
86     addEntry(CallInformation cinfo, String JavaDoc opname)
87     {
88         // create storage
89
ClientCallInformation callinfo = new ClientCallInformation();
90
91         // fill
92
callinfo.call_information = cinfo;
93         callinfo.result = null;
94         callinfo.system_exception = null;
95         callinfo.user_exception = null;
96         callinfo.eca_call_information.operation_name = opname;
97
98         // store
99
_call_infos.put(Thread.currentThread().getName(), callinfo);
100     }
101
102     final public void
103     removeEntry()
104     {
105         // remove from storage
106
_call_infos.remove(Thread.currentThread().getName());
107     }
108
109     final public void
110     setResult(org.omg.CORBA.Any JavaDoc res)
111     {
112         ClientCallInformation callinfo = (ClientCallInformation)_call_infos.get(Thread.currentThread().getName());
113         callinfo.result = res;
114     }
115
116     //
117
// IDL:coach.org/ECA/CallContext:1.0
118
//
119

120     final public org.coach.ECA.CallInformation
121     call_information()
122     {
123         ClientCallInformation callinfo = (ClientCallInformation)_call_infos.get(Thread.currentThread().getName());
124         return callinfo.eca_call_information;
125     }
126
127     final public org.omg.CORBA.Any JavaDoc
128     result()
129     {
130         ClientCallInformation callinfo = (ClientCallInformation)_call_infos.get(Thread.currentThread().getName());
131         return callinfo.result;
132     }
133
134     final public org.omg.CORBA.Any JavaDoc
135     system_exception()
136     {
137         ClientCallInformation callinfo = (ClientCallInformation)_call_infos.get(Thread.currentThread().getName());
138         return callinfo.system_exception;
139     }
140
141     final public org.omg.CORBA.Any JavaDoc
142     user_exception()
143     {
144         ClientCallInformation callinfo = (ClientCallInformation)_call_infos.get(Thread.currentThread().getName());
145         return callinfo.user_exception;
146     }
147
148     final public void
149     send_system_exception(org.omg.CORBA.Any JavaDoc exc)
150     {
151         ClientCallInformation callinfo = (ClientCallInformation)_call_infos.get(Thread.currentThread().getName());
152         callinfo.system_exception = exc;
153     }
154
155     final public void
156     send_user_exception(org.omg.CORBA.Any JavaDoc exc)
157     {
158         ClientCallInformation callinfo = (ClientCallInformation)_call_infos.get(Thread.currentThread().getName());
159         callinfo.user_exception = exc;
160     }
161
162     final public org.omg.CORBA.Object JavaDoc
163     get_service_internal(String JavaDoc sid, String JavaDoc internal_id)
164     {
165         Service s = _services_set.find_service(sid);
166         if (s==null) {
167             return null;
168         }
169
170         return s.get_service_internal(internal_id);
171     }
172
173     final public org.omg.CORBA.Object JavaDoc
174     get_service_callback(String JavaDoc sid, String JavaDoc callback_id)
175     throws org.coach.ECM.UnknownService,
176            org.coach.ECM.UnknownServiceCallback
177     {
178         // TODO: how can the reference to the segment which called
179
// the operation be retrieved???
180

181         // NOTE: one solution could be to have proxies specific to each segment and either wrapping the
182
// references returned by LocalReceptacles::get_connections operation in the receptacle case
183
// or wrapping the LocalReceptacles::push operation in the emitter/publisher cases
184
// That way, the wrapper could "know" to which segment he's bound and set this information
185
// in a thread-safe manner when called, then we could retrieved the information in this class
186
// (as the thread executing the wrapper and the controllers is the same)
187

188         throw new org.coach.ECM.UnknownService();
189         /*
190         Object obj = null;
191
192         if (!(obj instanceof org.coach.ECM.ECMExecutor)) {
193             throw new org.coach.ECM.UnknownService();
194         }
195
196         org.coach.ECM.ECMExecutor ecmexe = (org.coach.ECM.ECMExecutor)obj;
197         return ecmexe.get_service_callback(sid, callback_id);
198         */

199     }
200
201     final public org.coach.ECA.Slot
202     get_slot(int slot_id)
203     {
204         return ComponentRuntime.getSlotFactory().getSlot(slot_id);
205     }
206
207     final public org.omg.CORBA.Any JavaDoc
208     create_any()
209     {
210         return _orb_service.create_any();
211     }
212
213     //
214
// IDL:coach.org/runtime/ECA/ClientCallContext:1.0
215
//
216

217     final public org.omg.CORBA.Object JavaDoc
218     target()
219     {
220         return _real_stub;
221     }
222
223     final public org.omg.CORBA.Policy JavaDoc
224     get_request_policy(int ptype)
225     {
226         ClientCallInformation callinfo = (ClientCallInformation)_call_infos.get(Thread.currentThread().getName());
227         CallInformation cinfo = callinfo.call_information;
228         Policy[] pols = cinfo.policies;
229         for (int i=0;i<pols.length;i++) {
230             if (pols[i].corba_policy().policy_type()==ptype) {
231                 return pols[i].corba_policy();
232             }
233         }
234
235         return null;
236     }
237 }
238
239 class ClientCallInformation
240 {
241     public org.omg.CORBA.Any JavaDoc result;
242     public org.omg.CORBA.Any JavaDoc system_exception;
243     public org.omg.CORBA.Any JavaDoc user_exception;
244     public CallInformation call_information;
245     public java.util.Stack JavaDoc controller_stack;
246     public org.coach.ECA.CallInformation eca_call_information;
247
248     public
249     ClientCallInformation()
250     {
251         result = null;
252         system_exception = null;
253         user_exception = null;
254         call_information = null;
255         controller_stack = new java.util.Stack JavaDoc();
256         eca_call_information = new org.coach.ECA.CallInformation();
257     }
258 }
259
Popular Tags