1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package it.jnrpe;
17
18 import it.jnrpe.commands.CommandRepository;
19 import it.jnrpe.events.IJNRPEEventListener;
20 import it.jnrpe.plugins.IPluginRepository;
21
22 import java.nio.charset.Charset;
23 import java.util.ArrayList;
24 import java.util.Collection;
25
26
27
28
29
30
31 public final class JNRPEBuilder {
32
33
34
35
36 private static final int DEFAULT_READ_TIMEOUT = 10;
37
38
39
40
41 private static final int DEFAULT_WRITE_TIMEOUT = 60;
42
43
44
45
46 private final IPluginRepository pluginRepository;
47
48
49
50
51 private final CommandRepository commandRepository;
52
53
54
55
56 private final Collection<String> acceptedHosts = new ArrayList<String>();
57
58
59
60
61 private final Collection<IJNRPEEventListener> eventListeners = new ArrayList<IJNRPEEventListener>();
62
63
64
65
66 private boolean acceptParams = false;
67
68
69
70
71 private int maxAcceptedConnections = JNRPE.DEFAULT_MAX_ACCEPTED_CONNECTIONS;
72
73
74
75
76 private Charset charset = Charset.defaultCharset();
77
78
79
80
81 private int readTimeout = DEFAULT_READ_TIMEOUT;
82
83
84
85
86 private int writeTimeout = DEFAULT_WRITE_TIMEOUT;
87
88
89
90
91
92
93
94
95
96 private JNRPEBuilder(final IPluginRepository jnrpePluginRepository,
97 final CommandRepository jnrpeCommandRepository) {
98 this.pluginRepository = jnrpePluginRepository;
99 this.commandRepository = jnrpeCommandRepository;
100 }
101
102
103
104
105
106
107
108
109
110
111 public static JNRPEBuilder forRepositories(
112 final IPluginRepository pluginRepository,
113 final CommandRepository commandRepository) {
114
115 return new JNRPEBuilder(pluginRepository, commandRepository);
116 }
117
118
119
120
121
122
123
124
125 public JNRPEBuilder acceptParams(final boolean accept) {
126 this.acceptParams = accept;
127 return this;
128 }
129
130
131
132
133
134
135
136
137 public JNRPEBuilder acceptHost(final String hostName) {
138 this.acceptedHosts.add(hostName);
139 return this;
140 }
141
142
143
144
145
146
147
148
149 public JNRPEBuilder withListener(final IJNRPEEventListener listener) {
150 this.eventListeners.add(listener);
151 return this;
152 }
153
154
155
156
157
158
159
160
161 public JNRPEBuilder withCharset(final Charset newCharset) {
162 this.charset = newCharset;
163 return this;
164 }
165
166
167
168
169
170
171
172
173 public JNRPEBuilder withMaxAcceptedConnections(
174 final int maxConnections) {
175 this.maxAcceptedConnections = maxConnections;
176 return this;
177 }
178
179
180
181
182
183
184
185
186
187 public JNRPEBuilder withReadTimeout(final int readTimeoutSecs) {
188 this.readTimeout = readTimeoutSecs;
189 return this;
190 }
191
192
193
194
195
196
197
198
199
200 public JNRPEBuilder withWriteTimeout(final int writeTimeoutSecs) {
201 this.writeTimeout = writeTimeoutSecs;
202 return this;
203 }
204
205
206
207
208
209
210 public JNRPE build() {
211 JNRPE jnrpe = new JNRPE(pluginRepository, commandRepository, charset,
212 acceptParams, acceptedHosts, maxAcceptedConnections,
213 readTimeout, writeTimeout, eventListeners);
214
215 return jnrpe;
216 }
217 }