01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.object.lockmanager.impl;
06:
07: import com.tc.async.api.EventContext;
08: import com.tc.management.ClientLockStatManager;
09: import com.tc.management.L2LockStatsManager;
10: import com.tc.net.protocol.tcm.ChannelID;
11: import com.tc.object.msg.LockStatisticsResponseMessage;
12: import com.tc.objectserver.api.TestSink;
13: import com.tc.objectserver.context.LockResponseContext;
14:
15: public class ClientServerLockStatManagerGlue implements Runnable {
16: private ClientLockStatManager clientLockStatManager;
17: private L2LockStatsManager serverLockStatManager;
18:
19: private TestSink sink;
20: private ChannelID channelID = new ChannelID(1);
21: private boolean stop = false;
22: private Thread eventNotifier;
23:
24: public ClientServerLockStatManagerGlue(TestSink sink) {
25: super ();
26: this .sink = sink;
27: eventNotifier = new Thread(this ,
28: "ClientServerLockStatManagerGlue");
29: eventNotifier.setDaemon(true);
30: eventNotifier.start();
31: }
32:
33: public void set(ClientLockStatManager clientLockStatManager,
34: L2LockStatsManager serverLockStatManager) {
35: this .clientLockStatManager = clientLockStatManager;
36: this .serverLockStatManager = serverLockStatManager;
37: }
38:
39: public void run() {
40: while (!stop) {
41: EventContext ec = null;
42: try {
43: ec = sink.take();
44: } catch (InterruptedException e) {
45: //
46: }
47: if (ec instanceof LockResponseContext) {
48: LockResponseContext lrc = (LockResponseContext) ec;
49: if (lrc.isLockStatEnabled()) {
50: clientLockStatManager.enableStackTrace(lrc
51: .getLockID(), lrc.getStackTraceDepth(), lrc
52: .getStatCollectFrequency());
53: }
54: } else if (ec instanceof LockStatisticsResponseMessage) {
55: LockStatisticsResponseMessage lsrm = (LockStatisticsResponseMessage) ec;
56: serverLockStatManager.recordStackTraces(lsrm
57: .getLockID(), lsrm.getClientID(), lsrm
58: .getStackTraces());
59: }
60: // ToDO :: implment WaitContext etc..
61: }
62: }
63:
64: public void stop() {
65: stop = true;
66: eventNotifier.interrupt();
67: }
68: }
|