2 // ========================================================================
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
19 package org.eclipse.jetty.server;
21 import java.io.IOException;
22 import java.util.concurrent.Executor;
23 import java.util.concurrent.Future;
25 import org.eclipse.jetty.io.ByteBufferPool;
26 import org.eclipse.jetty.util.annotation.ManagedAttribute;
27 import org.eclipse.jetty.util.annotation.ManagedObject;
28 import org.eclipse.jetty.util.thread.Scheduler;
31 * An abstract Network Connector.
33 * Extends the {@link AbstractConnector} support for the {@link NetworkConnector} interface.
35 @ManagedObject("AbstractNetworkConnector")
36 public abstract class AbstractNetworkConnector extends AbstractConnector implements NetworkConnector
39 private volatile String _host;
40 private volatile int _port = 0;
42 public AbstractNetworkConnector(Server server, Executor executor, Scheduler scheduler, ByteBufferPool pool, int acceptors, ConnectionFactory... factories)
44 super(server,executor,scheduler,pool,acceptors,factories);
47 public void setHost(String host)
53 @ManagedAttribute("The network interface this connector binds to as an IP address or a hostname. If null or 0.0.0.0, then bind to all interfaces.")
54 public String getHost()
59 public void setPort(int port)
65 @ManagedAttribute("Port this connector listens on. If set the 0 a random port is assigned which may be obtained with getLocalPort()")
72 public int getLocalPort()
78 protected void doStart() throws Exception
85 protected void doStop() throws Exception
92 public void open() throws IOException
99 // Interrupting is often sufficient to close the channel
100 interruptAcceptors();
105 public Future<Void> shutdown()
108 return super.shutdown();
112 protected boolean isAccepting()
114 return super.isAccepting() && isOpen();
118 public String toString()
120 return String.format("%s{%s:%d}",
122 getHost() == null ? "0.0.0.0" : getHost(),
123 getLocalPort() <= 0 ? getPort() : getLocalPort());