Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * JBoss, Home of Professional Open Source.
    * Copyright 2012 Red Hat, Inc., and individual contributors
    * as indicated by the @author tags.
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.tomcat.util.net;
  
AbstractEndpoint Created on Dec 14, 2011 at 2:58:58 PM

Author(s):
Nabil Benothman
  
  public abstract class AbstractEndpoint {

The default socket timeout = 60 sec
  
  	protected static final int DEFAULT_SO_TIMEOUT = 60 * 1000;

Running state of the endpoint.
  
  	protected volatile boolean running = false;

Will be set to true whenever the endpoint is paused.
  
  	protected volatile boolean paused = false;

Track the initialization state of the endpoint.
  
  	protected boolean initialized = false;

The number of open connections
  
  	protected AtomicInteger counter = new AtomicInteger();

  
  	protected boolean reuseAddress = .;

Current worker threads busy count.
  
  	protected int curThreadsBusy = 0;

Current worker threads count.
  
  	protected int curThreads = 0;

Sequence number used to generate thread names.
  
  	protected int sequence = 0;

Acceptor thread count.
  
  	protected int acceptorThreadCount = 0;

External Executor based thread pool.
  
  	protected Executor executor = null;
Maximum amount of worker threads.
  
  	protected int maxThreads = (.....) ? 32 : ((. == -1) ? 32 * Runtime.getRuntime().availableProcessors() : .);

The maximum number of connections
  
  	protected int maxConnections = (.....) ? 1024 : (32 * 1024);

Priority of the acceptor and poller threads.
 
 	protected int threadPriority = .;

Size of the sendfile (= concurrent files which can be served).
 
 	protected int sendfileSize = (.....) ? 128 : (16 * 1024);

Server socket port.
 
 	protected int port;

Address for the server socket.
 
 	protected InetAddress address;

The default thread factory
 
Allows the server developer to specify the backlog that should be used for server sockets. By default, this value is 100.
 
 	// protected int backlog = 100;
 	protected int backlog = 511;

Socket TCP no delay.
 
 	protected boolean tcpNoDelay = false;

Socket linger.
 
 	protected int soLinger = 100;
Socket timeout.
 
 	protected int soTimeout = -1;
Defer accept.
 
 	protected boolean deferAccept = true;

Keep-Alive timeout.
 
 	protected int keepAliveTimeout = -1;

    
Receive buffer.
 
     protected int soReceiveBuffer = .;
     public int getSoReceiveBuffer() { return ; }
     public void setSoReceiveBuffer(int soReceiveBuffer) { this. = soReceiveBuffer; }

    
Send buffer.
 
     protected int soSendBuffer = .;
     public int getSoSendBuffer() { return ; }
     public void setSoSendBuffer(int soSendBuffer) { this. = soSendBuffer; }

The default is true - the created threads will be in daemon mode. If set to false, the control thread will not be daemon - and will keep the process alive.
 
 	protected boolean daemon = true;
Name of the thread pool, which will be used for naming child threads.
 
 	protected String name = "TP";
Use sendfile for sending static files.
 
 	protected boolean useSendfile = true;

Reverse connection. In this proxied mode, the endpoint will not use a server socket, but will connect itself to the front end server.
 
 	protected boolean reverseConnection = false;
SSL engine.
 
 	protected boolean SSLEnabled = false;

SSL protocols.
 
 	protected String SSLProtocol = "all";

SSL password (if a cert is encrypted, and no password has been provided, a callback will ask for a password).
 
 	protected String SSLPassword = null;

SSL cipher suite.
 
 	protected String SSLCipherSuite = "ALL";
SSL certificate file.
 
 	protected String SSLCertificateFile = null;
SSL certificate chain file.
 
 	protected String SSLCertificateChainFile = null;

SSL CA certificate path.
 
 	protected String SSLCACertificatePath = null;

SSL CA certificate file.
 
 	protected String SSLCACertificateFile = null;
SSL CA revocation path.
 
 	protected String SSLCARevocationPath = null;
SSL CA revocation file.
 
 	protected String SSLCARevocationFile = null;
SSL verify client.
 
 	protected String SSLVerifyClient = "none";
SSL verify depth.
 
 	protected int SSLVerifyDepth = 10;
SSL allow insecure renegotiation for the the client that does not support the secure renegotiation.
 
 	protected boolean SSLInsecureRenegotiation = false;
SSL certificate key file.
 
 	protected String SSLCertificateKeyFile = null;

Initialize the endpoint

 
 	public abstract void init() throws Exception;

Start the endpoint, creating acceptor, poller and sendfile threads, etc.

 
 	public abstract void start() throws Exception;

Pause the endpoint, which will make it stop accepting new sockets.
 
 	public void pause() {
 		if ( && !) {
 			 = true;
 		}
 	}

Resume the endpoint, which will make it start accepting new connections again.
 
 	public void resume() {
 		if () {
 			 = false;
 		}
 	}

Stop the endpoint. This will cause all processing threads to stop.
 
 	public abstract void stop();

Deallocate the memory pools, and close server socket.

 
 	public abstract void destroy() throws Exception;

Unlock the server socket accept using a bogus connection.
 
 	protected void unlockAccept() {
 		java.net.Socket s = null;
         InetSocketAddress saddr = null;
 		try {
             // Need to create a connection to unlock the accept();
             if ( == null) {
                 saddr = new InetSocketAddress("localhost");
             } else {
                 saddr = new InetSocketAddress();
             }
             s = new java.net.Socket();
             s.setSoLinger(true, 0);
             s.connect(saddr, 2000);
 			// If deferAccept is enabled, send at least one byte
 			if () {
 			}
 		} catch (Exception e) {
 			// Ignore
 		} finally {
 			if (s != null) {
 				try {
 					s.close();
 				} catch (Exception e) {
 					// Ignore
 				}
 			}
 		}
 	}

Create a new thread for the specified target

Parameters:
target
name
daemon
Returns:
an instance of a new thread
 
 	protected Thread newThread(Runnable targetString nameboolean daemon) {
 		Thread thread = this. != null ? this..newThread(target)
 				: new Thread(target);
 
 		thread.setName(getName() +"-" + name);
 		thread.setDaemon(daemon);
 
 		return thread;
 	}
 
 	// --------------------------------------------
 	
Getter for running

Returns:
the running
 
 	public boolean isRunning() {
 		return this.;
 	}

Setter for the running

Parameters:
running the running to set
 
 	public void setRunning(boolean running) {
 		this. = running;
 	}

Getter for paused

Returns:
the paused
 
 	public boolean isPaused() {
 		return this.;
 	}

Setter for the paused

Parameters:
paused the paused to set
 
 	public void setPaused(boolean paused) {
 		this. = paused;
 	}

Getter for initialized

Returns:
the initialized
 
 	public boolean isInitialized() {
 		return this.;
 	}

Setter for the initialized

Parameters:
initialized the initialized to set
 
 	public void setInitialized(boolean initialized) {
 		this. = initialized;
 	}

Getter for curThreadsBusy

Returns:
the curThreadsBusy
 
 	public int getCurThreadsBusy() {
 		return this.;
 	}

Setter for the curThreadsBusy

Parameters:
curThreadsBusy the curThreadsBusy to set
 
 	public void setCurThreadsBusy(int curThreadsBusy) {
 		this. = curThreadsBusy;
 	}

Getter for curThreads

Returns:
the curThreads
 
 	public int getCurThreads() {
 		return this.;
 	}

Setter for the curThreads

Parameters:
curThreads the curThreads to set
 
 	public void setCurThreads(int curThreads) {
 		this. = curThreads;
 	}

Getter for sequence

Returns:
the sequence
 
 	public int getSequence() {
 		return this.++;
 	}

Setter for the sequence

Parameters:
sequence the sequence to set
 
 	public void setSequence(int sequence) {
 		this. = sequence;
 	}

Getter for executor

Returns:
the executor
 
 	public Executor getExecutor() {
 		return this.;
 	}

Setter for the executor

Parameters:
executor the executor to set
 
 	public void setExecutor(Executor executor) {
 		this. = executor;
 	}

Getter for maxThreads

Returns:
the maxThreads
 
 	public int getMaxThreads() {
 		return this.;
 	}

Setter for the maxThreads

Parameters:
maxThreads the maxThreads to set
 
 	public void setMaxThreads(int maxThreads) {
 		this. = maxThreads;
 	}

Getter for maxConnections

Returns:
the maxConnections
 
 	public int getMaxConnections() {
 		return this.;
 	}

Setter for the maxConnections

Parameters:
maxConnections the maxConnections to set
 
 	public void setMaxConnections(int maxConnections) {
 		this. = maxConnections;
 	}

Getter for threadPriority

Returns:
the threadPriority
 
 	public int getThreadPriority() {
 		return this.;
 	}

Setter for the threadPriority

Parameters:
threadPriority the threadPriority to set
 
 	public void setThreadPriority(int threadPriority) {
 		this. = threadPriority;
 	}

Getter for sendfileSize

Returns:
the sendfileSize
 
 	public int getSendfileSize() {
 		return this.;
 	}

Setter for the sendfileSize

Parameters:
sendfileSize the sendfileSize to set
 
 	public void setSendfileSize(int sendfileSize) {
 		this. = sendfileSize;
 	}

Getter for port

Returns:
the port
 
 	public int getPort() {
 		return this.;
 	}

Setter for the port

Parameters:
port the port to set
 
 	public void setPort(int port) {
 		this. = port;
 	}

Getter for address

Returns:
the address
 
 	public InetAddress getAddress() {
 		return this.;
 	}

Setter for the address

Parameters:
address the address to set
 
 	public void setAddress(InetAddress address) {
 		this. = address;
 	}

Getter for backlog

Returns:
the backlog
 
 	public int getBacklog() {
 		return this.;
 	}

Setter for the backlog

Parameters:
backlog the backlog to set
 
 	public void setBacklog(int backlog) {
 		if (backlog > 0)
 			this. = backlog;
 	}

Getter for tcpNoDelay

Returns:
the tcpNoDelay
 
 	public boolean getTcpNoDelay() {
 		return this.;
 	}

Setter for the tcpNoDelay

Parameters:
tcpNoDelay the tcpNoDelay to set
 
 	public void setTcpNoDelay(boolean tcpNoDelay) {
 		this. = tcpNoDelay;
 	}

Getter for soLinger

Returns:
the soLinger
 
 	public int getSoLinger() {
 		return this.;
 	}

Setter for the soLinger

Parameters:
soLinger the soLinger to set
 
 	public void setSoLinger(int soLinger) {
 		this. = soLinger;
 	}

Getter for soTimeout

Returns:
the soTimeout
 
 	public int getSoTimeout() {
 		return this.;
 	}

Setter for the soTimeout

Parameters:
soTimeout the soTimeout to set
 
 	public void setSoTimeout(int soTimeout) {
 		this. = soTimeout;
 	}

Getter for deferAccept

Returns:
the deferAccept
 
 	public boolean getDeferAccept() {
 		return this.;
 	}

Setter for the deferAccept

Parameters:
deferAccept the deferAccept to set
 
 	public void setDeferAccept(boolean deferAccept) {
 		this. = deferAccept;
 	}

Getter for keepAliveTimeout

Returns:
the keepAliveTimeout
 
 	public int getKeepAliveTimeout() {
 		return this.;
 	}

Setter for the keepAliveTimeout

Parameters:
keepAliveTimeout the keepAliveTimeout to set
 
 	public void setKeepAliveTimeout(int keepAliveTimeout) {
 		this. = keepAliveTimeout;
 	}

Getter for daemon

Returns:
the daemon
 
 	public boolean getDaemon() {
 		return this.;
 	}

Setter for the daemon

Parameters:
daemon the daemon to set
 
 	public void setDaemon(boolean daemon) {
 		this. = daemon;
 	}

Getter for name

Returns:
the name
 
 	public String getName() {
 		return this.;
 	}

Setter for the name

Parameters:
name the name to set
 
 	public void setName(String name) {
 		this. = name;
 	}

Getter for useSendfile

Returns:
the useSendfile
 
 	public boolean getUseSendfile() {
 		return this.;
 	}

Setter for the useSendfile

Parameters:
useSendfile the useSendfile to set
 
 	public void setUseSendfile(boolean useSendfile) {
 		this. = useSendfile;
 	}

Getter for reverseConnection

Returns:
the reverseConnection
 
 	public boolean isReverseConnection() {
 		return this.;
 	}

Setter for the reverseConnection

Parameters:
reverseConnection the reverseConnection to set
 
 	public void setReverseConnection(boolean reverseConnection) {
 		this. = reverseConnection;
 	}

Getter for sSLEnabled

Returns:
the sSLEnabled
 
 	public boolean getSSLEnabled() {
 		return this.;
 	}

Setter for the sSLEnabled

Parameters:
sSLEnabled the sSLEnabled to set
 
 	public void setSSLEnabled(boolean sSLEnabled) {
 		this. = sSLEnabled;
 	}

Getter for sSLProtocol

Returns:
the sSLProtocol
 
 	public String getSSLProtocol() {
 		return this.;
 	}

Setter for the sSLProtocol

Parameters:
sSLProtocol the sSLProtocol to set
 
 	public void setSSLProtocol(String sSLProtocol) {
 		this. = sSLProtocol;
 	}

Getter for sSLPassword

Returns:
the sSLPassword
 
 	public String getSSLPassword() {
 		return this.;
 	}

Setter for the sSLPassword

Parameters:
sSLPassword the sSLPassword to set
 
 	public void setSSLPassword(String sSLPassword) {
 		this. = sSLPassword;
 	}

Getter for sSLCipherSuite

Returns:
the sSLCipherSuite
 
 	public String getSSLCipherSuite() {
 		return this.;
 	}

Setter for the sSLCipherSuite

Parameters:
sSLCipherSuite the sSLCipherSuite to set
 
 	public void setSSLCipherSuite(String sSLCipherSuite) {
 		this. = sSLCipherSuite;
 	}

Getter for sSLCertificateFile

Returns:
the sSLCertificateFile
 
 		return this.;
 	}

