Ice is an object-oriented middleware platform under the Zeroc. Fundamentally, this means that ice provides tools, APIs, and library support for building object-oriented client-server applications. ICE applications are suitable for use in heterogeneous platform environments: Customers and servers can be in different programming languages, run on different operating systems and machine architectures, and can communicate using a variety of network technologies. The source code for these applications is portable, regardless of the deployment environment.
Zeroc ICE (Internet Communications Engine) middleware is known as standard unification, open source, Cross-platform, Cross-language, distributed, secure, service transparent, load balanced, object-oriented, superior performance, fire time penetration, communication shielding. Therefore, compared to CORBA,DCOM,SOAP,J2EE, such as middleware technology, nature is set many advantages in one, but without their shortcomings.
It uses C/S pattern structure, supports synchronous invocation and asynchronous invocation, and distributes the calling mode asynchronously. Support for cross language object invocation. Multiple languages use a common slice (specification Language for ICE) to communicate. Supports the mapping of ice to c,java,c#,vb,python,ruby,php and other languages. Ice is rich in properties, and its performance is far from being based on JMS.
A Java-based ice application process is documented below
1 Download the latest installation package;
Http://www.zeroc.com/download.html depending on the operating system and need to choose
I'm installing a ice-3.3.0 here.
2 ice-related paths after installation:
Slice2cpp,slice2java under the/bin/.
Ice.jar stored in/lib/java2/
The associated ice stock is stored under/lib.
3. Create an ice file
Model.ice
#ifndef _model
#define _model
Module com
{
Module Alan
{
Module generated
{
Module model
{
/** defines an array of integers **/
Sequence<int> Integerarray;
/** Custom Map Type **/
Dictionary<string, string> Custommap;
/** Message Type **/
Enum MessageType {error,info,warning};
/** the operation type of the message **/
Enum ActionType {add,modifiy,remove,stop,start,pause};
/** Message Structure **/
["Java:getset"]
struct Message {
/** Message Type **/
MessageType type;
/** Message Type **/
ActionType Action;
/** related id**/
Integerarray Relatedids;
/** Extended Properties **/
Custommap extention;
};
};
};
};
};
#endif
Service.ice
#ifndef _generated
#define _generated
#include <model.ice>
module com
{
module Alan
{
module generated
{
interface Messageserviceice
{
/**
* send information to ICE service
* @param Message Content
* @return True success false failed
& nbsp; */
string SendMessage (Model::message msg);
};
};
};
};
#endif
4.dos environment (can be made into. bat files)
CD E:/workspace/icetest/slice
E:/ice-3.3.0/bin/slice2java-i.--output-dir=. /SRC *.ice//Production Code
E:/ice-3.3.0/bin/slice2html-i.--output-dir=doc *.ice//Production doc documents, you can ignore
5. After the code production structure (in the actual application can bar generted packaging to the client and server side)
Import Ice.jar Write code, Messageserviceiceimpl. Java code:
public class Messageserviceiceimpl extends _messageserviceicedisp {
Public String SendMessage (msg, current __current) {
String str = msg.gettype () + "" + msg.getaction () + "" + arrays.tostring (Msg.getrelatedids ());
return str;
}
}
Server-side code:
public class Iceservice {
public static void Main (string[] args) {
int status = 0;
Communicator IC = null;
try{
IC = util.initialize (args);
Objectadapter adapter = ic.createobjectadapterwithendpoints ("Testadapter", "Tcp-h localhost-p 10000");
Objectimpl object = new Messageserviceiceimpl ();
Adapter.add (object, ic.stringtoidentity ("Testadapter"));
Adapter.activate ();
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);
}
Client code:
public class Iceclient {
public static void Main (string[] args) {
int status = 0;
Communicator IC = null;
try{
IC = Ice.Util.initialize (args);
Ice.objectprx base = Ic.stringtoproxy ("Testadapter:tcp-h localhost-p 10000");
MESSAGESERVICEICEPRX client = Messageserviceiceprxhelper.checkedcast (base);
if (client = null)
throw new Error ("Invalid proxy");
map<string, String > Map = new hashmap<string, string> ();
msg = new Message (Messagetype.info, actiontype.add,new int[]{1},map);
SYSTEM.OUT.PRINTLN (msg);//The service-side method is called here (client.sendmessage)
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);
}
}
6. Finally, we start running the server, then run the client, see the console output info ADD [1], a basic ice application is completed.
About ice more please pay attention to the next article: http://blog.csdn.net/liuzhoulong/article/details/6228333