1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.eclipse.jetty.maven.plugin;
21
22 import java.util.Collection;
23 import java.util.List;
24 import java.util.concurrent.Executor;
25 import java.util.concurrent.Future;
26
27 import org.eclipse.jetty.io.ByteBufferPool;
28 import org.eclipse.jetty.io.EndPoint;
29 import org.eclipse.jetty.server.ConnectionFactory;
30 import org.eclipse.jetty.server.Connector;
31 import org.eclipse.jetty.server.Server;
32 import org.eclipse.jetty.server.ServerConnector;
33 import org.eclipse.jetty.util.annotation.ManagedAttribute;
34 import org.eclipse.jetty.util.component.AbstractLifeCycle;
35 import org.eclipse.jetty.util.thread.Scheduler;
36
37
38
39
40
41
42
43
44
45
46
47
48 public class MavenServerConnector extends AbstractLifeCycle implements Connector
49 {
50 public static String PORT_SYSPROPERTY = "jetty.http.port";
51
52 public static final int DEFAULT_PORT = 8080;
53 public static final String DEFAULT_PORT_STR = String.valueOf(DEFAULT_PORT);
54 public static final int DEFAULT_MAX_IDLE_TIME = 30000;
55
56 private Server server;
57 private ServerConnector delegate;
58 private String host;
59 private String name;
60 private int port;
61 private long idleTimeout;
62 private int lingerTime;
63
64
65 public MavenServerConnector()
66 {
67 }
68
69 public void setServer(Server server)
70 {
71 this.server = server;
72 }
73
74 public void setHost(String host)
75 {
76 this.host = host;
77 }
78
79 public String getHost()
80 {
81 return this.host;
82 }
83
84 public void setPort(int port)
85 {
86 this.port = port;
87 }
88
89 public int getPort ()
90 {
91 return this.port;
92 }
93
94 public void setName (String name)
95 {
96 this.name = name;
97 }
98
99 public void setIdleTimeout(long idleTimeout)
100 {
101 this.idleTimeout = idleTimeout;
102 }
103
104 public void setSoLingerTime(int lingerTime)
105 {
106 this.lingerTime = lingerTime;
107 }
108
109 @Override
110 protected void doStart() throws Exception
111 {
112
113 if (this.server == null)
114 throw new IllegalStateException("Server not set for MavenServerConnector");
115
116 this.delegate = new ServerConnector(this.server);
117 this.delegate.setName(this.name);
118 this.delegate.setPort(this.port);
119 this.delegate.setHost(this.host);
120 this.delegate.setIdleTimeout(idleTimeout);
121 this.delegate.setSoLingerTime(lingerTime);
122 this.delegate.start();
123
124 super.doStart();
125 }
126
127 @Override
128 protected void doStop() throws Exception
129 {
130 this.delegate.stop();
131 super.doStop();
132 this.delegate = null;
133 }
134
135
136
137
138 @Override
139 public Future<Void> shutdown()
140 {
141 checkDelegate();
142 return this.delegate.shutdown();
143 }
144
145
146
147
148 @Override
149 public Server getServer()
150 {
151 return this.server;
152 }
153
154
155
156
157 @Override
158 public Executor getExecutor()
159 {
160 checkDelegate();
161 return this.delegate.getExecutor();
162 }
163
164
165
166
167 @Override
168 public Scheduler getScheduler()
169 {
170 checkDelegate();
171 return this.delegate.getScheduler();
172 }
173
174
175
176
177 @Override
178 public ByteBufferPool getByteBufferPool()
179 {
180 checkDelegate();
181 return this.delegate.getByteBufferPool();
182 }
183
184
185
186
187 @Override
188 public ConnectionFactory getConnectionFactory(String nextProtocol)
189 {
190 checkDelegate();
191 return this.delegate.getConnectionFactory(nextProtocol);
192 }
193
194
195
196
197 @Override
198 public <T> T getConnectionFactory(Class<T> factoryType)
199 {
200 checkDelegate();
201 return this.delegate.getConnectionFactory(factoryType);
202 }
203
204
205
206
207 @Override
208 public ConnectionFactory getDefaultConnectionFactory()
209 {
210 checkDelegate();
211 return this.delegate.getDefaultConnectionFactory();
212 }
213
214
215
216
217 @Override
218 public Collection<ConnectionFactory> getConnectionFactories()
219 {
220 checkDelegate();
221 return this.delegate.getConnectionFactories();
222 }
223
224
225
226
227 @Override
228 public List<String> getProtocols()
229 {
230 checkDelegate();
231 return this.delegate.getProtocols();
232 }
233
234
235
236
237 @Override
238 @ManagedAttribute("maximum time a connection can be idle before being closed (in ms)")
239 public long getIdleTimeout()
240 {
241 checkDelegate();
242 return this.delegate.getIdleTimeout();
243 }
244
245
246
247
248 @Override
249 public Object getTransport()
250 {
251 checkDelegate();
252 return this.delegate.getTransport();
253 }
254
255
256
257
258 @Override
259 public Collection<EndPoint> getConnectedEndPoints()
260 {
261 checkDelegate();
262 return this.delegate.getConnectedEndPoints();
263 }
264
265
266
267
268 @Override
269 public String getName()
270 {
271 return this.name;
272 }
273
274 private void checkDelegate() throws IllegalStateException
275 {
276 if (this.delegate == null)
277 throw new IllegalStateException ("MavenServerConnector delegate not ready");
278 }
279 }