ICE is an object-oriented distributed middleware platform that provides features like RPC, a language-neutral specification language called Slice, language mappings, support for transports like TCP and UDP, services for server activation and firewall traversal, and integration with persistence and threading. Developing applications with ICE involves writing Slice definitions, generating code from Slice, implementing servers that activate objects, and writing clients that make calls to servers. The process is demonstrated through a sample counter service application.
2. What is ICE?
The Internet Communications Engine
An object-oriented distributed middleware platform.
3. ICE Content
object-oriented RPC mechanism
language-neutral specification language (Slice)
language mappings for various languages
support for different transports (TCP, SSL, UDP)
with highly-efficient protocol
external services (server activation, firewall
traversal, etc.)
integrated persistence (Freeze)
threading support
4. Client and Server Structure
Client Application Server Application
Proxy Skeleton Object
Ice API Ice API
Code Adapter
Client Ice Core Server Ice Core
Network
Ice API
Generated Code
5. What is slice?
language-independent types
a compiler creates language-specific source
code
only type definitions without statements
define operations and exchange type defined
7. Basic Slice Types
Type Range of Mapped Type Size of Mapped Type
bool false or true ≥ 1 bits
byte -128-127 or 0-255 ≥ 8 bits
short -215 to 215-1 ≥ 16 bits
int -231 to 231-1 ≥ 32 bits
long -263 to 263-1 ≥ 64 bits
float IEEE single-precision ≥ 32 bits
double IEEE double-precision ≥ 64 bits
string Unicode (UTF-8 for java) Variable-length
8. Enumerations
enum CounterType {
BLOG,
ALBUM,
FEED,
GUEST
};
Rules
• Like Java Enum
• Cannot specify the value
• Empty enumerations are illegal
11. Dictionaries
dictionary<string,string> AccountCacheMap;
dictionary<string,AccountCacheMap> AccountCacheMapMap;
Default type: java.util.HashMap
The key rule:
An integral type (bool, byte, short, int, long, enum) or string
A structure containing only members of integral type or type string
13. Interfaces Operations And Parameters
rules
an operation name
a return type (or void if none)
zero or more parameters
an optional exception specification
operation cannot be overloaded
15. Step 1: write a slice file
module sce{
module demo{
interface CounterService{
int incr();
int decr();
int get();
void set(int num);
};
};
};
16. Step 2: slice2java
slice2java demo.ice
C:Usersxylzworkspacesce-demo>ll sce-demo
-rw-rw-rw- 1 user group 1089 Feb 28 16:34 Callback_CounterService_decr.java
-rw-rw-rw- 1 user group 1086 Feb 28 16:34 Callback_CounterService_get.java
-rw-rw-rw- 1 user group 1089 Feb 28 16:34 Callback_CounterService_incr.java
-rw-rw-rw- 1 user group 639 Feb 28 16:34 Callback_CounterService_set.java
-rw-rw-rw- 1 user group 697 Feb 28 16:34 CounterService.java
-rw-rw-rw- 1 user group 1149 Feb 28 16:34 CounterServiceHolder.java
-rw-rw-rw- 1 user group 3112 Feb 28 16:34 CounterServicePrx.java
-rw-rw-rw- 1 user group 17744 Feb 28 16:34 CounterServicePrxHelper.java
-rw-rw-rw- 1 user group 808 Feb 28 16:34 CounterServicePrxHolder.java
-rw-rw-rw- 1 user group 1034 Feb 28 16:34 _CounterServiceDel.java
-rw-rw-rw- 1 user group 7998 Feb 28 16:34 _CounterServiceDelD.java
-rw-rw-rw- 1 user group 5642 Feb 28 16:34 _CounterServiceDelM.java
-rw-rw-rw- 1 user group 6210 Feb 28 16:34 _CounterServiceDisp.java
-rw-rw-rw- 1 user group 769 Feb 28 16:34 _CounterServiceOperations.java
-rw-rw-rw- 1 user group 687 Feb 28 16:34 _CounterServiceOperationsNC.java
17. Step 3: write a server
package sce.demo.server;
import java.util.concurrent.atomic.AtomicInteger;
import Ice.Current;
import sce.demo._CounterServiceDisp;
public class CounterServiceI extends _CounterServiceDisp {
final AtomicInteger counter = new AtomicInteger(0);
public int incr(Current __current) { return counter.incrementAndGet(); }
public int decr(Current __current) {return counter.decrementAndGet();}
public int get(Current __current) {return counter.get();}
public void set(int num, Current __current) {counter.set(num); }
}
18. Step 4: start the server
package sce.demo.server;
public class Server {
public static void main(String[] args) throws Exception {
Ice.Communicator ic = null;
try {
ic = Ice.Util.initialize(args);
Ice.ObjectAdapter adapter = ic.createObjectAdapterWithEndpoints("Demo", "default -p 2012");
adapter.add(new CounterServiceI(), ic.stringToIdentity("Counter"));
adapter.activate();
ic.waitForShutdown();
} finally {
if (ic != null) ic.destroy();
}
}
}
19. Step 5: write a client
package sce.demo.client;
import sce.demo.CounterServicePrx;
import sce.demo.CounterServicePrxHelper;
public class Client {
public static void main(String[] args) {
Ice.Communicator ic = null;
try {
ic = Ice.Util.initialize(args);
Ice.ObjectPrx base = ic.stringToProxy("Counter:default -p 2012");
CounterServicePrx counter = CounterServicePrxHelper.checkedCast(base);
//
final int initValue = 100;
counter.set(initValue);
System.out.println((initValue+1)+" => "+counter.incr()); 101 => 101
System.out.println((initValue+1)+" => "+counter.get()); 101 => 101
System.out.println((initValue)+" => "+counter.decr());
} finally {
100 => 100
if (ic != null) ic.destroy();
}
}
}
20. Common Steps
1. write the slice files
2. convert slice to java source files (slice2java)
3. write the server (active the object)
4. write the client