Ice是一种面向对象的中间间平台,入门ice,简单的HelloWorld是必不可少的。
转载请注明http://www.cnblogs.com/zrtqsk/p/3745286.html,谢谢。
一、写一个ice定义
ice用来定义接口、程序骨架的,方便远程调用。首先我们要使用ice专属的slice语言写一个ice定义。如下:
file_name:HelloWorld.ice
module myHelloWorld{
interface HelloWorld{
void say(string s);
};
};
module相当于java中的包,是ice定义中必不可少的。
二、编译这个ice定义
要编译这个ice定义,首先要安装一个ice服务器,将其中的bin文件夹加入环境变量。跟jdk配置类似。然后使用其中的slice2java命令编译。
例如HelloWorld.ice文件放在我F盘的test文件夹,运行aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAATAAAAAVCAIAAABOjyWVAAACHUlEQVR4nO2aUVLDMAxEdd3cqtegtyjH6CXMH7S2tVo5TmJg3zCMx1FXKymiP1iJMLNSyv3xvH/+/Hw8nrfbbds2E0JMRAspxEJoIYVYCC2kEAuhhRRiIbSQQiyEFlKIhdBCCrEQOxfS+8iCZL3hivZXGnbszGa+5iLzev5Tb0IVtqdkZl68+GVvcnejqtoK/IbMzhIEzGrBxFf8oIVkmrb4QuLg8xcyVPiPC2nvy/AqUl16TmZVNPb0OFdA9rLZz/DzVxfyMuYuZHf32i54W1rlbR95H2F0vOyp4KyfUJ9PAS4H6gIedvZnoChgwzPjpcZ5+VaQ/sH9ICXCuIXMevIKA2HM2dPxZIEOVgNJSZ+hWyZ1qI9TVDHtHE/rTzUOZr6V1VTekFnzTdNOoh1MGf2GHK4Z2MPx4D6VN5sFh3X9Z1N3dbyzF8/kas9AZ6A/3fP37+oA6upmJ/OGAJ02jO8zmxhgmYX0xJmyu5FhkeFISMGd99mPhz6NeIkHzntypaoA/fEekR5S8832gdEBYRMoEXbkQlpvHsxgsgPuRmIdcAmS7vef0rT3CfJ1DeQ6oj/mzIuJDwsJ/bd9y+pk+xxTIgwuZBU57KEy4zlk7rEO7oB33/Yd34f6WKRr+DWy+wg0wau9qwCsHtcfMq8nwuTFLU3V5cWDDrO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Oc/eIee54Jxn72O3hkCLXEfZZxSESwcHOc9qkPNccM6z97EP764WdXWy26ySo/L5COHSPkLOs+IJJOd5GfFjXcHapEQIVUArOc9RwgcP4HHWEiFUNkLOc6RQ8xHCpcEr5BgBgCr4CACogo8AgCr4CACogo8AgCrkPAOAKuQ8A4Aq5DwDgCrkPPvSqG33cj8S6mtPeKYVCoSc5wjkPLvpSSHgI0FAzrMK5DwHn/PspidQXMh5VoOc5+Bznt30BMIDOc+FQ85zcDnPsqRYp55IT5plOLLmrMElJhu2Zs7yOz9XkPNcOOQ8+53zLO1Y3p4Q9RwWyHn2AjnPtomBj/msNht16glRz+GAnGePkPMcZM6zbSqVw0eIei425Dx7h5xn33OeZR3L2xPpSSPqedkg51kNcp59znnOe59V3hOinosKOc+KJ5Cc59KDtUkpEKqAVnKewQqPs5YCobIRcp7BSDdRz+AFcowAQBV8BABUwUcAQBV8BABUwUcAQBV8BABUwUcAQBV8BABUwUcAQBVx9eq1r74aGhgY7O+/ePrzc8eOf4aPAEBBiK++ujIwcKn/i4tnzpz/7O+fx46dxEcAoCDEzZsj167d+Pra9eHhr4eGhi9fHjp3rv+9997DRwDAJaL1j60Wvffee59++ik+AgAuEfF4/PHjx3EDk5OTU1NT+AgAuAQfAQBV8BEAUAUfAQBV8BEAUAUfAQBV8BEAUEUkzExPT+MjAFAQ4sc//vFPfvKTZ555ZtOmTc3NzYlEAh8BgIIQL7300tatW997773jx48zHwEAD/x/YcIEMPJoLXsAAAAASUVORK5CYII=" alt="" />
myHelloWorld文件夹名是ice定义中的module名。
三、编写Servant类
servant类是ice服务器端提供操作调用的行为制品,它提供的是ice对象的实质内容。说白了,就是ice所定义的接口,在服务器端的实现类。
按照管理,servant类名是ice接口名加一个“I”后缀,如下:
package client; import Ice.Current;
import myHelloWorld._HelloWorldDisp; public class HelloWorldI extends _HelloWorldDisp{ private static final long serialVersionUID = 1L; @Override
public void say(String s, Current __current) {
System.out.println("Hello World!"+" the string s is " + s);
}
}
如上,servant类需要继承_HelloWorldDisp这个slice2java编译生成的抽象类。实现方法参数是原本的形参加一个Ice的Current对象。
四、编写远程的服务器类
package client;
public class Server { public static void main(String[] args)
{
int status = 0;
// Communicator实例,是ice run time的主句柄
Ice.Communicator ic = null;
try
{
// 调用Ice.Util.Initialize()初始化Ice run time
System.out.println("初始化ice run time...");
ic = Ice.Util.initialize(args); // 创建一个对象适配器,传入适配器名字和在10000端口处接收来的请求
System.out.println("创建对象适配器,监听端口10000...");
Ice.ObjectAdapter adapter = ic.createObjectAdapterWithEndpoints("SimplePrinterAdapter", "default -p 10000"); // 实例化一个PrinterI对象,为Printer接口创建一个servant
System.out.println("为接口创建servant...");
Ice.Object object = new HelloWorldI(); // 调用适配器的add,告诉它有一个新的servant,传递的参数是刚才的servant,这里的“SimplePrinter”是Servant的名字
System.out.println("对象适配器加入servant...");
adapter.add(object, Ice.Util.stringToIdentity("SimplePrinter")); //调用适配器的activate()方法,激活适配器。被激活后,服务器开始处理来自客户的请求。
System.out.println("激活适配器,服务器等待处理请求...");
adapter.activate(); //这个方法挂起发出调用的线程,直到服务器实现终止为止。或我们自己发出一个调用关闭。
ic.waitForShutdown();
} catch (Ice.LocalException e)
{
e.printStackTrace();
status = 1;
} catch (Exception e)
{
e.printStackTrace();
status = 1;
} finally
{
if (ic != null)
{
ic.destroy();
}
}
System.exit(status);
}
}
这个服务器类其实就寥寥几行代码,注释已经很清楚了。
五、编写客户端类
package client;
import myHelloWorld.HelloWorldPrx;
import myHelloWorld.HelloWorldPrxHelper; public class Client { public static void main(String[] args)
{
int status = 0;
// Communicator实例
Ice.Communicator ic = null;
try
{
// 调用Ice.Util.Initialize()初始化Ice run time
ic = Ice.Util.initialize(args); // 获取远地打印机的代理
Ice.ObjectPrx base = ic.stringToProxy("SimplePrinter:default -p 10000"); // 将上面的代理向下转换成一个Printer接口的代理
HelloWorldPrx helloWorld = HelloWorldPrxHelper.checkedCast(base); // 如果转换成功
if (helloWorld == null)
{
throw new Error("Invalid proxy");
} // 调用这个代理,将字符串传给它
helloWorld.say("bar"); } catch (Ice.LocalException e)
{
e.printStackTrace();
status = 1;
} catch (Exception e)
{
e.printStackTrace();
status = 1;
} finally
{
if (ic != null)
{
ic.destroy();
}
}
System.exit(status);
}
}
六、运行
先运行服务器,服务器线程一直运行等待,如下:
初始化ice run time...
创建对象适配器,监听端口10000...
为接口创建servant...
对象适配器加入servant...
激活适配器,服务器等待处理请求...
运行了客户端后,显示如下:
初始化ice run time...
创建对象适配器,监听端口10000...
为接口创建servant...
对象适配器加入servant...
激活适配器,服务器等待处理请求...
Hello World! the string s is bar
将客户端改一下 helloWorld.say("foo");,再运行,显示如下:
初始化ice run time...
创建对象适配器,监听端口10000...
为接口创建servant...
对象适配器加入servant...
激活适配器,服务器等待处理请求...
Hello World! the string s is bar
Hello World! the string s is foo
(部分参考《Ice分布式程序设计》)