Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 54aedb1303e91c25f6ae983735dcc54c26751e20 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
//
//  ========================================================================
//  Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
//  ------------------------------------------------------------------------
//  All rights reserved. This program and the accompanying materials
//  are made available under the terms of the Eclipse Public License v1.0
//  and Apache License v2.0 which accompanies this distribution.
//
//      The Eclipse Public License is available at
//      http://www.eclipse.org/legal/epl-v10.html
//
//      The Apache License v2.0 is available at
//      http://www.opensource.org/licenses/apache2.0.php
//
//  You may elect to redistribute this code under either of these licenses.
//  ========================================================================
//


package org.eclipse.jetty.maven.plugin;

import java.util.Collection;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Future;

import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.server.ConnectionFactory;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.thread.Scheduler;




/**
 * MavenServerConnector
 *
 * As the ServerConnector class does not have a no-arg constructor, and moreover requires
 * the server instance passed in to all its constructors, it cannot
 * be referenced in the pom.xml. This class wraps a ServerConnector, delaying setting the
 * server instance. Only a few of the setters from the ServerConnector class are supported.
 */
public class MavenServerConnector extends AbstractLifeCycle implements Connector
{
    public static int DEFAULT_PORT = 8080;
    public static String DEFAULT_PORT_STR = String.valueOf(DEFAULT_PORT);   
    public static int DEFAULT_MAX_IDLE_TIME = 30000;
    
    private Server server;
    private ServerConnector delegate;
    private String host;
    private String name;
    private int port;
    private long idleTimeout;
    private int lingerTime;
    
    
    public MavenServerConnector()
    {
    }
    
    public void setServer(Server server)
    {
        this.server = server;
    }

    public void setHost(String host)
    {
        this.host = host;
    }
   
    public String getHost()
    {
        return this.host;
    }

    public void setPort(int port)
    {
        this.port = port;
    }
    
    public int getPort ()
    {
        return this.port;
    }

    public void setName (String name)
    {
        this.name = name;
    }
    
    public void setIdleTimeout(long idleTimeout)
    {
        this.idleTimeout = idleTimeout;
    }
    
    public void setSoLingerTime(int lingerTime)
    {
        this.lingerTime = lingerTime;
    }
    
    @Override
    protected void doStart() throws Exception
    {

        if (this.server == null)
            throw new IllegalStateException("Server not set for MavenServerConnector");

        this.delegate = new ServerConnector(this.server);
        this.delegate.setName(this.name);
        this.delegate.setPort(this.port);
        this.delegate.setHost(this.host);
        this.delegate.setIdleTimeout(idleTimeout);
        this.delegate.setSoLingerTime(lingerTime);
        this.delegate.start();

        super.doStart();
    }

    @Override
    protected void doStop() throws Exception
    {
        this.delegate.stop();
        super.doStop();
        this.delegate = null;
    }

    /** 
     * @see org.eclipse.jetty.util.component.Graceful#shutdown()
     */
    @Override
    public Future<Void> shutdown()
    {
        checkDelegate();
        return this.delegate.shutdown();
    }

    /** 
     * @see org.eclipse.jetty.server.Connector#getServer()
     */
    @Override
    public Server getServer()
    {
        return this.server;
    }

    /** 
     * @see org.eclipse.jetty.server.Connector#getExecutor()
     */
    @Override
    public Executor getExecutor()
    {
        checkDelegate();
        return this.delegate.getExecutor();
    }

    /** 
     * @see org.eclipse.jetty.server.Connector#getScheduler()
     */
    @Override
    public Scheduler getScheduler()
    {
        checkDelegate();
        return this.delegate.getScheduler();
    }

    /** 
     * @see org.eclipse.jetty.server.Connector#getByteBufferPool()
     */
    @Override
    public ByteBufferPool getByteBufferPool()
    {
        checkDelegate();
        return this.delegate.getByteBufferPool();
    }

    /** 
     * @see org.eclipse.jetty.server.Connector#getConnectionFactory(java.lang.String)
     */
    @Override
    public ConnectionFactory getConnectionFactory(String nextProtocol)
    {
        checkDelegate();
        return this.delegate.getConnectionFactory(nextProtocol);
    }

    /** 
     * @see org.eclipse.jetty.server.Connector#getConnectionFactory(java.lang.Class)
     */
    @Override
    public <T> T getConnectionFactory(Class<T> factoryType)
    {
        checkDelegate();
        return this.delegate.getConnectionFactory(factoryType);
    }

    /** 
     * @see org.eclipse.jetty.server.Connector#getDefaultConnectionFactory()
     */
    @Override
    public ConnectionFactory getDefaultConnectionFactory()
    {
        checkDelegate();
        return getDefaultConnectionFactory();
    }

    /** 
     * @see org.eclipse.jetty.server.Connector#getConnectionFactories()
     */
    @Override
    public Collection<ConnectionFactory> getConnectionFactories()
    {
        checkDelegate();
        return this.delegate.getConnectionFactories();
    }

    /** 
     * @see org.eclipse.jetty.server.Connector#getProtocols()
     */
    @Override
    public List<String> getProtocols()
    {
        checkDelegate();
        return this.delegate.getProtocols();
    }

    /** 
     * @see org.eclipse.jetty.server.Connector#getIdleTimeout()
     */
    @Override
    @ManagedAttribute("maximum time a connection can be idle before being closed (in ms)")
    public long getIdleTimeout()
    {
        checkDelegate();
        return this.delegate.getIdleTimeout();
    }

    /** 
     * @see org.eclipse.jetty.server.Connector#getTransport()
     */
    @Override
    public Object getTransport()
    {
        checkDelegate();
        return this.delegate.getTransport();
    }

    /** 
     * @see org.eclipse.jetty.server.Connector#getConnectedEndPoints()
     */
    @Override
    public Collection<EndPoint> getConnectedEndPoints()
    {
        checkDelegate();
        return this.delegate.getConnectedEndPoints();
    }

    /** 
     * @see org.eclipse.jetty.server.Connector#getName()
     */
    @Override
    public String getName()
    {
        return this.name;
    }
    
    private void checkDelegate() throws IllegalStateException
    {
        if (this.delegate == null)
            throw new IllegalStateException ("MavenServerConnector delegate not ready");
    }
}

Back to the top