Server-Side Java Mapping for Interfaces
Skeleton Interfaces
On the server side, interfaces map to skeleton interfaces. A skeleton is an interface that defines a method for each operation on the corresponding Slice interface. For example, consider our Slice definition for the Greeter interface:
module VisitorCenter
{
interface Greeter
{
string greet(string name);
}
}
The Slice compiler generates the following definition for this interface:
package VisitorCenter;
public interface Greeter extends com.zeroc.Ice.Object {
String greet(String name, com.zeroc.Ice.Current current);
@Override
default CompletionStage<com.zeroc.Ice.OutgoingResponse> dispatch(
com.zeroc.Ice.IncomingRequest request)
throws com.zeroc.Ice.UserException {
...
}
}
public interface AsyncGreeter extends com.zeroc.Ice.Object {
CompletionStage<String> greetAsync(
String name, com.zeroc.Ice.Current current);
@Override
default CompletionStage<com.zeroc.Ice.OutgoingResponse> dispatch(
com.zeroc.Ice.IncomingRequest request)
throws com.zeroc.Ice.UserException {
...
}
}
The important points to note here are:
As for the client side, Slice modules are mapped to Java packages with the same name, so the generated skeleton interface is part of the
VisitorCenterpackage unless you remap it with thejava:identifiermetadata directive.
For each Slice interface
<interface-name>, the compiler generates two Java interfaces that extendcom.zeroc.Ice.Object(the skeleton interfaces).Each skeleton interface contains an abstract method for each operation in the Slice interface.
Each skeleton interface reimplements (overrides) the
dispatchmethod provided bycom.zeroc.Ice.Object: it dispatches incoming requests to the methods on the skeleton based on the operation name received in the request.
Object Servant Base Interface
The Slice pseudo-interface Object is mapped to the com.zeroc.Ice.Object interface in Java:
package com.zeroc.Ice;
public interface Object {
default CompletionStage<OutgoingResponse> dispatch(IncomingRequest request)
throws UserException {
...
}
}
com.zeroc.Ice.Object provides a default dispatch implementation for the 4 operations on the Slice pseudo-interface Object: ice_ping, ice_isA, ice_id and ice_ids.
Servant Classes
In order to provide an implementation for an Ice object, you must create a servant class that implements one of the generated skeleton interfaces. For example, to create a servant for the Greeter interface, you could write:
class Chatbot implements Greeter {
@Override
public String greet(String name, com.zeroc.Ice.Current current) {
return "Hello, " + _name + "!";
}
}
Note that Chatbot implements VisitorCenter.Greeter, one of the two skeleton interfaces.
As far as Ice is concerned, the Chatbot class must implement only a single method: the abstract method greet. This makes the servant class a concrete class that you can instantiate. You can add other methods and fields as you see fit to support your implementation.
The async skeleton interface is described in Asynchronous Method Dispatch (AMD) in Java.