1
2
3
4
5
6
7
8
9
10
11 package org.mule.management.stats;
12
13 import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicLong;
14 import org.mule.api.management.stats.Statistics;
15
16
17
18
19 public abstract class AbstractFlowConstructStatistics implements Statistics
20 {
21 private static final long serialVersionUID = 5337576392583767442L;
22
23 protected final String flowConstructType;
24 protected String name;
25 protected boolean enabled = false;
26 private long samplePeriod = 0;
27 protected final AtomicLong receivedEventSync = new AtomicLong(0);
28 protected final AtomicLong receivedEventASync = new AtomicLong(0);
29
30 public AbstractFlowConstructStatistics(String flowConstructType, String name)
31 {
32 this.name = name;
33 this.flowConstructType = flowConstructType;
34 }
35
36
37
38
39 public synchronized void setEnabled(boolean b)
40 {
41 enabled = b;
42 }
43
44
45
46
47 public boolean isEnabled()
48 {
49 return enabled;
50 }
51
52 public synchronized String getName()
53 {
54 return name;
55 }
56
57 public synchronized void setName(String name)
58 {
59 this.name = name;
60 }
61
62 public synchronized void clear()
63 {
64 receivedEventSync.set(0);
65 receivedEventASync.set(0);
66 samplePeriod = System.currentTimeMillis();
67 }
68
69
70 public void incReceivedEventSync()
71 {
72 receivedEventSync.addAndGet(1);
73 }
74
75 public void incReceivedEventASync()
76 {
77 receivedEventASync.addAndGet(1);
78 }
79
80 public long getAsyncEventsReceived()
81 {
82 return receivedEventASync.get();
83 }
84
85 public long getSyncEventsReceived()
86 {
87 return receivedEventSync.get();
88 }
89
90 public long getTotalEventsReceived()
91 {
92 return getSyncEventsReceived() + getAsyncEventsReceived();
93 }
94
95 public String getFlowConstructType()
96 {
97 return flowConstructType;
98 }
99
100 public long getSamplePeriod()
101 {
102 return System.currentTimeMillis() - samplePeriod;
103 }
104 }