KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > coach > tracing > service > pi > TracingServiceImpl


1 /***************************************************************************/
2 /* COACH: Component Based Open Source Architecture for */
3 /* Distributed Telecom Applications */
4 /* See: http://www.objectweb.org/ */
5 /* */
6 /* Copyright (C) 2003 Lucent Technologies Nederland BV */
7 /* Bell Labs Advanced Technologies - EMEA */
8 /* */
9 /* Initial developer(s): Harold Batteram */
10 /* */
11 /* This library is free software; you can redistribute it and/or */
12 /* modify it under the terms of the GNU Lesser General Public */
13 /* License as published by the Free Software Foundation; either */
14 /* version 2.1 of the License, or (at your option) any later version. */
15 /* */
16 /* This library is distributed in the hope that it will be useful, */
17 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
19 /* Lesser General Public License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public */
22 /* License along with this library; if not, write to the Free Software */
23 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
24 /***************************************************************************/
25 package org.coach.tracing.service.pi;
26
27 import org.omg.CORBA.Any JavaDoc;
28 import org.omg.CORBA.OctetSeqHelper JavaDoc;
29 import org.omg.CORBA.TCKind JavaDoc;
30 import org.omg.CORBA.LocalObject JavaDoc;
31 import org.omg.CORBA.ORB JavaDoc;
32 import org.omg.PortableInterceptor.Current JavaDoc;
33 import org.omg.PortableInterceptor.CurrentHelper JavaDoc;
34 import org.omg.PortableInterceptor.InvalidSlot JavaDoc;
35 import java.util.Hashtable JavaDoc;
36 import org.coach.tracing.service.*;
37 import org.coach.tracing.api.pi.*;
38 import java.io.*;
39
40 class TracingServiceImpl extends LocalObject JavaDoc implements TracingService
41 {
42     private int slotId;
43     private int currentServiceId = 0;
44     private Current JavaDoc piCurrent;
45     private Any JavaDoc NOT_IN_EFFECT;
46     private Hashtable JavaDoc dataTable = new Hashtable JavaDoc();
47     private ORB JavaDoc orb;
48
49     public TracingServiceImpl(int slotId)
50     {
51         this.slotId = slotId;
52 //System.err.println("TracingServiceImpl slot: " + slotId);
53
}
54
55     // Package protected so the TracingService ORBInitializer can access this
56
// non-IDL defined method.
57
void setPICurrent(Current JavaDoc piCurrent)
58     {
59         this.piCurrent = piCurrent;
60     }
61
62     private void init()
63     {
64         if (orb == null)
65         {
66 //System.err.println("TracingServiceImpl init()");
67
orb = ORB.init(new String JavaDoc[0], null);
68             NOT_IN_EFFECT = orb.create_any();
69             TracingServiceInterceptor.init();
70         }
71     }
72
73     public synchronized void start()
74     {
75         init();
76         try
77         {
78             // This is called from a client thread scope.
79
Any JavaDoc any = orb.create_any();
80             ThreadContext tc = ThreadContext.getCurrentThreadContext();
81             String JavaDoc tid = tc.getThreadId();
82 //System.err.println("TracingServiceImpl start(): " + tid);
83
any.insert_string(tid);
84             piCurrent.set_slot(slotId, any);
85         }
86         catch (Exception JavaDoc e)
87         {
88             e.printStackTrace();
89         }
90     }
91
92     public void stop()
93     {
94         try
95         {
96             piCurrent.set_slot(slotId, NOT_IN_EFFECT);
97         }
98         catch (Exception JavaDoc e)
99         {
100             e.printStackTrace();
101         }
102     }
103 }
Popular Tags