package com.saga.main;

import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.List;

import org.apache.hadoop.conf.Configuration;
import org.zillion.util.log.LogUtil;

import com.saga.entity.EntityHbase;
import com.saga.entity.EntityMysql;
import com.saga.thread.common.CheckThread;
import com.saga.thread.common.LoadConfigThread;
import com.saga.thread.common.SaveThread;
import com.saga.thread.common.StatsThread;
import com.saga.thread.common.WTDBThread;
import com.saga.thread.down.DownThread;
import com.saga.thread.up.TransferThread;
import com.saga.thread.up.UpThread;
import com.saga.util.Constant;
import com.zillion.database.agent.ZillionAgent;

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		// 初始化
		init(args);
		// 业务进程启动
		threadStart();
	}

	/**
	 * 启动各业务线程
	 */
	private static void threadStart() {
		// TODO Auto-generated method stub
		// 点位状态监控
		try {
			new CheckThread().start();
			Thread.sleep(3L);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			LogUtil.error("Main.threadStart.CheckThread: " + e.toString());
		}
		// 配置实时加载进程
		try {
			new LoadConfigThread().start();
			Thread.sleep(Constant.Millisecond.SECOND_1);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			LogUtil.error("Main.threadStart.LoadConfigThread: " + e.toString());
		}
		// Down进程
		try {
			new DownThread(Constant.TypeServer.get("Down")).start();
			Thread.sleep(3L);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			LogUtil.error("Main.threadStart.DownThread: " + e.toString());
		}
		// Up进程
		try {
			new UpThread(Constant.TypeServer.get("Up")).start();
			Thread.sleep(3L);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			LogUtil.error("Main.threadStart.UpThread: " + e.toString());
		}
		// Transfer进程
		try {
			new TransferThread().start();
			Thread.sleep(3L);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			LogUtil.error("Main.threadStart.TransferThread: " + e.toString());
		}

		// 数据处理进程
		try {
			new SaveThread().start();
			Thread.sleep(3L);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			LogUtil.error("Main.threadStart.SaveThread: " + e.toString());
		}
		// 数据写库进程
		try {
			List<WTDBThread> wtdbthreadList = new ArrayList<WTDBThread>();
			for (int i = 0; i < Constant.InsertThread; i++) {
				WTDBThread thread = new WTDBThread();
				thread.start();
				wtdbthreadList.add(thread);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			LogUtil.error("Main.threadStart.WTDBThread: " + e.toString());
		}

		// 统计进程
		try {
			new StatsThread().start();
			Thread.sleep(3L);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			LogUtil.error("Main.threadStart.StatsThread: " + e.toString());
		}
	}

	/**
	 * 初始化
	 */
	private static void init(String[] args) {
		// TODO Auto-generated method stub
		try {
			// loadExcelConfig
			LoadConfigThread.loadExcelConfig();
			// DB 连接
			dbConnect();
			// 初始化数据库环境
			initDB();
			// 加载DB配置
			loadDB();
			//// 加载Config文件配置
			// loadFileConfig();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			LogUtil.error("Main.init: " + e.toString());
			System.exit(0);
		}
	}

	// private static void loadFileConfig() {
	// // TODO Auto-generated method stub
	// // 加载采集器配置文件
	// // 文件夹命名格式：config+"-"+楼号+"-"+mac序号，示例：config-1101080002-1
	// Constant.getConfigFile(LogUtil.GetPath(), "config-", "port");
	// // 采集器点位位置信息写入数据库
	// for (Entry<String, String> pi : Constant.pointInfo.entrySet()) {
	// String building = pi.getKey().split("-")[0];
	// String mac = pi.getKey().split("-")[1];
	// String node = mac;
	// String point = pi.getKey().split("-")[2];
	// String busno = pi.getValue().split("-")[0];
	// String site = pi.getValue().split("-")[1];
	// try {
	// HBaseUtil.InsertPointInfo(Constant.agent,
	// Constant.BuildingDB.get(building), building, node, point,
	// busno, site);
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// // System.out.println(building + node + point + busno + site);
	// }
	// }

	/**
	 * DB 连接
	 */
	private static void dbConnect() {
		// TODO Auto-generated method stub
		if (Constant.DbConnection.containsKey("Db-Mysql")) {
			mysqlConnect();
		} else if (Constant.DbConnection.containsKey("Db-Hbase")) {
			hbaseConnect();
		}
		if (Constant.DbConnection.containsKey("Upload-Mysql")) {
			mysqlUploadConnect();
		} else if (Constant.DbConnection.containsKey("Upload-Hbase")) {
			hbaseUploadConnect();
		}
	}

	/**
	 * HBase 连接
	 */
	private static void hbaseUploadConnect() {
		try {
			EntityHbase entityHbase = new EntityHbase();
			entityHbase = (EntityHbase) Constant.DbConnection.get("Db-Hbase");
			Configuration configuration = new Configuration();
			configuration.set("hbase.cluster.distributed", "true");
			configuration.set("hbase.zookeeper.quorum", entityHbase.Address);
			Constant.agentUpload = new ZillionAgent(configuration);
			Constant.agentUpload.Start();
		} catch (Exception e) {
			e.printStackTrace();
			LogUtil.error("Main.init.hbaseUploadConnect: " + e.toString());
		}
	}

	/**
	 * MySQL 连接
	 */
	private static void mysqlUploadConnect() {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			EntityMysql entityMysql = new EntityMysql();
			entityMysql = (EntityMysql) Constant.DbConnection.get("Upload-Mysql");
			Constant.connUpload = DriverManager.getConnection(
					"jdbc:mysql://" + entityMysql.Ip + ":" + entityMysql.Port + "/", entityMysql.User,
					entityMysql.Password);
		} catch (Exception e) {
			e.printStackTrace();
			LogUtil.error("Main.init.mysqlUploadConnect: " + e.toString());
		}
	}

	/**
	 * MySQL 连接
	 */
	private static void mysqlConnect() {
		// TODO Auto-generated method stub
		try {
			Class.forName("com.mysql.jdbc.Driver");
			EntityMysql entityMysql = new EntityMysql();
			entityMysql = (EntityMysql) Constant.DbConnection.get("Db-Mysql");
			Constant.conn = DriverManager.getConnection("jdbc:mysql://" + entityMysql.Ip + ":" + entityMysql.Port + "/",
					entityMysql.User, entityMysql.Password);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			LogUtil.error("Main.init.mysqlConnect: " + e.toString());
		}
	}

	/**
	 * 加载DB配置
	 */
	private static void loadDB() {
		// TODO Auto-generated method stub
		// // V1.0点位日志结构
		// {
		// loadStatus();
		// }
		// V2.0点位日志结构
		{
			// 先加载状态再加载列表，如无状态记录则根据列表生成null
			// loadStatus2();
			loadStatus2();
			// loadPointList2();
			loadPointList2();
		}
	}
	//
	// private static void loadPointList2() {
	// // TODO Auto-generated method stub
	// // 重新启动加载点位列表
	// for (Entry<String, String> bd : Constant.BuildingDB.entrySet()) {
	// try {
	// String project = bd.getKey();
	// String db = bd.getValue();
	// HBaseUtil.LoadDB2Cache_dy_pointlist(Constant.agent, db, "dy_pointlist",
	// project);
	//
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// LogUtil.error("Main.loadPointList2: " + e.toString());
	// }
	// }
	// }

	/**
	 * 加载点位列表
	 */
	private static void loadPointList2() {
		// TODO Auto-generated method stub
		// 重新启动加载点位列表
		Constant.loadDB2Cache_dy_pointlist();
	}
	// private static void loadStatus() {
	// // TODO Auto-generated method stub
	// // 重新启动加载节点、点位状态
	// for (Entry<String, String> bd : Constant.BuildingDB.entrySet()) {
	// try {
	// String project = bd.getKey();
	// String db = bd.getValue();
	// HBaseUtil.GetCollectorStatus(Constant.agent, db, "pointgatewaystatus",
	// project);
	// HBaseUtil.GetPointStatus(Constant.agent, db, "pointstatus", project);
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// LogUtil.error("Main.loadStatus: " + e.toString());
	// }
	// }
	// }
	//
	// private static void loadStatus2() {
	// // TODO Auto-generated method stub
	// // 重新启动加载节点、点位状态
	// for (Entry<String, String> bd : Constant.BuildingDB.entrySet()) {
	// try {
	// String project = bd.getKey();
	// String db = bd.getValue();
	// HBaseUtil.LoadDB2Cache_ps_physical_status(Constant.agent, db,
	// "ps_physical_status", project);
	// HBaseUtil.LoadDB2Cache_ps_virtual_meter_status(Constant.agent, db,
	// "ps_virtual_meter_status", project);
	// HBaseUtil.LoadDB2Cache_ps_virtual_point_status(Constant.agent, db,
	// "ps_virtual_point_status", project);
	// HBaseUtil.LoadDB2Cache_ps_virtual_project_status(Constant.agent, db,
	// "ps_virtual_project_status",
	// project);
	//
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// LogUtil.error("Main.loadStatus2: " + e.toString());
	// }
	// }
	// }

	/**
	 * 加载点位状态
	 */
	private static void loadStatus2() {
		// TODO Auto-generated method stub
		// 重新启动加载节点、点位状态
		try {
			Constant.LoadDB2Cache_ps_physical_status(Constant.Database, "ps_physical_status");
			Constant.LoadDB2Cache_ps_virtual_meter_status(Constant.Database, "ps_virtual_meter_status");
			Constant.LoadDB2Cache_ps_virtual_point_status(Constant.Database, "ps_virtual_point_status");
			Constant.LoadDB2Cache_ps_virtual_project_status(Constant.Database, "ps_virtual_project_status");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			LogUtil.error("Main.loadStatus2: " + e.toString());
		}
	}

	/**
	 * 初始化数据库环境
	 */
	private static void initDB() {
		// TODO Auto-generated method stub
		try {
			// createDB(db);
			Constant.CreateDB(Constant.Database);
			Thread.sleep(Constant.Millisecond.SECOND_1);

			// // V1.0点位日志结构
			// {
			// Thread.sleep(Constant.Millisecond.SECOND_1);
			// // dropTB(db);
			// // Thread.sleep(Constant.Millisecond.SECOND_1);
			// createTB(db);
			// }

			// V2.0点位日志结构
			{
				// dropTB2(db);
				// Thread.sleep(Constant.Millisecond.SECOND_1);
				// createTB2(db);
				createTB2(Constant.Database);
			}

			Thread.sleep(Constant.Millisecond.SECOND_1);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	// private static void createTB2(String db) {
	// // TODO Auto-generated method stub
	// try {
	// HBaseUtil.CreateTable(Constant.agent, db, "original_month");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	// HBaseUtil.CreateTable_present(Constant.agent, db, "original_present");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	// HBaseUtil.CreateTable_set(Constant.agent, db, "originalset");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	// HBaseUtil.CreateTable_setpresent(Constant.agent, db,
	// "originalset_present");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	// // dy_pointlist
	// HBaseUtil.CreateTable_dy_pointlist(Constant.agent, db, "dy_pointlist");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	// // fjd_0_buildingcomputetime
	// HBaseUtil.CreateTable_fjd_0_buildingcomputetime(Constant.agent, db,
	// "fjd_0_buildingcomputetime");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	//
	// // ps_physical_status
	// HBaseUtil.CreateTable_ps_physical_status(Constant.agent, db,
	// "ps_physical_status");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	//
	// // ps_physical_log
	// HBaseUtil.CreateTable_ps_physical_log(Constant.agent, db,
	// "ps_physical_log");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	//
	// // ps_virtual_point_status
	// HBaseUtil.CreateTable_ps_virtual_point_status(Constant.agent, db,
	// "ps_virtual_point_status");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	//
	// // ps_virtual_point_log
	// HBaseUtil.CreateTable_ps_virtual_point_log(Constant.agent, db,
	// "ps_virtual_point_log");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	//
	// // ps_virtual_meter_status
	// HBaseUtil.CreateTable_ps_virtual_meter_status(Constant.agent, db,
	// "ps_virtual_meter_status");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	//
	// // ps_virtual_meter_log
	// HBaseUtil.CreateTable_ps_virtual_meter_log(Constant.agent, db,
	// "ps_virtual_meter_log");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	//
	// // ps_virtual_project_status
	// HBaseUtil.CreateTable_ps_virtual_project_status(Constant.agent, db,
	// "ps_virtual_project_status");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	//
	// // ps_virtual_project_log
	// HBaseUtil.CreateTable_ps_virtual_project_log(Constant.agent, db,
	// "ps_virtual_project_log");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	//
	// Thread.sleep(Constant.Millisecond.SECOND_30);
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// LogUtil.error("Main.createTB2: " + e.toString());
	// }
	// }

	/**
	 * 初始化建表
	 */
	private static void createTB2(String db) {
		// TODO Auto-generated method stub
		try {
			// original_month
			Constant.CreateTable(db, "original_month");
			Thread.sleep(Constant.Millisecond.SECOND_1);
			// original_detail
			Constant.CreateTable_detail(db, "original_detail");
			Thread.sleep(Constant.Millisecond.SECOND_1);
			// original_upload
			Constant.CreateTable_upload();
			Thread.sleep(Constant.Millisecond.SECOND_1);
			// original_present
			Constant.CreateTable_present(db, "original_present");
			Thread.sleep(Constant.Millisecond.SECOND_1);
			// originalset
			Constant.CreateTable_set(db, "originalset");
			Thread.sleep(Constant.Millisecond.SECOND_1);
			// originalset_present
			Constant.CreateTable_setpresent(db, "originalset_present");
			Thread.sleep(Constant.Millisecond.SECOND_1);
			// dy_pointlist
			Constant.CreateTable_dy_pointlist(db, "dy_pointlist");
			Thread.sleep(Constant.Millisecond.SECOND_1);
			// fjd_0_buildingcomputetime
			Constant.CreateTable_fjd_0_buildingcomputetime(db, "fjd_0_buildingcomputetime");
			Thread.sleep(Constant.Millisecond.SECOND_1);

			// ps_physical_status
			Constant.CreateTable_ps_physical_status(db, "ps_physical_status");
			Thread.sleep(Constant.Millisecond.SECOND_1);

			// ps_physical_log
			Constant.CreateTable_ps_physical_log(db, "ps_physical_log");
			Thread.sleep(Constant.Millisecond.SECOND_1);

			// ps_virtual_point_status
			Constant.CreateTable_ps_virtual_point_status(db, "ps_virtual_point_status");
			Thread.sleep(Constant.Millisecond.SECOND_1);

			// ps_virtual_point_log
			Constant.CreateTable_ps_virtual_point_log(db, "ps_virtual_point_log");
			Thread.sleep(Constant.Millisecond.SECOND_1);

			// ps_virtual_meter_status
			Constant.CreateTable_ps_virtual_meter_status(db, "ps_virtual_meter_status");
			Thread.sleep(Constant.Millisecond.SECOND_1);

			// ps_virtual_meter_log
			Constant.CreateTable_ps_virtual_meter_log(db, "ps_virtual_meter_log");
			Thread.sleep(Constant.Millisecond.SECOND_1);

			// ps_virtual_project_status
			Constant.CreateTable_ps_virtual_project_status(db, "ps_virtual_project_status");
			Thread.sleep(Constant.Millisecond.SECOND_1);

			// ps_virtual_project_log
			Constant.CreateTable_ps_virtual_project_log(db, "ps_virtual_project_log");
			Thread.sleep(Constant.Millisecond.SECOND_1);

			Thread.sleep(Constant.Millisecond.SECOND_3);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			LogUtil.error("Main.init.initDB.createTB2: " + e.toString());
		}
	}
	//
	// private static void dropTB2(String db) {
	// // TODO Auto-generated method stub
	// try {
	// // Constant.agent.DDL_DropTable(db, "original_month");
	// // Thread.sleep(Constant.Millisecond.SECOND_3);
	// // Constant.agent.DDL_DropTable(db, "original_present");
	// // Thread.sleep(Constant.Millisecond.SECOND_3);
	// // Constant.agent.DDL_DropTable(db, "originalset");
	// // Thread.sleep(Constant.Millisecond.SECOND_3);
	// // Constant.agent.DDL_DropTable(db, "originalset_present");
	// // Thread.sleep(Constant.Millisecond.SECOND_3);
	// // // dy_pointlist
	// // Constant.agent.DDL_DropTable(db, "dy_pointlist");
	// // Thread.sleep(Constant.Millisecond.SECOND_3);
	//
	// // ps_physical_status
	// Constant.agent.DDL_DropTable(db, "ps_physical_status");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	//
	// // ps_physical_log
	// Constant.agent.DDL_DropTable(db, "ps_physical_log");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	//
	// // ps_virtual_point_status
	// Constant.agent.DDL_DropTable(db, "ps_virtual_point_status");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	//
	// // ps_virtual_point_log
	// Constant.agent.DDL_DropTable(db, "ps_virtual_point_log");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	//
	// // ps_virtual_meter_status
	// Constant.agent.DDL_DropTable(db, "ps_virtual_meter_status");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	//
	// // ps_virtual_meter_log
	// Constant.agent.DDL_DropTable(db, "ps_virtual_meter_log");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	//
	// // ps_virtual_project_status
	// Constant.agent.DDL_DropTable(db, "ps_virtual_project_status");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	//
	// // ps_virtual_project_log
	// Constant.agent.DDL_DropTable(db, "ps_virtual_project_log");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	//
	// Thread.sleep(Constant.Millisecond.SECOND_30);
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// }

	// private static void createTB(String db) {
	// // TODO Auto-generated method stub
	// try {
	// HBaseUtil.CreateTable(Constant.agent, db, "original_month");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	// HBaseUtil.CreateTable_present(Constant.agent, db, "original_present");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	// HBaseUtil.CreateTable_set(Constant.agent, db, "originalset");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	// HBaseUtil.CreateTable_setpresent(Constant.agent, db,
	// "originalset_present");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	// HBaseUtil.CreateTable_CollectorStatus(Constant.agent, db,
	// "pointgatewaystatus");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	// HBaseUtil.CreateTable_CollectorCommunicationLog(Constant.agent, db,
	// "pointgatewaylog");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	// HBaseUtil.CreateTable_PointStatus(Constant.agent, db, "pointstatus");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	// HBaseUtil.CreateTable_PointCommunicationLog(Constant.agent, db,
	// "pointlog");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	// HBaseUtil.CreateTable_PointInfo(Constant.agent, db, "pointinfo");
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// }

	// private static void dropTB(String db) {
	// // TODO Auto-generated method stub
	// try {
	// // Constant.agent.DDL_DropTable(db, "original_month");
	// // Thread.sleep(Constant.Millisecond.SECOND_3);
	// // Constant.agent.DDL_DropTable(db, "original_present");
	// // Thread.sleep(Constant.Millisecond.SECOND_3);
	// // Constant.agent.DDL_DropTable(db, "originalset");
	// // Thread.sleep(Constant.Millisecond.SECOND_3);
	// // Constant.agent.DDL_DropTable(db, "originalset_present");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	// Constant.agent.DDL_DropTable(db, "collectorstatus");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	// Constant.agent.DDL_DropTable(db, "collectorcommunicationlog");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	// Constant.agent.DDL_DropTable(db, "pointstatus");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	// Constant.agent.DDL_DropTable(db, "pointcommunicationlog");
	// Thread.sleep(Constant.Millisecond.SECOND_3);
	// Constant.agent.DDL_DropTable(db, "pointinfo");
	// Thread.sleep(Constant.Millisecond.SECOND_30);
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// }

	// private static void createDB(String db) {
	// // TODO Auto-generated method stub
	// try {
	// HBaseUtil.CreateDB(Constant.agent, db);
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// }

	// private static void createAgentsDB(String db) {
	// // TODO Auto-generated method stub
	// try {
	// HBaseUtil.CreateDB(db);
	// Thread.sleep(1000L);
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	//
	// }

	// private static void agentStart(String[] args) {
	// // TODO Auto-generated method stub
	// try {
	// String resource = "/hbase-site.xml";
	// Configuration configuration = new Configuration();
	//
	// configuration.addResource(new
	// FileInputStream(System.getProperty("user.dir") + resource));
	// String zookeeper_connectionAddress =
	// "zookeeper1:2181,zookeeper2:2181,zookeeper3:2181";
	//
	// if (args != null && args.length > 0 && "test".equalsIgnoreCase(args[0]))
	// {
	// // zookeeper_connectionAddress =
	// // "zk01.td.com:2181,zk02.td.com:2181,zk03.td.com:2181";
	// zookeeper_connectionAddress = "zookeeper1,zookeeper2,zookeeper3";
	// }
	//
	// int zookeeper_sessionTimeout = 300000;
	// Constant.agent = new ZillionAgent(configuration,
	// zookeeper_connectionAddress, zookeeper_sessionTimeout);
	//
	// Constant.agent.Start();
	// // LogUtil.info("" + Constant.BuildingDB);
	// // LogUtil.info("" + Constant.BuildingAdds);
	// // LogUtil.info("" + Constant.BuildingConv);
	//
	// } catch (Exception e) {
	// // TODO Auto-generated catch block
	// LogUtil.error("Main.init.agentStart: " + e.toString());
	// }
	// }

	/**
	 * HBase 连接
	 */
	private static void hbaseConnect() {
		// TODO Auto-generated method stub
		// try {
		// String resource = "/hbase-site.xml";
		// Configuration configuration = new Configuration();
		// configuration.addResource(new
		// FileInputStream(System.getProperty("user.dir") + resource));
		// int zookeeper_sessionTimeout = 300000;

		// List<String> qrlist = new ArrayList<String>();
		// qrlist.add("zookeeper1:2181,zookeeper2:2181,zookeeper3:2181");
		// qrlist.add("zookeeper1,zookeeper2,zookeeper3");
		// qrlist.add("zookeeper1.saga");
		// qrlist.add("zookeeper");

		// for (String qr : qrlist) {
		try {
			EntityHbase entityHbase = new EntityHbase();
			entityHbase = (EntityHbase) Constant.DbConnection.get("Db-Hbase");
			Configuration configuration = new Configuration();
			configuration.set("hbase.cluster.distributed", "true");
			configuration.set("hbase.zookeeper.quorum", entityHbase.Address);
			Constant.agent = new ZillionAgent(configuration);
			Constant.agent.Start();
		} catch (Exception e) {
			e.printStackTrace();
			LogUtil.error("Main.init.hbaseConnect: " + e.toString());
		}
		// }
		// Constant.agents.add(new ZillionAgent(configuration,
		// "zookeeper1:2181,zookeeper2:2181,zookeeper3:2181",
		// zookeeper_sessionTimeout));
		// Constant.agents
		// .add(new ZillionAgent(configuration,
		// "zookeeper1,zookeeper2,zookeeper3", zookeeper_sessionTimeout));
		// Constant.agents.add(new ZillionAgent(configuration, "zookeeper1",
		// zookeeper_sessionTimeout));
		// Constant.agents.add(new ZillionAgent(configuration,
		// "zookeeper1.saga", zookeeper_sessionTimeout));

		// } catch (Exception e) {
		// // TODO Auto-generated catch block
		// LogUtil.error("Main.init.hbaseConnect: " + e.toString());
		// }
	}
}