Setter for the sSLCertificateFile

Parameters:
sSLCertificateFile the sSLCertificateFile to set
 
 	public void setSSLCertificateFile(String sSLCertificateFile) {
 		this. = sSLCertificateFile;
 	}

Getter for sSLCertificateChainFile

Returns:
the sSLCertificateChainFile
 
 	}

Setter for the sSLCertificateChainFile

Parameters:
sSLCertificateChainFile the sSLCertificateChainFile to set
 
 	public void setSSLCertificateChainFile(String sSLCertificateChainFile) {
 		this. = sSLCertificateChainFile;
 	}

Getter for sSLCACertificatePath

Returns:
the sSLCACertificatePath
 
 		return this.;
 	}

Setter for the sSLCACertificatePath

Parameters:
sSLCACertificatePath the sSLCACertificatePath to set
 
 	public void setSSLCACertificatePath(String sSLCACertificatePath) {
 		this. = sSLCACertificatePath;
 	}

Getter for sSLCACertificateFile

Returns:
the sSLCACertificateFile
 
 		return this.;
 	}

Setter for the sSLCACertificateFile

Parameters:
sSLCACertificateFile the sSLCACertificateFile to set
 
 	public void setSSLCACertificateFile(String sSLCACertificateFile) {
 		this. = sSLCACertificateFile;
 	}

