package org.kne.cloud.network.klalb;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.channels.SocketChannel;

import javax.net.SocketFactory;

import org.kne.cloud.network.SocketChannelFactory;

public class KLALBVirtualSocketChannelFactory extends SocketChannelFactory {
private KLALBController controller;
	
	public KLALBVirtualSocketChannelFactory(KLALBController controller) {
		super();
		this.controller = controller;
	}
	@Override
	public SocketChannel createSocketChannel() throws IOException {
		return KLALBVirtualSocketChannel.open(controller);
	}
	@Override
	public SocketChannel createSocketChannel(String arg0, int arg1) throws IOException, UnknownHostException {
		SocketChannel sc=createSocketChannel();
		sc.connect(new InetSocketAddress(arg0,arg1));
		return sc;
	}

	@Override
	public SocketChannel createSocketChannel(InetAddress arg0, int arg1) throws IOException {
		SocketChannel sc=createSocketChannel();
		sc.connect(new InetSocketAddress(arg0,arg1));
		return sc;
	}

	@Override
	public SocketChannel createSocketChannel(String arg0, int arg1, InetAddress arg2, int arg3)
			throws IOException, UnknownHostException {
		SocketChannel sc=createSocketChannel();
		sc.bind(new InetSocketAddress(arg2, arg3));
		sc.connect(new InetSocketAddress(arg0,arg1));
		return sc;
	}

	@Override
	public SocketChannel createSocketChannel(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException {
		SocketChannel sc=createSocketChannel();
		sc.bind(new InetSocketAddress(arg2, arg3));
		sc.connect(new InetSocketAddress(arg0,arg1));
		return sc;
	}

}
