KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > orb > portableInterceptor > RecursionAwareCI


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21 package org.jacorb.orb.portableInterceptor;
22
23 import org.omg.PortableInterceptor.*;
24
25 import java.util.*;
26 import org.omg.CORBA.LocalObject JavaDoc;
27
28 public abstract class RecursionAwareCI
29     extends org.omg.CORBA.LocalObject JavaDoc
30     implements ClientRequestInterceptor
31 {
32     private Hashtable thread_stacks = null;
33     
34     private Hashtable ignore_operations = null;
35
36     /**
37      * @param ignore_special_ops If set to true, calls to
38      * methods from the CORBA.Object interface like _is_a
39      * will be ignored.
40      */

41     public RecursionAwareCI( boolean ignore_special_ops )
42     {
43         thread_stacks = new Hashtable();
44         ignore_operations = new Hashtable();
45
46         if ( ignore_special_ops )
47         {
48             ignore_operations.put( "_is_a", "" );
49             ignore_operations.put( "_get_interface", "" );
50             ignore_operations.put( "_non_existent", "" );
51             ignore_operations.put( "_get_policy", "" );
52             ignore_operations.put( "_get_domain_managers", "" );
53             ignore_operations.put( "_set_policy_overrides", "" );
54         }
55     }
56
57     public void addIgnoreOperation( String JavaDoc operation_name )
58     {
59         ignore_operations.put( operation_name, operation_name );
60     }
61
62     private boolean enterCall( String JavaDoc operation )
63     {
64         if ( ignore_operations.containsKey( operation ) )
65             return false;
66
67         Thread JavaDoc current = Thread.currentThread();
68
69         if ( thread_stacks.containsKey( current ))
70             return false;
71
72         thread_stacks.put( current, current );
73
74         return true;
75     }
76
77     private void exitCall()
78     {
79         thread_stacks.remove( Thread.currentThread() );
80     }
81
82     // implementation InterceptorOperations interface
83
public final void send_request( ClientRequestInfo ri )
84         throws ForwardRequest
85     {
86         if( enterCall( ri.operation() ))
87         {
88             try
89             {
90                 do_send_request( ri );
91             }
92             finally
93             {
94                 exitCall();
95             }
96         }
97     }
98
99     public final void send_poll(ClientRequestInfo ri)
100     {
101         if( enterCall( ri.operation() ))
102         {
103             try
104             {
105                 do_send_poll( ri );
106             }
107             finally
108             {
109                 exitCall();
110             }
111         }
112     }
113
114     public final void receive_reply(ClientRequestInfo ri)
115     {
116         if( enterCall( ri.operation() ))
117         {
118             try
119             {
120                 do_receive_reply( ri );
121             }
122             finally
123             {
124                 exitCall();
125             }
126         }
127     }
128
129     public final void receive_exception(ClientRequestInfo ri)
130         throws ForwardRequest
131     {
132         if( enterCall( ri.operation() ))
133         {
134             try
135             {
136                 do_receive_exception( ri );
137             }
138             finally
139             {
140                 exitCall();
141             }
142         }
143     }
144
145     public final void receive_other(ClientRequestInfo ri)
146         throws ForwardRequest
147     {
148         if( enterCall( ri.operation() ))
149         {
150             try
151             {
152                 do_receive_other( ri );
153             }
154             finally
155             {
156                 exitCall();
157             }
158         }
159     }
160
161     public abstract void do_send_request( ClientRequestInfo ri )
162         throws ForwardRequest;
163
164     public abstract void do_send_poll(ClientRequestInfo ri);
165
166     public abstract void do_receive_reply(ClientRequestInfo ri);
167
168     public abstract void do_receive_exception(ClientRequestInfo ri)
169         throws ForwardRequest;
170
171     public abstract void do_receive_other(ClientRequestInfo ri)
172         throws ForwardRequest;
173 }
174
175
176
177
178
179
180
181
182
183
184
185
Popular Tags