01: package org.jacorb.util.tracing;
02:
03: /*
04: * JacORB - a free Java ORB
05: *
06: * Copyright (C) 1999-2004 Gerald Brose
07: *
08: * This library is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU Library General Public
10: * License as published by the Free Software Foundation; either
11: * version 2 of the License, or (at your option) any later version.
12: *
13: * This library is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16: * Library General Public License for more details.
17: *
18: * You should have received a copy of the GNU Library General Public
19: * License along with this library; if not, write to the Free
20: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21: *
22: */
23:
24: import org.omg.CosNaming.NamingContextExt;
25: import org.omg.CosNaming.NamingContextExtHelper;
26: import org.omg.IOP.Codec;
27: import org.omg.IOP.ENCODING_CDR_ENCAPS;
28: import org.omg.IOP.Encoding;
29: import org.omg.PortableInterceptor.ORBInitInfo;
30: import org.omg.PortableInterceptor.ORBInitializer;
31:
32: /**
33: * This class registers the trace interceptors
34: */
35: public class TraceInitializer extends org.omg.CORBA.LocalObject
36: implements ORBInitializer {
37: /**
38: * This method registers the interceptor.
39: */
40: public void post_init(ORBInitInfo info) {
41: try {
42: int slot_id = info.allocate_slot_id();
43:
44: NamingContextExt nc = NamingContextExtHelper.narrow(info
45: .resolve_initial_references("NameService"));
46:
47: TracingService tracer = TracingServiceHelper.narrow(nc
48: .resolve(nc.to_name("tracing.service")));
49:
50: if (tracer == null) {
51: System.err
52: .println("No Tracing Service, cannot register tracer interceptor!");
53: return;
54: }
55:
56: Encoding encoding = new Encoding(ENCODING_CDR_ENCAPS.value,
57: (byte) 1, (byte) 0);
58: Codec codec = info.codec_factory().create_codec(encoding);
59:
60: ClientTraceInterceptor interceptor = new ClientTraceInterceptor(
61: codec, slot_id, tracer);
62: info.add_client_request_interceptor(interceptor);
63:
64: info
65: .add_server_request_interceptor(new ServerTraceInterceptor(
66: slot_id, codec));
67:
68: } catch (Exception e) {
69: e.printStackTrace();
70: }
71: }
72:
73: public void pre_init(ORBInitInfo info) {
74: }
75: }
|