IceBox divergent

ice box 以配置文件为主,所以首先得先会配置,有什么不懂的就往官方网站上拾到拾到

https://doc.zeroc.com/display/Doc/Home


run cmd:

java IceBox.Server --Ice.Config=config
java -classpath example.jar IceBox.Server --Ice.Config=example.properties

example.properties:

IceBox.Service.ExampleService=/classes:PrinterServiceI --Ice.Trace.Network=1
IceBox.UseSharedCommunicator.ExampleService=1
ExampleServer.Endpoints=tcp -p 10001

#you can define servel services

#thread pool properties
Ice.ThreadPool.Server.Size=8
Ice.ThreadPool.Server.SizeMax=100
Ice.ThreadPool.Server.SizeWarn=40
Ice.ThreadPool.Client.Size=8
Ice.ThreadPool.Client.SizeMax=100
Ice.ThreadPool.Client.SizeWarn=40
 
Ice.ACM.Close=0
IceBox.InheritProperties=1
#if exist define serval services, assign the startup order, and print when startup
IceBox.LoadOrder=ExampleService,order 2, order 3
IceBox.PrintServicesReady=ExampleService 1, order 2, order 3

Define your demo slice:

module Demo{
    interface Printer {
        void printString(string s);
    };
};
Genarated your code of slice:

$ mkdir generated
$ slice2java --output-dir generated demo.ice

so you can found a class name Demo._PrinterDisp, and imply this class, but i do not suggest this method in the paper, the principle of slice:



IceBox Interface:

module IceBox {
local interface Service {
    void start(string name, Ice::Communicator communicator, Ice::StringSeq args);
    void stop();
};
};
Define your Ice Box Service:

public class PrinterI extends Demo._PrinterDisp implements IceBox.Service {
    public void printString(String s, Ice.Current current)
    {
        System.out.println(s);
    }
    
    @Override
    public void start(String name, Communicator communicator, String[] args) {
        adapter = communicator.createObjectAdapter(name);
        Ice.Object obj = this;
        adapter.add(obj, communicator.stringToIdentity(name));
        adapter.activate();
    }
 
    @Override
    public void stop() {
        adapter.destroy();
    }

}

so a service in ice box like this,

Ofcouse, you can define servral services:




at last, the client invoke:

public class Client {
    public static void
    main(String[] args)
    {
        int status = 0;
        Ice.Communicator ic = null;
        try {
            ic = Ice.Util.initialize(args);
            Ice.ObjectPrx base = ic.stringToProxy("ExampleService:default -p 10001");
            Demo.PrinterPrx printer = Demo.PrinterPrxHelper.checkedCast(base);
            if (printer == null)
                throw new Error("Invalid proxy");
 
            printer.printString("Hello World!");
        } catch (Ice.LocalException e) {
            e.printStackTrace();
            status = 1;
        } catch (Exception e) {
            System.err.println(e.getMessage());
            status = 1;
        }
        if (ic != null) {
            // Clean up
            //
            try {
                ic.destroy();
            } catch (Exception e) {
                System.err.println(e.getMessage());
                status = 1;
            }
        }
        System.exit(status);
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值