package org.kne.cloud.network.klalb;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.channels.ServerSocketChannel;

import javax.net.ServerSocketFactory;

import org.kne.cloud.network.ServerSocketChannelFactory;

public class KLALBVirtualServerSocketChannelFactory extends ServerSocketChannelFactory {

	private KLALBController controller;
	
	public KLALBVirtualServerSocketChannelFactory(KLALBController controller) {
		super();
		this.controller = controller;
	}

	public KLALBController getController() {
		return controller;
	}
	@Override
	public ServerSocketChannel createServerSocketChannel() throws IOException {
		return  KLALBVirtualServerSocketChannel.open(controller);
	}

	@Override
	public ServerSocketChannel createServerSocketChannel(int port) throws IOException {
		ServerSocketChannel ksc=createServerSocketChannel();
		ksc.bind(new InetSocketAddress(port));
		return ksc;
	}

	@Override
	public ServerSocketChannel createServerSocketChannel(int port, int backlog) throws IOException {
		ServerSocketChannel ksc=createServerSocketChannel();
		ksc.bind(new InetSocketAddress(port),backlog);
		return ksc;
	}

	@Override
	public ServerSocketChannel createServerSocketChannel(int port, int backlog, InetAddress ifAddress) throws IOException {
		ServerSocketChannel ksc=createServerSocketChannel();
		ksc.bind(new InetSocketAddress(ifAddress,port),backlog);
		return ksc;
	}

}
