ZeroC Ice IceBox

  • ZeroC Ice IceBox已关闭评论
  • 115,174 views
  • A+
所属分类:ZeroC-Ice

IceBox介绍

IceBox服务器用于配置服务、并把对它们的管理集中在一起,服务被开发成可动态加载的组件,通过属性为IceBox服务配置它负责加载和管理的应用特有的服务。要把多个服务组合成一个应用,可以通过配置、而不是编译和链接来完成。这解除了服务和服务器的耦合,允许你按照需要组合服务或分离服务。

编写.ice文件

[["java:package:com.xub.ice"]] // 定义java包名  
module devops{    
struct Information {    
string name; 
int age; 
bool sex; 
string content;
  };       
  interface DevopsInforation     {           
     Information getDevopsInformation(Information information); 
  };
};

生成java代码

参考https://it.baiked.com/zerocice/271.html

接口实现类

package com.xub.ice.devops;

import Ice.Communicator;
import Ice.Current;
import Ice.ObjectAdapter;
import IceBox.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by xubo-os on 2017/11/27.
 */
public class DevopsInforationImpl extends _DevopsInforationDisp implements Service {
    private Logger logger = LoggerFactory.getLogger(DevopsInforationImpl.class);
    private ObjectAdapter _adapter;
    private static final long serialVersionUID = 1L;

    @Override
    public Information getDevopsInformation(Information information, Current __current) {
        logger.info("getDevopsInformation to call ." + logger.getClass().getName());
        return information;
    }

    @Override
    public void start(String s, Communicator communicator, String[] strings) {
        _adapter = communicator.createObjectAdapter(s);
        Ice.Object object = this;
        _adapter.add(object, communicator.stringToIdentity(s));
        _adapter.activate();
        logger.info(s + " started ");
    }

    @Override
    public void stop() {
        logger.info(this._adapter.getName(), " stoped ");
        _adapter.destroy();
    }
}

配置文件config.properties

#service properties
IceBox.InstanceName=MyAppIceBox 1
IceBox.InheritProperties=1
#所有服务初始化完成之后打印 xxx ready
IceBox.PrintServicesReady=MyAppIceBox 1
#IceBox.serviceManager.Endpoints=tcp -p 9999 -h localhost
#performance properties
#IceBox.ThreadPool.Server.Size=4
#IceBox.ThreadPool.Server.SizeMax=100
#IceBox.ThreadPool.Server.SizeWarn=40
#IceBox.ThreadPool.Client.Size=4
#IceBox.ThreadPool.Client.SizeMax=100
#IceBox.ThreadPool.Client.SizeWarn=40
#for system stronger
Ice.ACM.Client=300
Ice.ACM.Server=300
#log and trace
#Ice.LogFile=iceserver.log
Ice.PrintStackTraces=1
Ice.Trace.Retry=2
Ice.Trace.Network=2
Ice.Trace.ThreadPool=1
Ice.Warn.Connections=1
Ice.Warn.Dispatch=1
Ice.Warn.Endpoints=1
#service define begin
#IceBox.Service.name=entry_point [--key=value] [args]
#name定义service的名字,作为start方法的name的参数,必须是唯一的
#entry_point是上面MyServie的完整类名
#[--key=value]:被作为property属性,用于构建该服务的communicator,
#用来更加精确的控制每个Ice服务的性能调优,这里也可以使用--Ice.Config=xxx.cfg的方式从具体的配置文件中加载参数。
#另外,也可以用IceBox.InheriProperties=1的属性让所以Ice服务实例都使用IceBox的配置属性
#[args]作为传入start方法的参数,作为服务启动初始化参数
IceBox.Service.MyService=com.xub.ice.devops.devops.DevopsInforationImpl prop1=1 prop2=2 prop3=3
MyService.Endpoints=tcp -p 10001 -h localhost
#service end
#service load order
#配置多个服务的先后顺序
IceBox.LoadOrder=MyService
IceBox.UseSharedCommunicator.MyService=1
IceBox.UseSharedCommunicator.SMSService=1

启动服务端

eclipse启动如下:

ZeroC Ice IceBoxZeroC Ice IceBox

点击run就启动起来了。

 

启动服务端

 

package com.xub.ice.devops.devops;
public class DevopsInforationClient { 
public static void main(String[] args) { 
int status = 0; Ice.Communicator ic = null; 
try{ 
System.out.println("Server starting..."); 
ic = Ice.Util.initialize(args); 
Ice.ObjectPrx baseObjectPrx=ic.stringToProxy("MyService:tcp -p 10001 -h localhost"); 
DevopsInforationPrx dePrx = DevopsInforationPrxHelper.checkedCast(baseObjectPrx); Information information=new Information(); 
information.age=11; information.name="xubo"; 
information.sex=true; information.content="IT"; 
System.out.println(dePrx.getDevopsInformation(information).content); 
ic.waitForShutdown(); 
}catch(Ice.LocalException e){ 
e.printStackTrace(); 
status = 1; 
}catch(Exception e){ 
System.err.println(e.getMessage()); status = 1; 
} if(ic != null){ 
try{ ic.destroy(); }catch(Exception e){ 
System.err.println(e.getMessage()); status = 1; 
} } 
System.exit(status); }
}

然后执行main方法后,控制台打印出it

  • 安卓客户端下载
  • 微信扫一扫
  • weinxin
  • 微信公众号
  • 微信公众号扫一扫
  • weinxin
avatar