Code Examples
A repository of 155 code examples for BeepBeep
MonitoringEvent.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2019 Sylvain HallĂ©
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published
7  by the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package misc.temperature;
19 
20 /**
21  * Parent class of all the input events in this example.
22  */
23 public abstract class MonitoringEvent
24 {
25  /**
26  * The ID of the rack where the event is generated
27  */
28  private int m_rackId;
29 
30  /**
31  * A timestamp indicating the moment when the event was created
32  * (in seconds). This is the only modification we made to the events with
33  * respect to the original example (which do not carry a timestamp).
34  */
35  private float m_timestamp;
36 
37  /**
38  * Creates a new monitoring event
39  * @param rack_id The ID of the rack where the event occurs
40  */
41  public MonitoringEvent(int rack_id)
42  {
43  super();
44  m_rackId = rack_id;
45  m_timestamp = (float) System.currentTimeMillis() / 1000f;
46  }
47 
48  /**
49  * Gets the event's rack ID
50  * @return The rack ID
51  */
52  public int getRackID()
53  {
54  return m_rackId;
55  }
56 
57  /**
58  * Gets the event's timestamp
59  * @return The timestamp, in seconds
60  */
61  public float getTimestamp()
62  {
63  return m_timestamp;
64  }
65 
66  /**
67  * Sub-class of monitoring event containing a temperature reading.
68  */
69  public static class TemperatureEvent extends MonitoringEvent
70  {
71  /**
72  * The temperature
73  */
74  private double m_temperature;
75 
76  /**
77  * Creates a new temperature event
78  * @param rack_id The ID of the rack where the event occurs
79  * @param temperature The temperature
80  */
81  public TemperatureEvent(int rack_id, double temperature)
82  {
83  super(rack_id);
84  m_temperature = temperature;
85  }
86 
87  /**
88  * Gets the event's temperature
89  * @return The temperature
90  */
91  public double getTemperature()
92  {
93  return m_temperature;
94  }
95 
96  @Override
97  public String toString()
98  {
99  return "TemperatureEvent(" + getTimestamp() + "," + getRackID() + ", " + m_temperature + ")";
100  }
101  }
102 
103  /**
104  * Sub-class of monitoring event containing a voltage reading.
105  */
106  public static class PowerEvent extends MonitoringEvent
107  {
108  /**
109  * The voltage
110  */
111  private double m_voltage;
112 
113  /**
114  * Creates a new temperature event
115  * @param rack_id The ID of the rack where the event occurs
116  * @param voltage The voltage
117  */
118  public PowerEvent(int rack_id, double voltage)
119  {
120  super(rack_id);
121  m_voltage = voltage;
122  }
123 
124  /**
125  * Gets the event's voltage
126  * @return The voltage
127  */
128  public double getVoltage()
129  {
130  return m_voltage;
131  }
132 
133  @Override
134  public String toString()
135  {
136  return "PowerEvent(" + getTimestamp() + "," + getRackID() + ", " + m_voltage + ")";
137  }
138  }
139 }
Parent class of all the input events in this example.
int getRackID()
Gets the event&#39;s rack ID.
MonitoringEvent(int rack_id)
Creates a new monitoring event.
float getTimestamp()
Gets the event&#39;s timestamp.