Getter for sSLCARevocationPath

Returns:
the sSLCARevocationPath
 
 		return this.;
 	}

Setter for the sSLCARevocationPath

Parameters:
sSLCARevocationPath the sSLCARevocationPath to set
 
 	public void setSSLCARevocationPath(String sSLCARevocationPath) {
 		this. = sSLCARevocationPath;
 	}

Getter for sSLCARevocationFile

Returns:
the sSLCARevocationFile
 
 		return this.;
 	}

Setter for the sSLCARevocationFile

Parameters:
sSLCARevocationFile the sSLCARevocationFile to set
 
 	public void setSSLCARevocationFile(String sSLCARevocationFile) {
 		this. = sSLCARevocationFile;
 	}

Getter for sSLVerifyClient

Returns:
the sSLVerifyClient
 
 	public String getSSLVerifyClient() {
 		return this.;
 	}

Setter for the sSLVerifyClient

Parameters:
sSLVerifyClient the sSLVerifyClient to set
 
 	public void setSSLVerifyClient(String sSLVerifyClient) {
 		this. = sSLVerifyClient;
 	}

Getter for sSLVerifyDepth

Returns:
the sSLVerifyDepth
	public int getSSLVerifyDepth() {
		return this.;
	}

Setter for the sSLVerifyDepth

