IceBox divergent

来源:互联网 发布:邦家博士骗局揭秘 知乎 编辑:程序博客网 时间:2024/04/28 02:34

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

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


run cmd:

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

example.properties:

IceBox.Service.ExampleService=/classes:PrinterServiceI --Ice.Trace.Network=1IceBox.UseSharedCommunicator.ExampleService=1ExampleServer.Endpoints=tcp -p 10001#you can define servel services#thread pool propertiesIce.ThreadPool.Server.Size=8Ice.ThreadPool.Server.SizeMax=100Ice.ThreadPool.Server.SizeWarn=40Ice.ThreadPool.Client.Size=8Ice.ThreadPool.Client.SizeMax=100Ice.ThreadPool.Client.SizeWarn=40 Ice.ACM.Close=0IceBox.InheritProperties=1#if exist define serval services, assign the startup order, and print when startupIceBox.LoadOrder=ExampleService,order 2, order 3IceBox.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
原创粉丝点击