// Path: src/main/java/org/javastack/bouncer/GenericPool.java
// public static interface GenericPoolFactory<T> {
// 	public T newInstance();
// }
// 
// Path: src/main/java/org/javastack/bouncer/TaskManager.java
// abstract static class AuditableRunner implements Runnable {
// 	Thread thread;
// 
// 	void setThread(final Thread thread) {
// 		this.thread = thread;
// 	}
// 
// 	Thread getThread() {
// 		return thread;
// 	}
// 
// 	long getClientId() {
// 		return ClientId.getId();
// 	}
// 
// 	void setClientId(final long clientId) {
// 		ClientId.setId(clientId);
// 	}
// 
// 	void destroyClientId() {
// 		ClientId.destroy();
// 	}
// }
// 
// Path: src/main/java/org/javastack/bouncer/jmx/BouncerStatistics.java
// public class BouncerStatistics extends Statistics implements BouncerStatisticsMBean {
// 	public static final String MY_NAME = BouncerStatistics.class.getPackage().getName() + ":type="
// 			+ BouncerStatistics.class.getSimpleName();
// 
// 	public void init() throws JMException {
// 		final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
// 		mbs.registerMBean(new AnnotatedStandardMBean(this, BouncerStatisticsMBean.class), new ObjectName(
// 				MY_NAME));
// 	}
// 
// 	public void destroy() throws JMException {
// 		final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
// 		mbs.unregisterMBean(new ObjectName(MY_NAME));
// 	}
// }


import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.nio.charset.Charset;
import java.security.GeneralSecurityException;
import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import java.security.Security;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.TimeUnit;
import javax.management.JMException;
import org.javastack.bouncer.GenericPool.GenericPoolFactory;
import org.javastack.bouncer.TaskManager.AuditableRunner;
import org.javastack.bouncer.jmx.BouncerStatistics;
/*
 *  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.javastack.bouncer;




/**
 * Simple TCP Bouncer
 * 
 * @author Guillermo Grandes / guillermo.grandes[at]gmail.com
 */
public class Bouncer implements ServerContext {
	private static final Timer timer = new Timer("scheduled-task", true);
// Path: src/main/java/org/javastack/bouncer/GenericPool.java
// public static interface GenericPoolFactory<T> {
// 	public T newInstance();
// }
// 
// Path: src/main/java/org/javastack/bouncer/TaskManager.java
// abstract static class AuditableRunner implements Runnable {
// 	Thread thread;
// 
// 	void setThread(final Thread thread) {
// 		this.thread = thread;
// 	}
// 
// 	Thread getThread() {
// 		return thread;
// 	}
// 
// 	long getClientId() {
// 		return ClientId.getId();
// 	}
// 
// 	void setClientId(final long clientId) {
// 		ClientId.setId(clientId);
// 	}
// 
// 	void destroyClientId() {
// 		ClientId.destroy();
// 	}
// }
// 
// Path: src/main/java/org/javastack/bouncer/jmx/BouncerStatistics.java
// public class BouncerStatistics extends Statistics implements BouncerStatisticsMBean {
// 	public static final String MY_NAME = BouncerStatistics.class.getPackage().getName() + ":type="
// 			+ BouncerStatistics.class.getSimpleName();
// 
// 	public void init() throws JMException {
// 		final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
// 		mbs.registerMBean(new AnnotatedStandardMBean(this, BouncerStatisticsMBean.class), new ObjectName(
// 				MY_NAME));
// 	}
// 
// 	public void destroy() throws JMException {
// 		final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
// 		mbs.unregisterMBean(new ObjectName(MY_NAME));
// 	}
// }


// Path: src/main/java/org/javastack/bouncer/Bouncer.java
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.nio.charset.Charset;
import java.security.GeneralSecurityException;
import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import java.security.Security;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.TimeUnit;
import javax.management.JMException;
import org.javastack.bouncer.GenericPool.GenericPoolFactory;
import org.javastack.bouncer.TaskManager.AuditableRunner;
import org.javastack.bouncer.jmx.BouncerStatistics;

/*
 *  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.javastack.bouncer;




/**
 * Simple TCP Bouncer
 * 
 * @author Guillermo Grandes / guillermo.grandes[at]gmail.com
 */
public class Bouncer implements ServerContext {
	private static final Timer timer = new Timer("scheduled-task", true);
	private static final GenericPoolFactory<ByteArrayOutputStream> byteArrayOutputStreamFactory = new GenericPoolFactory<ByteArrayOutputStream>() {