系统安装ice3.4.1,并配置环境变量;
定义slice文件
[[ "java:package:com.hhly.tel.ice"]]
module book {
interface OnlineBook {
void bookTick(string name,double price,string content);
};
interface SMSService {
void sendSMS(string name,double price,string content);
};
};
这表示有2个接口,一个OnlineBook,一个SMSService,都位于com.hhly.tel.ice.book下面。
生成JAVA类
使用slice2java xx.ice生成
然后将生成的类复制到工程中
上图中圈红的都是ice生成的类。
实现我们自己的逻辑
如上图的service下面,是OnlineBook和SMSService的实现,代码如下:
package com.hhly.tel.ice.book.service;
import Ice.Communicator;
import Ice.Current;
import Ice.ObjectAdapter;
import IceBox.Service;
import com.hhly.tel.ice.book._OnlineBookDisp;
import org.apache.log4j.Logger;
/**
* @Author j.tommy
* @Date 2016/6/19 0019 上午 4:08
*/
public class ICEBookService extends _OnlineBookDisp implements Service{
public static final Logger log = Logger.getLogger(ICEBookService.class);
private ObjectAdapter _adapter;
@Override
public void bookTick(String name, double price, String content, Current __current) {
log.info("Call bookTick()...params->[name=" + name + ",price=" + price + ",content=" + content + "].");
}
@Override
public void start(String name, Communicator communicator, String[] strings) {
// 创建objectAdapter,这里和service同名
_adapter = communicator.createObjectAdapter(name);
// 传Serant并激活
Ice.Object object = this;
_adapter.add(object,communicator.stringToIdentity(name));
_adapter.activate();
log.info(name + " started.");
}
@Override
public void stop() {
log.info(this._adapter.getName() + " stoped.");
_adapter.destroy();
}
}
package com.hhly.tel.ice.book.service;
import Ice.Communicator;
import Ice.Current;
import Ice.ObjectAdapter;
import IceBox.Service;
import com.hhly.tel.ice.book._SMSServiceDisp;
import org.apache.log4j.Logger;
/**
*