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;
 
 import  java.nio.channels.AsynchronousChannelGroup;
 import  java.nio.channels.AsynchronousServerSocketChannel;
 
NioServerSocketChannelFactory Created on Jan 3, 2012 at 12:08:30 PM

Author(s):
Nabil Benothman
 
 public abstract class NioServerSocketChannelFactory implements Cloneable {
 
 	protected Hashtable<StringObjectattributes = new Hashtable<StringObject>();
 
 	protected AsynchronousChannelGroup threadGroup;
 	protected boolean internalExecutor = true;

Create a new instance of NioServerSocketChannelFactory
 
 		/* NOTHING */
 	}

Create a new instance of NioServerSocketChannelFactory

Parameters:
threadGroup
 
 	protected NioServerSocketChannelFactory(AsynchronousChannelGroup threadGroup) {
 		this. = threadGroup;
 	}

Initialize the factory

Throws:
IOException
 
 	public abstract void init() throws IOException;

Destroy the factory

Throws:
IOException
 
 	public abstract void destroy() throws IOException;

General mechanism to pass attributes from the ServerConnector to the socket factory. Note that the "preferred" mechanism is to use bean setters and explicit methods, but this allows easy configuration via server.xml or simple Properties

Parameters:
name
value
 
 	public void setAttribute(String nameObject value) {
 		if (name != null && value != null) {
 			.put(namevalue);
 		}
 	}

Returns a copy of the environment's default socket factory.

Returns:
the default factory
 
 	public static synchronized NioServerSocketChannelFactory getDefault() {
 		return getDefault(null);
 	}

Returns a copy of the environment's default socket factory.

Parameters:
threadGroup
Returns:
the default factory
	public static synchronized NioServerSocketChannelFactory getDefault(
			AsynchronousChannelGroup threadGroup) {
		//
		// optimize typical case: no synch needed
		//
		if ( == null) {
			//
			// Different implementations of this method could
			// work rather differently. For example, driving
			// this from a system property, or using a different
			// implementation than JavaSoft's.
			//
else {
                        if (. != threadGroup)
                                 = new DefaultNioServerSocketChannelFactory(threadGroup);
                }
		try {
			throw new RuntimeException(e.getMessage());
		}
	}

Create and configure a new secure NioServerSocketChannelFactory instance

Parameters:
threadGroup the thread group that will be used with the server sockets
Returns:
a new secure NioServerSocketChannelFactory instance
	public static synchronized NioServerSocketChannelFactory createSecureFactory(
			AsynchronousChannelGroup threadGroup) {
		return new NioJSSESocketChannelFactory(threadGroup);
	}

Create a new NioServerSocketChannelFactory instance

Parameters:
threadGroup the thread group that will be used with the server sockets
secure
Returns:
a new secure NioServerSocketChannelFactory instance
			AsynchronousChannelGroup threadGroupboolean secure) {
		return secure ? createSecureFactory(threadGroup) : getDefault(threadGroup);
	}

Returns a server socket channel which uses all network interfaces on the host, and is bound to a the specified port. The socket is configured with the socket options (such as accept timeout) given to this factory.

Parameters:
port the port to listen to
Returns:
an instance of java.nio.channels.AsynchronousServerSocketChannel
Throws:
IOException for networking errors
	public AsynchronousServerSocketChannel createServerChannel(int portthrows IOException {
		return createServerChannel(port, -1);
	}

Returns a server socket which uses all network interfaces on the host, is bound to a the specified port, and uses the specified connection backlog. The socket is configured with the socket options (such as accept timeout) given to this factory.

Parameters:
port the port to listen to
backlog how many connections are queued
Returns:
an instance of java.nio.channels.AsynchronousServerSocketChannel
Throws:
IOException for networking errors
	public AsynchronousServerSocketChannel createServerChannel(int portint backlog)
			throws IOException {
		return createServerChannel(portbacklognullfalsetrue);
	}

Returns a server socket channel which uses only the specified network interface on the local host, is bound to a the specified port, and uses the specified connection backlog. The socket is configured with the socket options (such as accept timeout) given to this factory.

Parameters:
port the port to listen to
backlog how many connections are queued
ifAddress the network interface address to use
reuseAddress
Returns:
an instance of java.nio.channels.AsynchronousServerSocketChannel
Throws:
IOException for networking errors
	public abstract AsynchronousServerSocketChannel createServerChannel(int portint backlog,
			InetAddress ifAddressboolean reuseAddressboolean internalExecutorthrows IOException;

Initialize the specified NioChannel

Parameters:
channel The channel to be initialized
Throws:
Exception
	public abstract void initChannel(NioChannel channelthrows Exception;

Wrapper function for accept(). This allows us to trap and translate exceptions if necessary

Parameters:
listener The Asynchronous Server Socket channel that will accept a new connection
Returns:
an instance of NioChannel representing the new connection
Throws:
IOException
	public abstract NioChannel acceptChannel(AsynchronousServerSocketChannel listener)
			throws IOException;

Extra function to initiate the handshake. Sometimes necessary for SSL

Parameters:
channel
Throws:
IOException
	public abstract void handshake(NioChannel channelthrows IOException;

Open an java.nio.channels.AsynchronousServerSocketChannel

Returns:
an instance of java.nio.channels.AsynchronousServerSocketChannel
Throws:
IOException
	protected AsynchronousServerSocketChannel open() throws IOException {
		return AsynchronousServerSocketChannel.open();
	}
New to GrepCode? Check out our FAQ X