X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=lib%2Fjetty%2Forg%2Feclipse%2Fjetty%2Fserver%2FServerConnector.java;fp=lib%2Fjetty%2Forg%2Feclipse%2Fjetty%2Fserver%2FServerConnector.java;h=2766a89f1bf988732b401628438d172474995f19;hp=a7d5fe0f2d8ee32579f393d22de736f29a6ea11c;hb=ba4f228fa9f72d50991a2218cfd83987ef5d385e;hpb=875b5e9651498a0cd8e0001c0742ba843e47cad0 diff --git a/lib/jetty/org/eclipse/jetty/server/ServerConnector.java b/lib/jetty/org/eclipse/jetty/server/ServerConnector.java index a7d5fe0f..2766a89f 100644 --- a/lib/jetty/org/eclipse/jetty/server/ServerConnector.java +++ b/lib/jetty/org/eclipse/jetty/server/ServerConnector.java @@ -1,6 +1,6 @@ // // ======================================================================== -// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. +// Copyright (c) 1995-2016 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 @@ -20,12 +20,10 @@ package org.eclipse.jetty.server; import java.io.IOException; import java.net.InetSocketAddress; -import java.net.ServerSocket; import java.net.Socket; import java.net.SocketException; import java.nio.channels.Channel; import java.nio.channels.SelectionKey; -import java.nio.channels.Selector; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; import java.util.concurrent.Executor; @@ -37,7 +35,6 @@ import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.SelectChannelEndPoint; import org.eclipse.jetty.io.SelectorManager; import org.eclipse.jetty.io.SelectorManager.ManagedSelector; -import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.Name; @@ -107,7 +104,7 @@ public class ServerConnector extends AbstractNetworkConnector * the number of acceptor threads to use, or -1 for a default value. Acceptors accept new TCP/IP connections. If 0, then * the selector threads are used to accept connections. * @param selectors - * the number of selector threads, or -1 for a default value. Selectors notice and schedule established connection that can make IO progress. + * the number of selector threads, or <=0 for a default value. Selectors notice and schedule established connection that can make IO progress. */ public ServerConnector( @Name("server") Server server, @@ -116,6 +113,26 @@ public class ServerConnector extends AbstractNetworkConnector { this(server,null,null,null,acceptors,selectors,new HttpConnectionFactory()); } + + /* ------------------------------------------------------------ */ + /** HTTP Server Connection. + *

Construct a ServerConnector with a private instance of {@link HttpConnectionFactory} as the only factory.

+ * @param server The {@link Server} this connector will accept connection for. + * @param acceptors + * the number of acceptor threads to use, or -1 for a default value. Acceptors accept new TCP/IP connections. If 0, then + * the selector threads are used to accept connections. + * @param selectors + * the number of selector threads, or <=0 for a default value. Selectors notice and schedule established connection that can make IO progress. + * @param factories Zero or more {@link ConnectionFactory} instances used to create and configure connections. + */ + public ServerConnector( + @Name("server") Server server, + @Name("acceptors") int acceptors, + @Name("selectors") int selectors, + @Name("factories") ConnectionFactory... factories) + { + this(server,null,null,null,acceptors,selectors,factories); + } /* ------------------------------------------------------------ */ /** Generic Server Connection with default configuration. @@ -154,7 +171,7 @@ public class ServerConnector extends AbstractNetworkConnector * the number of acceptor threads to use, or -1 for a default value. Acceptors accept new TCP/IP connections. If 0, then * the selector threads are used to accept connections. * @param selectors - * the number of selector threads, or -1 for a default value. Selectors notice and schedule established connection that can make IO progress. + * the number of selector threads, or <=0 for a default value. Selectors notice and schedule established connection that can make IO progress. */ public ServerConnector( @Name("server") Server server, @@ -184,7 +201,7 @@ public class ServerConnector extends AbstractNetworkConnector * @param server * The server this connector will be accept connection for. * @param executor - * An executor used to run tasks for handling requests, acceptors and selectors. I + * An executor used to run tasks for handling requests, acceptors and selectors. * If null then use the servers executor * @param scheduler * A scheduler used to schedule timeouts. If null then use the servers scheduler @@ -194,7 +211,7 @@ public class ServerConnector extends AbstractNetworkConnector * the number of acceptor threads to use, or -1 for a default value. Acceptors accept new TCP/IP connections. If 0, then * the selector threads are used to accept connections. * @param selectors - * the number of selector threads, or -1 for a default value. Selectors notice and schedule established connection that can make IO progress. + * the number of selector threads, or <=0 for a default value. Selectors notice and schedule established connection that can make IO progress. * @param factories * Zero or more {@link ConnectionFactory} instances used to create and configure connections. */ @@ -208,7 +225,8 @@ public class ServerConnector extends AbstractNetworkConnector @Name("factories") ConnectionFactory... factories) { super(server,executor,scheduler,bufferPool,acceptors,factories); - _manager = new ServerConnectorManager(getExecutor(), getScheduler(), selectors > 0 ? selectors : Runtime.getRuntime().availableProcessors()); + _manager = new ServerConnectorManager(getExecutor(), getScheduler(), + selectors>0?selectors:Math.max(1,Math.min(4,Runtime.getRuntime().availableProcessors()/2))); addBean(_manager, true); } @@ -231,6 +249,29 @@ public class ServerConnector extends AbstractNetworkConnector return channel!=null && channel.isOpen(); } + + @ManagedAttribute("The priority delta to apply to selector threads") + public int getSelectorPriorityDelta() + { + return _manager.getSelectorPriorityDelta(); + } + + /** + * Sets the selector thread priority delta to the given amount. + *

This allows the selector threads to run at a different priority. + * Typically this would be used to lower the priority to give preference + * to handling previously accepted connections rather than accepting + * new connections.

+ * + * @param selectorPriorityDelta the amount to set the thread priority delta to + * (may be negative) + * @see Thread#getPriority() + */ + public void setSelectorPriorityDelta(int selectorPriorityDelta) + { + _manager.setSelectorPriorityDelta(selectorPriorityDelta); + } + /** * @return whether this connector uses a channel inherited from the JVM. * @see System#inheritedChannel() @@ -276,8 +317,8 @@ public class ServerConnector extends AbstractNetworkConnector serverChannel = ServerSocketChannel.open(); InetSocketAddress bindAddress = getHost() == null ? new InetSocketAddress(getPort()) : new InetSocketAddress(getHost(), getPort()); - serverChannel.socket().bind(bindAddress, getAcceptQueueSize()); serverChannel.socket().setReuseAddress(getReuseAddress()); + serverChannel.socket().bind(bindAddress, getAcceptQueueSize()); _localPort = serverChannel.socket().getLocalPort(); if (_localPort <= 0)