KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > coach > tracing > service > ComponentContext


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;
26
27 import java.util.*;
28 import java.awt.*;
29 import java.awt.event.*;
30 import org.coach.tracing.api.pi.*;
31
32 public class ComponentContext
33 {
34     private static TracingService tracingService;
35     private static boolean awtInitialized = false;
36     private static int componentCount;
37
38     /**
39      * Java handles all GUI calls within a single awt thread. This means ThreadContext information
40      * cannot be maintained on the basis of the tread id alone.
41      * When a new AWT frame is created the ComponentContext of the thread creating the frame
42      * is stored in a table and accociated with the frame id.
43      */

44     public static synchronized void setFrameContext(java.awt.Frame JavaDoc frame)
45     {
46         if (!awtInitialized)
47         {
48             try
49             {
50                 // Obtain the reference to the tracing service.
51
System.err.println("Initializing COACH tracing service in FrameContext");
52                 tracingService = org.coach.tracing.api.pi.TracingServiceHelper.narrow(org.objectweb.openccm.corba.TheORB.getORB().resolve_initial_references("TracingService"));
53                 // Start the tracing service in the default AWT thread
54
javax.swing.SwingUtilities.invokeLater(new AwtInitializer(tracingService));
55                 awtInitialized = true;
56             }
57             catch (Throwable JavaDoc pix)
58             {
59                 System.err.println("Failed to locate tracing service: " + pix);
60             }
61         }
62         ThreadContext.setFrameThreadContext(frame);
63         // Start the tracing service in the main thread
64
tracingService.start();
65     }
66
67     public static synchronized void setComponentContext(Object JavaDoc ccmObject)
68     {
69         String JavaDoc componentName = "CCMComponent_" + ccmObject.hashCode();
70         String JavaDoc componentType = ccmObject.getClass().getName();
71         
72         if (tracingService == null)
73         {
74             try
75             {
76                 // Obtain the reference to the tracing service.
77
tracingService = org.coach.tracing.api.pi.TracingServiceHelper.narrow(org.objectweb.openccm.corba.TheORB.getORB().resolve_initial_references("TracingService"));
78             }
79             catch (Throwable JavaDoc pix)
80             {
81                 System.err.println("Failed to locate tracing service: " + pix);
82             }
83         }
84
85         ThreadContext tc = ThreadContext.getCurrentThreadContext();
86 //System.err.println("*** setComponentContext: " + tc.getThreadId() + "\ncomponent: " + componentName + "\ntype: " + componentType + "\n" + Thread.currentThread().getName());
87
tc.setComponentName(componentName);
88         tc.setComponentType(componentType);
89         tc.setContainerName("MyContainer");
90         tc.setContainerType("MyContainerType");
91
92         // Start the tracing service in the main thread
93
tracingService.start();
94     }
95 }
96
97 /**
98  * The run method of this class is called from the AWT thread.
99  */

100 class AwtInitializer implements Runnable JavaDoc
101 {
102     TracingService tracingService;
103     
104     public AwtInitializer(TracingService tracingService)
105     {
106         this.tracingService = tracingService;
107     }
108     
109     public void run()
110     {
111 //System.err.println("************ AwtInitializer: " + Thread.currentThread().getName());
112
// start the tracing service in the AWT thread
113
tracingService.start();
114     }
115 }
116         
117
Popular Tags