package com.dokukino.genkidama;

import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;
import java.util.TimerTask;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.xmlrpc.XmlRpcException;

public class OnlineUserUpdateTask extends TimerTask {
	public static Log logger = LogFactory.getLog(OnlineUserUpdateTask.class);
	public static final long TASK_PERIOD = 1 * 60 * 1000;
	
	@SuppressWarnings("unchecked")
	@Override
	public void run() {
		int ringPort = GenkidamaManager.getInstance().getRingPort();
		List params = new ArrayList();
		params.add(ringPort);
		params.add(VersionInfo.APPLICATION_MINOR_VERSION);
		while(true) {
			try {
					XmlRpcInvoker.invoke("onlineUsers.update", params);
					break;
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				logger.error(e);
			} catch (XmlRpcException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				logger.error(e);
			}
		}
	}
}
