Commit 60b399cd by s_guodong

pom文件整理

parent 0e4a33ed
package com.brilliance.eibs.server.manager;
import com.brilliance.eibs.core.model.IServiceDef;
import com.brilliance.eibs.factory.FactoryManager;
import com.brilliance.eibs.factory.parser.ConfigParser;
import com.brilliance.eibs.factory.parser.ParserFactory;
import com.brilliance.eibs.main.Server;
import com.brilliance.eibs.server.IServerInstance;
import com.brilliance.eibs.util.LogUtil;
import com.brilliance.eibs.util.Serializable2FileUtil;
import org.slf4j.Logger;
import org.sss.common.model.IState;
import org.sss.common.model.IState.IStopCallback;
import java.util.List;
/**
* @author gechengyang
* @category 服务调用API
**/
public class ServerManagerUtil {
private static Logger logger = LogUtil.getLogger("services");
// private static Log logger = LogFactory.getLog("services");
/**
* 服务调用入口
*
* @param serviceId
* 服务ID
* @param stock
* 是否阻塞
* @param state
* BD服务关闭时的控制
* @param args
* 服务相关参数
**/
public static void service(final String serviceId, boolean stock, IState state, Object[] args) {
if (Server.servers.containsKey(serviceId)) {
logger.info("service id[" + serviceId + "] has been started");
return;
}
logger.info("service id[" + serviceId + "] will be started");
Server.dealBDHotDeploy();
state.setStopCallback(new IStopCallback() {
public void stop() {
logger.info("callback stop");
try {
IServerInstance server = Server.servers.get(serviceId);
server.close();
// / Server.servers.remove(serviceId);
removeServer(serviceId);
} catch (Exception e) {
logger.error("stop receiver error" + e.getMessage());
removeServer(serviceId);
}
}
});
logger.info("before to satart service....");
ConfigParser parser = ParserFactory.getInstance(logger);// 配置解析器
List<IServiceDef> serviceDefs = parser.getServiceDefs("services");// 获取所有服务定义
Serializable2FileUtil.writeObject(serviceDefs, "services");// 保存为序列化文件,用于热部署
try {
for (IServiceDef serviceDef : serviceDefs)// 启动services
{
if (serviceId.equals(serviceDef.getId())) {
if (serviceDef.getState().equals("on") && !Server.servers.containsKey(serviceId)) {
Server.startServer(serviceDef, args);
}
}
}
// 初始化内存
Server.initBeanFactoryMemory(parser, FactoryManager.getBeanFactory());
} catch (Exception e) {
e.printStackTrace();
removeServer(serviceId);
}
}
public static void removeServer(String serviceId) {
IServerInstance serverInstance = Server.servers.get(serviceId);
Server.servers.remove(serviceId);
if (serverInstance != null)
serverInstance = null;
}
}
package com.brilliance.eibs.server.manager;
import org.apache.commons.io.IOUtils;
import org.sss.common.model.IStream;
import java.io.*;
public class StreamImpl
implements IStream
{
InputStream is;
InputStream bzis;
@SuppressWarnings("unused")
private StreamImpl()
{
}
public StreamImpl(File file)
throws IOException
{
this.is = new FileInputStream(file);
}
public StreamImpl(InputStream is)
{
this.is = is;
}
public InputStream getInputStream()
throws IOException
{
return this.is;
}
public OutputStream getOutputStream()
throws IOException
{
throw new UnsupportedOperationException();
}
public InputStream getCompressedInputStream()
throws IOException
{
return null;
}
public OutputStream getCompressedOutputStream()
throws IOException
{
throw new UnsupportedOperationException();
}
public boolean isEmpty()
{
try
{
return this.is.available() == 0;
}
catch (Exception localException) {
}
return true;
}
public String getValue()
{
throw new UnsupportedOperationException();
}
public String setValue(String value)
{
throw new UnsupportedOperationException();
}
public String getName()
{
throw new UnsupportedOperationException();
}
public void setName(String name)
{
throw new UnsupportedOperationException();
}
public String getType()
{
throw new UnsupportedOperationException();
}
public void setType(String type)
{
throw new UnsupportedOperationException();
}
public void close()
{
if (this.bzis != null)
IOUtils.closeQuietly(this.bzis);
this.bzis = null;
IOUtils.closeQuietly(this.is);
}
}
package com.brilliance.eibs.server.manager;
import com.brilliance.eibs.core.model.ITaskDef;
import com.brilliance.eibs.factory.FactoryManager;
import com.brilliance.eibs.factory.parser.ConfigParser;
import com.brilliance.eibs.factory.parser.ParserFactory;
import com.brilliance.eibs.main.Server;
import com.brilliance.eibs.quartz.CronTask;
import com.brilliance.eibs.util.LogUtil;
import com.brilliance.eibs.util.Serializable2FileUtil;
import org.slf4j.Logger;
import org.sss.common.model.IState;
import org.sss.common.model.IState.IStopCallback;
import java.util.List;
/**
* @author gechengyang
* @category 服务调用API
**/
public class TaskManagerUtil {
private static Logger logger = LogUtil.getLogger("services");
/**
* 定时任务用入口是
*
* @param taskId
* 服务ID
* @param stock
* 是否阻塞
* @param state
* BD服务关闭时的控制
* @param args
* 服务相关参数
**/
public static boolean task(final String taskId, boolean stock, IState state, Object[] args) {
if (Server.taskMap.containsKey(taskId)) {
logger.info("task id[" + taskId + "] has been started");
return true;
}
logger.info("task id[" + taskId + "] will be started");
Server.dealBDHotDeploy();
if (null != state)
state.setStopCallback(new IStopCallback() {
public void stop() {
logger.info("callback stop");
try {
CronTask task = Server.taskMap.get(taskId);
Server.closeTask(taskId);
} catch (Exception e) {
logger.error("stop task error" + e.getMessage());
Server.closeTask(taskId);
}
}
});
logger.info("before to satart task....");
ConfigParser parser = ParserFactory.getInstance(logger);// 配置解析器
List<ITaskDef> taskDefs = parser.getTaskDefs("services");// 获取所有服务定义
Serializable2FileUtil.writeObject(taskDefs, "tasks");// 保存为序列化文件,用于热部署
try {
for (ITaskDef taskDef : taskDefs)// 启动services
{
if (taskId.equals(taskDef.getId())) {
if (taskDef.getState().equals("on") && !Server.taskMap.containsKey(taskId))
Server.startTask(taskDef, args);
}
}
// 初始化内存
Server.initBeanFactoryMemory(parser, FactoryManager.getBeanFactory());
} catch (Exception e) {
e.printStackTrace();
Server.closeTask(taskId);
return false;
}
return true;
}
public static boolean task(final String taskId, boolean stock, Object[] args) {
return task(taskId, stock, null, args);
}
public static void removeTask(String taskId) {
Server.closeTask(taskId);
}
public static boolean isStarted(String taskId) {
return Server.taskMap.containsKey(taskId);
}
}
package com.brilliance.eibs.util;
import com.brilliance.eibs.server.manager.StreamImpl;
import org.sss.common.model.IStream;
import java.io.ByteArrayInputStream;
/**
* BD中的一些函数操作
* **/
public class BdUtil
{
/**
* 返回Istream对象
* **/
public static IStream iStream(byte[] buffer)
{
IStream is = new StreamImpl(new ByteArrayInputStream(buffer));
return is;
}
public static void main(String[] args)
{
System.out.println(BdUtil.iStream("12345".getBytes()));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment