/** * Obtain the Executor used by the underlying endpoint. */ @Override public Executor getExecutor() { return endpoint.getExecutor(); }
public InetAddress getAddress() { return endpoint.getAddress(); } public void setAddress(InetAddress ia) {
public String getProperty(String name) { return (String) getAttribute(name); }
public final void start() throws Exception { if (bindState == BindState.UNBOUND) { bind(); bindState = BindState.BOUND_ON_START; } startInternal(); }
protected final void startAcceptorThreads() { int count = getAcceptorThreadCount(); acceptors = new Acceptor[count]; for (int i = 0; i < count; i++) { acceptors[i] = createAcceptor(); Thread t = new Thread(acceptors[i], getName() + "-Acceptor-" + i); t.setPriority(getAcceptorThreadPriority()); t.setDaemon(getDaemon()); t.start(); } }
/** * Pause the endpoint, which will stop it accepting new connections and * unlock the acceptor. */ public void pause() { if (running && !paused) { paused = true; releaseConnectionLatch(); unlockAccept(); getHandler().pause(); } }
saddr = new InetSocketAddress("localhost", getPort()); } else { saddr = new InetSocketAddress(address,getPort()); if (getSocketProperties().getSoTimeout() > stmo) stmo = getSocketProperties().getSoTimeout(); if (getSocketProperties().getUnlockTimeout() > utmo) utmo = getSocketProperties().getUnlockTimeout(); s.setSoTimeout(stmo); s.setSoLinger(getSocketProperties().getSoLingerOn(),getSocketProperties().getSoLingerTime()); if (getLog().isDebugEnabled()) { getLog().debug("About to unlock socket for:"+saddr); if (getDeferAccept()) { sw.flush(); if (getLog().isDebugEnabled()) { getLog().debug("Socket unlock completed for:"+saddr); if (getLog().isDebugEnabled()) { getLog().debug(sm.getString("endpoint.debug.unlock", "" + getPort()), e);
public void createExecutor() { internalExecutor = true; TaskQueue taskqueue = new TaskQueue(); TaskThreadFactory tf = new TaskThreadFactory(getName() + "-exec-", daemon, getThreadPriority()); executor = new ThreadPoolExecutor(getMinSpareThreads(), getMaxThreads(), 60, TimeUnit.SECONDS,taskqueue, tf); taskqueue.setParent( (ThreadPoolExecutor) executor); }
InetSocketAddress localAddress = null; try { localAddress = getLocalAddress(); } catch (IOException ioe) { getLog().debug(sm.getString("endpoint.debug.unlock.localFail", getName()), ioe); getLog().warn(sm.getString("endpoint.debug.unlock.localNone", getName())); return; unlockAddress = getUnlockAddress(localAddress); int stmo = 2 * 1000; int utmo = 2 * 1000; if (getSocketProperties().getSoTimeout() > stmo) stmo = getSocketProperties().getSoTimeout(); if (getSocketProperties().getUnlockTimeout() > utmo) utmo = getSocketProperties().getUnlockTimeout(); s.setSoTimeout(stmo); s.setSoLinger(getSocketProperties().getSoLingerOn(),getSocketProperties().getSoLingerTime()); if (getLog().isDebugEnabled()) { getLog().debug("About to unlock socket for:" + unlockAddress); if (getDeferAccept()) { if (getLog().isDebugEnabled()) { getLog().debug("Socket unlock completed for:" + unlockAddress); if (getLog().isDebugEnabled()) { getLog().debug(sm.getString("endpoint.debug.unlock.fail", "" + getPort()), t);
String configured = (String) endpoint.getAttribute("proxyPort"); int localPort = 0; if (configured != null) { localPort = Integer.parseInt(configured); } else { localPort = endpoint.getPort(); InetAddress localAddress = endpoint.getAddress(); String localIp = localAddress == null ? null : localAddress .getHostAddress(); if (localIp == null) { localIp = (String) endpoint.getAttribute("proxyIP"); InetAddress localAddress = endpoint.getAddress(); String localH = localAddress == null ? null : localAddress .getCanonicalHostName(); if (localH == null) { localH = (String) endpoint.getAttribute("proxyName");
@Override protected boolean handleIncompleteRequestLineRead() { // Haven't finished reading the request so keep the socket // open openSocket = true; // Check to see if we have read any of the request line yet if (inputBuffer.getParsingRequestLinePhase() < 2) { if (socket.getLastAccess() > -1 || keptAlive) { // Haven't read the request line and have previously processed a // request. Must be keep-alive. Make sure poller uses keepAlive. socket.setTimeout(endpoint.getKeepAliveTimeout()); } } else { // Started to read request line. Need to keep processor // associated with socket readComplete = false; // Make sure poller uses soTimeout from here onwards socket.setTimeout(endpoint.getSoTimeout()); } if (endpoint.isPaused()) { // 503 - Service unavailable response.setStatus(503); adapter.log(request, response, 0); error = true; } else { return true; } return false; }
request.setServerPort(endpoint.getPort()); return; if (!endpoint.isSSLEnabled()) {
public void shutdownExecutor() { if ( executor!=null && internalExecutor ) { if ( executor instanceof ThreadPoolExecutor ) { //this is our internal one, so we need to shut it down ThreadPoolExecutor tpe = (ThreadPoolExecutor) executor; tpe.shutdownNow(); long timeout = getExecutorTerminationTimeoutMillis(); if (timeout > 0) { try { tpe.awaitTermination(timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { // Ignore } if (tpe.isTerminating()) { getLog().warn(sm.getString("endpoint.warn.executorShutdown", getName())); } } TaskQueue queue = (TaskQueue) tpe.getQueue(); queue.setParent(null); } executor = null; } }
public final void init() throws Exception { if (bindOnInit) { bind(); bindState = BindState.BOUND_ON_INIT; } if (this.domain != null) { // Register endpoint (as ThreadPool - historical name) oname = new ObjectName(domain + ":type=ThreadPool,name=\"" + getName() + "\""); Registry.getRegistry(null, null).registerComponent(this, oname, null); for (SSLHostConfig sslHostConfig : findSslHostConfigs()) { registerJmx(sslHostConfig); } } }
/** * Transfers processing to a container thread. * * @param runnable The actions to process on a container thread * * @throws RejectedExecutionException If the runnable cannot be executed */ public void execute(Runnable runnable) { Executor executor = endpoint.getExecutor(); if (!endpoint.isRunning() || executor == null) { throw new RejectedExecutionException(); } executor.execute(runnable); }
/** * Close the server socket (to prevent further connections) if the server * socket was originally bound on {@link #start()} (rather than on * {@link #init()}). * * @see #getBindOnInit() */ public final void closeServerSocketGraceful() { if (bindState == BindState.BOUND_ON_START) { bindState = BindState.SOCKET_CLOSED_ON_STOP; try { doCloseServerSocket(); } catch (IOException ioe) { getLog().warn(sm.getString("endpoint.serverSocket.closeFailed", getName()), ioe); } } }
sc = createSocketProcessor(socketWrapper, event); } else { sc.reset(socketWrapper, event); Executor executor = getExecutor(); if (dispatch && executor != null) { executor.execute(sc); getLog().warn(sm.getString("endpoint.executor.fail", socketWrapper) , ree); return false; } catch (Throwable t) { getLog().error(sm.getString("endpoint.process.fail"), t); return false;
public int getPort() { return endpoint.getPort(); } public void setPort(int port) {
/** * Expected to be used by the handler once the processor is no longer * required. * * @param socket * @param processor * @param isSocketClosing Not used in HTTP * @param addToPoller */ @Override public void release(SocketWrapper<Long> socket, Processor<Long> processor, boolean isSocketClosing, boolean addToPoller) { processor.recycle(isSocketClosing); recycledProcessors.push(processor); if (addToPoller && proto.endpoint.isRunning()) { ((AprEndpoint)proto.endpoint).getPoller().add( socket.getSocket().longValue(), proto.endpoint.getKeepAliveTimeout(), true, false); } }
/** * Pause the endpoint, which will stop it accepting new connections. */ public void pause() { if (running && !paused) { paused = true; unlockAccept(); } }