⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbserver.java

📁 DbService数据库接口,测试规范?菘饨涌?测试规范数据库接口,测试规范
💻 JAVA
字号:
package com.rainbow.mas.plugin.dbplugin;

import org.apache.log4j.Logger;

import com.rainbow.mas.monitor.PerformanceMonitor;
import com.rainbow.mas.plugin.dbplugin.util.SvcUtil;
import com.rainbow.mas.plugin.dbplugin.util.SysConfUtil;
import com.rainbow.mas.web.dto.ServiceBaseInfo;

import Ice.Application;
import Ice.ObjectPrx;
import MasBox.AlreadyStoppedException;
import MasBox.NoSuchServiceException;
import MasBox.RunningStatus;
import MasBox.ServiceManagerPrxHelper;
import MasBox.ServiceManagerPrx;
import MasBox.SvcInfo;

public class DbServer extends Application {
	public static final Logger logger = Logger.getLogger(DbServer.class
			.getName());

	private SvcInfo svcInfo;
	
	private ServiceBaseInfo svcbaseinfo;

	private ServiceManagerPrx svcMgrPrx;
	
	public RunningStatus status;

	public int run(String[] args) {
		logger.info("run ...");
		//注意:数据库通讯插件默认名字为DbSvc
		svcbaseinfo = SvcUtil.getSvc("DbSvc");
		
		String endpoint = svcbaseinfo.getEndpoint();
		if (endpoint==null){
			logger.info("endopoint is null. can't initial the service!");
			return 0; 
		}
		String [] list = endpoint.split(":");
		if (list.length!=2){
			logger.info("endopoint is bad formated. Can't initial the service!");
					return 0; 
		}
		String name = list[0];
		String host = list[1];
		
		Ice.ObjectAdapter adapter = communicator()
				.createObjectAdapterWithEndpoints("DbSvc",host);
		adapter.add(new DbServiceI(this), communicator().stringToIdentity(
				"DbSvc"));
		adapter.activate();
		boolean flag = init();
		if (flag){
			HeartBeatThread t = new HeartBeatThread(this);
			t.start();
			
			communicator().waitForShutdown();
			
			unInit();
			t.setStop();
			t.interrupt();
		}
		return 0;
	}
	
	public void ping(){
		logger.info("report running status");
		try {
			if (svcMgrPrx!=null){
				svcMgrPrx.reportServiceRunningStatus("DbSvc", status);
			}
		} catch (AlreadyStoppedException e) {
			logger.error("already stopped service",e);
		} catch (NoSuchServiceException e) {
			logger.error("no such service ",e);
		}
	}

	private boolean init() {
		logger.info("init...");
		svcMgrPrx = null;
		
		String endpoint = SysConfUtil.getValue("SELF", "ServiceManagerEndpoint");
		if (endpoint==null){
			endpoint ="MasBox.ServiceManager:tcp -h 127.0.0.1 -p 8888"; 
		}
		
		if ( svcbaseinfo == null){
			logger.info("can't find DbSvc's configure in mas.service_baseinfo_tb!" +
					"Service is shutdown!");
			return false;
		}

		ObjectPrx objPrx = communicator().stringToProxy(endpoint);
		if (objPrx != null) {
			svcMgrPrx = ServiceManagerPrxHelper.checkedCast(objPrx);
			svcMgrPrx.ice_twoway().ice_timeout(-1).ice_secure(false);
		}

		logger.info("get current pid ... ");
		long pid = PerformanceMonitor.getCurrentProcessId();
		logger.info("pid:"+pid);
		svcInfo = new SvcInfo();
		svcInfo.svcId=svcbaseinfo.getSvcId();
		svcInfo.pId = Long.toString(pid);
		svcInfo.neededCommicationCapability = svcbaseinfo.getCommuAbilitySupport();
		
		if (svcMgrPrx != null) {
			try {
				logger.info("register DbSvc ... ");
				svcMgrPrx.registerService("DbSvc", svcInfo);
				return true;
			} catch (AlreadyStoppedException e) {
				logger.error("already stopped service",e);
			} catch (NoSuchServiceException e) {
				logger.error("no such service",e);
			}
		} else {
			logger.info("can't connected to svcMgrPrx");
		}
		return false;
	}

	private void unInit() {
		logger.info("uninit...");
		if (svcMgrPrx != null) {
			try {
				svcMgrPrx.unregisterService("DbSvc", svcInfo);
			} catch (AlreadyStoppedException e) {
				e.printStackTrace();
			} catch (NoSuchServiceException e) {
				e.printStackTrace();
			}
		} else {
			logger.info("can't connected to svcMgrPrx");
		}
	}

	public static void main(String[] args) {
		DbServer app = new DbServer();
		int status = app.main("Server", args);
		System.exit(status);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -