package org.bench4q.monitor.file.Linux;

import java.io.FileNotFoundException;
import java.io.PrintWriter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

import org.bench4q.monitor.model.NetworkInterfaceModel;
import org.bench4q.monitor.performance.linux.NetworkInterfaceMonitor;
import org.bench4q.monitor.files.Write;

public class WriteNetworkInterfaceLinux extends Write {
	private NetworkInterfaceMonitor networkInterfaceMonitor;

	public WriteNetworkInterfaceLinux(PrintWriter out, int idleTime)
			throws FileNotFoundException {
		this.out = out;
		this.networkInterfaceMonitor = new NetworkInterfaceMonitor();
		this.idleTime = idleTime;
	}

	public void run() {
		try {
			JAXBContext context = JAXBContext
					.newInstance(NetworkInterfaceModel.class);
			Marshaller marshaller = context.createMarshaller();
			NetworkInterfaceModel networkInterfaceModel = networkInterfaceMonitor
					.getNetworkInterfaceInfo(idleTime);
			marshaller.marshal(networkInterfaceModel, out);
		} catch (Exception e) {
			System.out.println(e);
		}

	}

}