Parameters:
sSLVerifyDepth the sSLVerifyDepth to set
	public void setSSLVerifyDepth(int sSLVerifyDepth) {
		this. = sSLVerifyDepth;
	}

Getter for sSLInsecureRenegotiation

Returns:
the sSLInsecureRenegotiation
	public boolean getSSLInsecureRenegotiation() {
	}

Setter for the sSLInsecureRenegotiation

Parameters:
sSLInsecureRenegotiation the sSLInsecureRenegotiation to set
	public void setSSLInsecureRenegotiation(boolean sSLInsecureRenegotiation) {
		this. = sSLInsecureRenegotiation;
	}

Getter for sSLCertificateKeyFile

Returns:
the sSLCertificateKeyFile
	}

Setter for the sSLCertificateKeyFile

Parameters:
sSLCertificateKeyFile the sSLCertificateKeyFile to set
	public void setSSLCertificateKeyFile(String sSLCertificateKeyFile) {
		this. = sSLCertificateKeyFile;
	}

Getter for reuseAddress

Returns:
the reuseAddress
	public boolean isReuseAddress() {
		return this.;
	}

Setter for the reuseAddress

Parameters:
reuseAddress the reuseAddress to set
	public void setReuseAddress(boolean reuseAddress) {
		this. = reuseAddress;
	}

Getter for acceptorThreadCount

Returns:
the acceptorThreadCount
	public int getAcceptorThreadCount() {
	}

Setter for the acceptorThreadCount

Parameters:
acceptorThreadCount the acceptorThreadCount to set
	public void setAcceptorThreadCount(int acceptorThreadCount) {
		this. = acceptorThreadCount;
New to GrepCode? Check out our FAQ X