001: package org.jacorb.util.tracing;
002:
003: /*
004: * JacORB - a free Java ORB
005: *
006: * Copyright (C) 1997-2004 Gerald Brose.
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Library General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Library General Public License for more details.
017: *
018: * You should have received a copy of the GNU Library General Public
019: * License along with this library; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: */
022:
023: import java.util.Hashtable;
024: import org.jacorb.util.tracing.TracingServicePackage.NoSuchRequestId;
025: import org.omg.CosNaming.NamingContextExt;
026: import org.omg.CosNaming.NamingContextExtHelper;
027:
028: /**
029: * @author Gerald Brose
030: * @version $Id: TracingServiceImpl.java,v 1.10 2006/07/27 10:32:57 alphonse.bendt Exp $
031: */
032: public class TracingServiceImpl extends TracingServicePOA {
033: private int pointIds = 0;
034: private Hashtable traces = new Hashtable();
035:
036: public synchronized int get_id() {
037: return pointIds++;
038: }
039:
040: public TraceData getTrace(Request source) throws NoSuchRequestId {
041: if (source.originator >= pointIds) {
042: System.out.println(">>>>>>>>>EXCEPTION!!! - getTrace()");
043:
044: throw new NoSuchRequestId();
045: }
046:
047: System.out.println("getTrace for tracer: " + source.originator
048: + ", rid: " + source.rid);
049:
050: Long key = new Long(source.rid);
051:
052: TraceTreeNode t = (TraceTreeNode) traces.get(key);
053:
054: if (t == null) {
055: return new TraceData(new TraceData[0], 0, "", 0, 0);
056: }
057:
058: TraceData result = new TraceData(new TraceData[t.subtraces
059: .size()], t.tracer_id, t.operation, t.client_time,
060: t.server_time);
061:
062: for (int i = 0; i < t.subtraces.size(); i++) {
063: Request r = (Request) t.subtraces.elementAt(i);
064: result.subtrace[i] = getTrace(r);
065: }
066:
067: return result;
068: }
069:
070: public void logTraceAtPoint(Request origin, String operation,
071: long client_time, long server_time) throws NoSuchRequestId {
072: if (origin.originator >= pointIds) {
073: System.out
074: .println(">>>>>>>>>EXCEPTION!!! - logTraceAtPoint()");
075:
076: throw new NoSuchRequestId();
077: }
078:
079: System.out.println("logTraceAtPoint for tracer: "
080: + origin.originator + ", rid: " + origin.rid);
081:
082: Long key = new Long(origin.rid);
083:
084: TraceTreeNode t = (TraceTreeNode) traces.get(key);
085:
086: if (t == null) {
087: t = new TraceTreeNode(origin.originator);
088: traces.put(key, t);
089: }
090:
091: t.operation = operation;
092: t.client_time = client_time;
093: t.server_time = server_time;
094: }
095:
096: public void registerSubTrace(Request original, // original call
097: Request nested) // nested call
098: throws NoSuchRequestId {
099:
100: System.out.println("registerSubTrace for tracer: "
101: + original.originator + ", rid: " + original.rid);
102:
103: if (original.originator >= pointIds
104: || nested.originator >= pointIds) {
105: System.out
106: .println(">>>>>>>>>EXCEPTION!!! - registerSubTrace()");
107: throw new NoSuchRequestId();
108: }
109:
110: Long key = new Long(original.rid);
111:
112: TraceTreeNode t = (TraceTreeNode) traces.get(key);
113:
114: if (t == null) {
115: t = new TraceTreeNode(original.originator);
116: traces.put(key, t);
117: }
118:
119: t.subtraces.addElement(nested);
120: }
121:
122: public static void main(String[] args) {
123: org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
124: try {
125: org.omg.PortableServer.POA poa = org.omg.PortableServer.POAHelper
126: .narrow(orb.resolve_initial_references("RootPOA"));
127:
128: poa.the_POAManager().activate();
129:
130: org.omg.CORBA.Object o = poa
131: .servant_to_reference(new TracingServiceImpl());
132:
133: NamingContextExt nc = NamingContextExtHelper.narrow(orb
134: .resolve_initial_references("NameService"));
135: nc.bind(nc.to_name("tracing.service"), o);
136: poa.the_POAManager().activate();
137: } catch (Exception e) {
138: e.printStackTrace();
139: }
140: orb.run();
141: }
142: }
|