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