Code Examples
A repository of 155 code examples for BeepBeep
MonitoringEventSource.java
1 package misc.temperature;
2 
3 import ca.uqac.lif.cep.Processor;
4 import ca.uqac.lif.cep.ProcessorException;
5 import ca.uqac.lif.cep.tmf.Source;
6 import java.util.Queue;
7 import java.util.Random;
10 
11 public class MonitoringEventSource extends Source
12 {
13  private final int maxRackId;
14 
15  private final long pause;
16 
17  private final double temperatureRatio;
18 
19  private final double powerStd;
20 
21  private final double powerMean;
22 
23  private final double temperatureStd;
24 
25  private final double temperatureMean;
26 
27  private int offset;
28 
29  private Random m_random = new Random();
30 
31  public MonitoringEventSource(int maxRackId, long pause,
32  double temperatureRatio,
33  double powerStd,
34  double powerMean,
35  double temperatureStd,
36  double temperatureMean)
37  {
38  super(1);
39  this.maxRackId = maxRackId;
40  this.pause = pause;
41  this.temperatureRatio = temperatureRatio;
42  this.powerMean = powerMean;
43  this.powerStd = powerStd;
44  this.temperatureMean = temperatureMean;
45  this.temperatureStd = temperatureStd;
46  }
47 
48  @Override
49  protected boolean compute(Object[] inputs, Queue<Object[]> outputs)
50  {
51  MonitoringEvent monitoringEvent;
52  int rackId = m_random.nextInt(maxRackId) + offset;
53  if (m_random.nextDouble() >= temperatureRatio)
54  {
55  double power = m_random.nextGaussian() * powerStd + powerMean;
56  monitoringEvent = new PowerEvent(rackId, power);
57  }
58  else
59  {
60  double temperature = m_random.nextGaussian() * temperatureStd + temperatureMean;
61  monitoringEvent = new TemperatureEvent(rackId, temperature);
62  }
63  outputs.add(new Object[] {monitoringEvent});
64  try
65  {
66  Thread.sleep(pause);
67  }
68  catch (InterruptedException e)
69  {
70  throw new ProcessorException(e);
71  }
72  return true;
73  }
74 
75  @Override
76  public Processor duplicate(boolean with_state)
77  {
78  // TODO Auto-generated method stub
79  return null;
80  }
81 }
A collection of examples taken from other stream processing software, and redone with BeepBeep...
Parent class of all the input events in this example.
Sub-class of monitoring event containing a temperature reading.
Sub-class of monitoring event containing a voltage reading.