package org.kne.cloud.network.klalb;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicLong;

import org.kne.cloud.network.FilterSocket;

public class MonitoredSocket extends FilterSocket {
	public Monitor getMonitor() {
		return monitor;
	}



	private Monitor monitor;
	
	@Override
	public synchronized void close() throws IOException {
		super.close();
	}
	public MonitoredSocket(Socket socket) {
		this(socket,new Monitor());
	}
	public MonitoredSocket(Socket socket,Monitor monitor) {
		super(socket);
	this.monitor=monitor;
	}
	
	

	
	private InputStream in;
	private OutputStream out;
	@Override
	public InputStream getInputStream() throws IOException {
		if(in==null)
			in=new MonitoredInputStream(socket.getInputStream(), monitor.getInTrafficAL());
		return in;
	}

	@Override
	public OutputStream getOutputStream() throws IOException {
		if(out==null) {
			out=new MonitoredOutputStream(socket.getOutputStream(), monitor.getOutTrafficAL());
		}
		return out;
	}

}
