KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > util > tracing > TraceInitializer


1 package org.jacorb.util.tracing;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1999-2004 Gerald Brose
7  *
8  * This library is free software; you can redistribute it and/or
9  * 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 JavaDoc;
25 import org.omg.CosNaming.NamingContextExtHelper JavaDoc;
26 import org.omg.IOP.Codec JavaDoc;
27 import org.omg.IOP.ENCODING_CDR_ENCAPS JavaDoc;
28 import org.omg.IOP.Encoding JavaDoc;
29 import org.omg.PortableInterceptor.ORBInitInfo JavaDoc;
30 import org.omg.PortableInterceptor.ORBInitializer JavaDoc;
31
32 /**
33  * This class registers the trace interceptors
34  */

35 public class TraceInitializer
36     extends org.omg.CORBA.LocalObject JavaDoc
37     implements ORBInitializer JavaDoc
38 {
39     public TraceInitializer()
40     {
41     }
42
43     /**
44      * This method registers the interceptor.
45      */

46     public void post_init(ORBInitInfo JavaDoc info)
47     {
48         try
49         {
50             int slot_id = info.allocate_slot_id();
51
52             NamingContextExt JavaDoc nc =
53                 NamingContextExtHelper.narrow(
54                      info.resolve_initial_references("NameService"));
55
56             TracingService tracer =
57                 TracingServiceHelper.narrow(
58                     nc.resolve( nc.to_name("tracing.service")));
59
60
61             if( tracer == null )
62             {
63                 System.err.println("No Tracing Service, cannot register tracer interceptor!");
64                 return;
65             }
66
67             Encoding JavaDoc encoding = new Encoding JavaDoc(ENCODING_CDR_ENCAPS.value,
68                                              (byte) 1, (byte) 0);
69             Codec JavaDoc codec = info.codec_factory().create_codec(encoding);
70
71             ClientTraceInterceptor interceptor =
72                 new ClientTraceInterceptor(codec, slot_id , tracer);
73             info.add_client_request_interceptor(interceptor);
74
75             info.add_server_request_interceptor( new ServerTraceInterceptor( slot_id,
76                                                                              codec));
77
78         }
79         catch (Exception JavaDoc e)
80         {
81             e.printStackTrace();
82         }
83     }
84
85     public void pre_init(ORBInitInfo JavaDoc info)
86     {
87     }
88
89 }
90
Popular Tags