EMMA Coverage Report (generated Mon Aug 23 17:21:34 CEST 2010)
[all classes][org.dcache.cells]

COVERAGE SUMMARY FOR SOURCE FILE [MessageProcessingMonitor.java]

nameclass, %method, %block, %line, %
MessageProcessingMonitor.java100% (1/1)18%  (2/11)28%  (22/79)35%  (7/20)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MessageProcessingMonitor100% (1/1)18%  (2/11)28%  (22/79)35%  (7/20)
ac_monitoring_disable (Args): String 0%   (0/1)0%   (0/5)0%   (0/2)
ac_monitoring_enable (Args): String 0%   (0/1)0%   (0/5)0%   (0/2)
ac_monitoring_info (Args): String 0%   (0/1)0%   (0/15)0%   (0/1)
access$000 (MessageProcessingMonitor): RequestCounters 0%   (0/1)0%   (0/3)0%   (0/1)
access$100 (MessageProcessingMonitor): CellEndpoint 0%   (0/1)0%   (0/3)0%   (0/1)
access$200 (MessageProcessingMonitor): RequestExecutionTimeGauges 0%   (0/1)0%   (0/3)0%   (0/1)
getReplyCellEndpoint (CellMessage): CellEndpoint 0%   (0/1)0%   (0/16)0%   (0/4)
isEnabled (): boolean 0%   (0/1)0%   (0/3)0%   (0/1)
setEnabled (boolean): void 0%   (0/1)0%   (0/4)0%   (0/2)
MessageProcessingMonitor (): void 100% (1/1)100% (18/18)100% (5/5)
setCellEndpoint (CellEndpoint): void 100% (1/1)100% (4/4)100% (2/2)

1package org.dcache.cells;
2 
3import java.util.Map;
4 
5import org.dcache.commons.stats.RequestCounterImpl;
6import org.dcache.commons.stats.RequestExecutionTimeGauge;
7import org.dcache.commons.stats.RequestCounters;
8import org.dcache.commons.stats.RequestExecutionTimeGauges;
9 
10import diskCacheV111.vehicles.Message;
11 
12import dmg.util.Args;
13import dmg.cells.nucleus.CellMessage;
14import dmg.cells.nucleus.NoRouteToCellException;
15import dmg.cells.nucleus.SerializationException;
16import dmg.cells.nucleus.CellEndpoint;
17import dmg.cells.nucleus.CellInfo;
18import dmg.cells.nucleus.CellMessageAnswerable;
19 
20public class MessageProcessingMonitor
21    implements CellCommandListener, CellMessageSender
22{
23    /**
24     * Request counters used to count message processing.
25     */
26    private final RequestCounters<Class> _counters;
27 
28    /**
29     * Request gauges used to measure message processing.
30     */
31    private final RequestExecutionTimeGauges<Class> _gauges;
32 
33    private CellEndpoint _endpoint;
34 
35    /**
36     * If true then message processing will be monitored and
37     * administrative commands to query the monitoring results are
38     * activated.
39     */
40    private boolean _enabled;
41 
42    public MessageProcessingMonitor()
43    {
44        _counters = new RequestCounters<Class>("Messages");
45        _gauges = new RequestExecutionTimeGauges<Class>("Messages");
46        _enabled = false;
47    }
48 
49    @Override
50    public void setCellEndpoint(CellEndpoint endpoint)
51    {
52        _endpoint = endpoint;
53    }
54 
55    public void setEnabled(boolean enabled)
56    {
57        _enabled = enabled;
58    }
59 
60    public boolean isEnabled()
61    {
62        return _enabled;
63    }
64 
65    public CellEndpoint getReplyCellEndpoint(CellMessage envelope)
66    {
67        if (_enabled) {
68            Class type = envelope.getMessageObject().getClass();
69            return new MonitoringReplyCellEndpoint(type);
70        } else {
71            return _endpoint;
72        }
73    }
74 
75    public final static String hh_monitoring_enable =
76        "# Enables monitoring of message processing";
77    public String ac_monitoring_enable(Args args)
78    {
79        _enabled = true;
80        return "";
81    }
82 
83    public final static String hh_monitoring_disable =
84        "# Disables monitoring of message processing";
85    public String ac_monitoring_disable(Args args)
86    {
87        _enabled = false;
88        return "";
89    }
90 
91    public final static String hh_monitoring_info =
92        "# Provides information about message processing";
93    public String ac_monitoring_info(Args args)
94    {
95        return _counters.toString() + "\n\n" + _gauges.toString();
96    }
97 
98    public class MonitoringReplyCellEndpoint implements CellEndpoint
99    {
100        private final Class _type;
101        private final long _startTime;
102 
103        public MonitoringReplyCellEndpoint(Class type)
104        {
105            _startTime = System.currentTimeMillis();
106            _type = type;
107            _counters.incrementRequests(_type);
108        }
109 
110        public void sendMessage(CellMessage envelope)
111            throws SerializationException,
112                   NoRouteToCellException
113        {
114            boolean success = false;
115            try {
116                _endpoint.sendMessage(envelope);
117                success = true;
118            } finally {
119                _gauges.update(_type, System.currentTimeMillis() - _startTime);
120                Object o = envelope.getMessageObject();
121                if (!success || o instanceof Exception ||
122                    (o instanceof Message) && ((Message) o).getReturnCode() != 0) {
123                    _counters.incrementFailed(_type);
124                }
125            }
126        }
127 
128        public void sendMessage(CellMessage envelope,
129                                CellMessageAnswerable callback,
130                                long timeout)
131        {
132            throw new UnsupportedOperationException("Cannot use callback for reply");
133        }
134 
135        public CellMessage sendAndWait(CellMessage envelope, long timeout)
136        {
137            throw new UnsupportedOperationException("Cannot use blocking send for reply");
138        }
139 
140        public CellMessage sendAndWaitToPermanent(CellMessage envelope, long timeout)
141        {
142            throw new UnsupportedOperationException("Cannot use blocking send for reply");
143        }
144 
145        public CellInfo getCellInfo()
146        {
147            return _endpoint.getCellInfo();
148        }
149 
150        public Map<String,Object> getDomainContext()
151        {
152            return _endpoint.getDomainContext();
153        }
154 
155        public Args getArgs()
156        {
157            return _endpoint.getArgs();
158        }
159    }
160}

[all classes][org.dcache.cells]
EMMA 2.0.5312 (C) Vladimir Roubtsov