package com.mjlogin;

import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


import com.mjlogin.service.AccountService;
import com.mjlogin.service.IndexService;
import com.mjlogin.service.MilitaryService;
import com.mjlogin.service.RoomService;
import com.taurus.core.plugin.redis.Redis;
import com.taurus.core.routes.Extension;
import com.taurus.core.routes.Routes;
import com.taurus.core.util.StringUtil;

public class MainServer extends Extension {
	public static int		DEFAULT_DAIMO		= 5;
	public static String  	GROUP_WEB_URL = "";
	private ScheduledThreadPoolExecutor timeScheduler;
	
	private static final String WEB_CONFIG_KEY = "web_config";
	private static final String FORCE_VER_KEY = "force_ver";
	public MainServer() {
		super();
		String str = Redis.use("group1_db1").hget(WEB_CONFIG_KEY,"default_daimo");
		if (StringUtil.isNotEmpty(str)) {
			DEFAULT_DAIMO = Integer.parseInt(Redis.use("group1_db1").hget(WEB_CONFIG_KEY,"default_daimo"));
		}
		GROUP_WEB_URL = Redis.use("group1_db1").hget("web_requrl", "groupWeb");
		
		timeScheduler = new ScheduledThreadPoolExecutor(1);
		timeScheduler.scheduleAtFixedRate(new Runnable() {

			@Override
			public void run() {
				System.gc();
			}
		}, 0,600, TimeUnit.SECONDS);
		
	}

	
	@Override
	public int readVersion() {
		int ver = Integer.parseInt(Redis.use("group1_db1").hget(WEB_CONFIG_KEY,FORCE_VER_KEY));
		return ver;
	}
	
	@Override
	public void configRoute(Routes me) {
		me.setInterceptor(new WebInterceptor());
		me.add("acc", AccountService.class);
		me.add("index", IndexService.class);
		me.add("military", MilitaryService.class);
		me.add("room", RoomService.class);
	}

	@Override
	public void onStart() {


	}

	@Override
	public void onStop() {
		// TODO Auto-generated method stub
		if(timeScheduler!=null) {
			timeScheduler.shutdownNow();
		}

	}

}
