001: /*
002: * JacORB - a free Java ORB
003: *
004: * Copyright (C) 1999-2004 Gerald Brose
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Library General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Library General Public License for more details.
015: *
016: * You should have received a copy of the GNU Library General Public
017: * License along with this library; if not, write to the Free
018: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019: *
020: */
021:
022: package org.jacorb.orb.portableInterceptor;
023:
024: import java.util.HashSet;
025:
026: import org.omg.PortableInterceptor.ClientRequestInfo;
027: import org.omg.PortableInterceptor.ClientRequestInterceptor;
028: import org.omg.PortableInterceptor.ForwardRequest;
029:
030: /**
031: * @author Gerald Brose
032: * @version $Id: RecursionAwareCI.java,v 1.9 2007/02/15 12:56:06 andre.spiegel Exp $
033: */
034: public abstract class RecursionAwareCI extends
035: org.omg.CORBA.LocalObject implements ClientRequestInterceptor {
036: private final HashSet thread_stacks;
037: private final HashSet ignore_operations;
038:
039: /**
040: * @param ignore_special_ops If set to true, calls to
041: * methods from the CORBA.Object interface like _is_a
042: * will be ignored.
043: */
044: public RecursionAwareCI(boolean ignore_special_ops) {
045: super ();
046:
047: thread_stacks = new HashSet();
048: ignore_operations = new HashSet();
049:
050: if (ignore_special_ops) {
051: ignore_operations.add("_is_a");
052: ignore_operations.add("_get_interface");
053: ignore_operations.add("_non_existent");
054: ignore_operations.add("_get_policy");
055: ignore_operations.add("_get_domain_managers");
056: ignore_operations.add("_set_policy_overrides");
057: ignore_operations.add("_get_component");
058: }
059: }
060:
061: private boolean enterCall(String operation) {
062: if (ignore_operations.contains(operation)) {
063: return false;
064: }
065:
066: Thread currentThread = Thread.currentThread();
067:
068: if (thread_stacks.contains(currentThread)) {
069: return false;
070: }
071:
072: thread_stacks.add(currentThread);
073:
074: return true;
075: }
076:
077: private void exitCall() {
078: thread_stacks.remove(Thread.currentThread());
079: }
080:
081: // implementation InterceptorOperations interface
082: public final void send_request(ClientRequestInfo requestInfo)
083: throws ForwardRequest {
084: if (enterCall(requestInfo.operation())) {
085: try {
086: do_send_request(requestInfo);
087: } finally {
088: exitCall();
089: }
090: }
091: }
092:
093: public final void send_poll(ClientRequestInfo requestInfo) {
094: if (enterCall(requestInfo.operation())) {
095: try {
096: do_send_poll(requestInfo);
097: } finally {
098: exitCall();
099: }
100: }
101: }
102:
103: public final void receive_reply(ClientRequestInfo ri) {
104: if (enterCall(ri.operation())) {
105: try {
106: do_receive_reply(ri);
107: } finally {
108: exitCall();
109: }
110: }
111: }
112:
113: public final void receive_exception(ClientRequestInfo ri)
114: throws ForwardRequest {
115: if (enterCall(ri.operation())) {
116: try {
117: do_receive_exception(ri);
118: } finally {
119: exitCall();
120: }
121: }
122: }
123:
124: public final void receive_other(ClientRequestInfo ri)
125: throws ForwardRequest {
126: if (enterCall(ri.operation())) {
127: try {
128: do_receive_other(ri);
129: } finally {
130: exitCall();
131: }
132: }
133: }
134:
135: public abstract void do_send_request(ClientRequestInfo ri)
136: throws ForwardRequest;
137:
138: public abstract void do_send_poll(ClientRequestInfo ri);
139:
140: public abstract void do_receive_reply(ClientRequestInfo ri);
141:
142: public abstract void do_receive_exception(ClientRequestInfo ri)
143: throws ForwardRequest;
144:
145: public abstract void do_receive_other(ClientRequestInfo ri)
146: throws ForwardRequest;
147: }
|