package serverP2P;
import tools.Logger;
import tools.LogLevel;
import protocolP2P.ProtocolP2PPacket;
import protocolP2P.ProtocolP2PPacketTCP;
import protocolP2P.Payload;
import tools.HostItem;
import serverP2P.RatioWatcher;

/** Class allowing to keep the tracker informed about file list (TCP impl.)
 * @author	Louis Royer
 * @author	Flavien Haas
 * @author	JS Auge
 * @version	1.0
 */
public class RatioWatcherTCP extends RatioWatcher {

	/** Constructor
	 * @param logger	Logger
	 * @param millis	Time interval before recheck
	 * @param tracker	HostItem for the tracker
	 */
	public RatioWatcherTCP(Logger logger, long millis, HostItem tracker) {
		super(logger, millis, tracker);
		assert logger != null : "Logger is null";
		assert tracker != null : "Tracker is null";
	}

	/** Implementation of writeLog
	 * @param text	Text to log
	 * @param logLevel	level of logging
	 */
	protected void writeLog(String text, LogLevel logLevel) {
		logger.writeTCP(text, logLevel);
	}

	/** Implementation of writeLog
	 * @param e	exception to log
	 * @param logLevel	level of logging
	 */
	protected void writeLog(Exception e, LogLevel logLevel) {
		logger.writeTCP(e, logLevel);
	}

	/** Create packets
	 * @param payload	Payload
	 */
	protected < T extends Payload > ProtocolP2PPacket<T> createProtocolP2PPacket(T payload) {
		return (ProtocolP2PPacket<T>)new ProtocolP2PPacketTCP<T>(payload);
	}

	/** Tracker socket getter
	 * @return tracker socket
	 */
	protected Object getTrackerSocket() {
		return tracker.getTCPSocket();
	}

	/** Closes tracker socket
	 */
	protected void closeTrackerSocket() {
		tracker.closeTCPSocket();
	}


}
