Synthia
Generic and flexible data structure generator
VisitorPicker.java
Go to the documentation of this file.
1 /*
2  Synthia, a data structure generator
3  Copyright (C) 2019-2020 Laboratoire d'informatique formelle
4  Université du Québec à Chicoutimi, Canada
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 package examples.apache;
20 
21 import ca.uqac.lif.synthia.Picker;
23 import ca.uqac.lif.synthia.util.Freeze;
27 
28 /**
29  * A picker producing instances of visitors.
30  * @ingroup Examples
31  */
32 public class VisitorPicker implements Picker<Picker<LogLine>>
33 {
35 
36  protected Picker<String> m_ip;
37 
39 
41 
43  {
44  super();
45  m_ip = ip;
46  m_map = map;
47  m_timestamp = timestamp;
48  }
49 
50  @Override
52  {
53  MarkovChain<String> map_dup = m_map.duplicate(false);
54  return new LogLinePicker(m_timestamp, new Freeze<String>(m_ip), map_dup);
55  }
56 
57  @Override
58  public Picker<Picker<LogLine>> duplicate(boolean with_state)
59  {
60  // TODO Auto-generated method stub
61  return null;
62  }
63 
64  @Override
65  public void reset()
66  {
67  // TODO Auto-generated method stub
68 
69  }
70 
71  /**
72  * Picker that produces log lines.
73  */
74  protected static class LogLinePicker implements Picker<LogLine>
75  {
76  /**
77  * The picker for the timestamp of the log line.
78  */
79  protected Picker<Long> m_timestamp;
80 
81  /**
82  * The picker for the IP address of the log line.
83  */
84  protected Picker<String> m_ip;
85 
86  /**
87  * The picker for the URL of the log line.
88  */
89  protected Picker<String> m_url;
90 
91  /**
92  * Creates a new log line picker.
93  * @param timestamp The picker for the timestamp of the log line
94  * @param ip The picker for the IP address of the log line
95  * @param url The picker for the URL of the log line
96  */
97  public LogLinePicker(Picker<Long> timestamp, Picker<String> ip, Picker<String> url)
98  {
99  super();
100  m_timestamp = timestamp;
101  m_ip = ip;
102  m_url = url;
103  }
104 
105  @Override
106  public void reset()
107  {
108  m_timestamp.reset();
109  m_ip.reset();
110  m_url.reset();
111  }
112 
113  @Override
114  public LogLine pick()
115  {
116  return new LogLine(m_ip.pick(), m_timestamp.pick(), 0, new Request(Method.GET, m_url.pick()), StatusCode.OK, 1000);
117  }
118 
119  @Override
120  public LogLinePicker duplicate(boolean with_state)
121  {
122  return new LogLinePicker(m_timestamp.duplicate(with_state), m_ip.duplicate(with_state), m_url.duplicate(with_state));
123  }
124  }
125 }
examples.apache
Generates a fake web server log simulating the trajectory of multiple visitors through a randomly-gen...
Definition: GenerateLog.java:19
ca.uqac.lif.synthia.Picker
Picks an object.
Definition: Picker.java:36
ca.uqac.lif.synthia.util.Freeze
Picker that returns the first object fetched from another picker and repeats it endlessly.
Definition: Freeze.java:48
examples.apache.VisitorPicker.m_floatSource
Picker< Float > m_floatSource
Definition: VisitorPicker.java:34
examples.apache.LogLine
Representation of a line of Apache's access log.
Definition: LogLine.java:31
ca.uqac.lif.synthia.util
Miscellaneous pickers performing various functions.
Definition: ArrayPicker.java:19
examples.apache.LogLine.StatusCode
The possible status codes associated to each request.
Definition: LogLine.java:36
examples.apache.VisitorPicker.duplicate
Picker< Picker< LogLine > > duplicate(boolean with_state)
Creates a copy of the picker.
Definition: VisitorPicker.java:58
ca.uqac
examples.apache.VisitorPicker
A picker producing instances of visitors.
Definition: VisitorPicker.java:32
ca.uqac.lif.synthia
Definition: Bounded.java:19
examples.apache.VisitorPicker.pick
Picker< LogLine > pick()
Picks an object.
Definition: VisitorPicker.java:51
examples.apache.VisitorPicker.reset
void reset()
Puts the picker back into its initial state.
Definition: VisitorPicker.java:65
examples.apache.VisitorPicker.m_ip
Picker< String > m_ip
Definition: VisitorPicker.java:36
ca.uqac.lif.synthia.sequence.MarkovChain.duplicate
MarkovChain< T > duplicate(boolean with_state)
Creates a copy of the picker.
Definition: MarkovChain.java:190
ca.uqac.lif
ca
ca.uqac.lif.synthia.Picker.pick
T pick()
Picks an object.
examples.apache.LogLine.Request
Simple representation of an HTTP request.
Definition: LogLine.java:120
ca.uqac.lif.synthia.sequence.MarkovChain
Generates a sequence of objects by a random walk in a Markov chain.
Definition: MarkovChain.java:47
examples.apache.VisitorPicker.m_timestamp
Picker< Long > m_timestamp
Definition: VisitorPicker.java:40
examples.apache.VisitorPicker.m_map
MarkovChain< String > m_map
Definition: VisitorPicker.java:38
examples
examples.apache.VisitorPicker.VisitorPicker
VisitorPicker(Picker< Long > timestamp, Picker< String > ip, MarkovChain< String > map)
Definition: VisitorPicker.java:42
ca.uqac.lif.synthia.Picker.duplicate
Picker< T > duplicate(boolean with_state)
Creates a copy of the picker.
ca.uqac.lif.synthia.Picker.reset
void reset()
Puts the picker back into its initial state.
ca.uqac.lif.synthia.sequence
Pickers related to the generation of a sequence of values.
Definition: BehaviorTree.java:19
examples.apache.LogLine.Request.Method
Definition: LogLine.java:122