Design a Contextual Interface
What is an interface type?
- An interface specifies a named set of public features.
- The key idea behind interface is to separate the specification of functionality (the interface) from its implementation by a class or component (subsystem).
- Interfaces separate the specification of functionality from its implementation.
- An interface defines a contract.
- An interface type is a classifier of all classes that implement a given interface.
A SORCER service provider is made up of service interfaces and a service provider class implementing them. The interfaces declare service operations used in service signatures. The class implements the operations declared in the interfaces and, perhaps, implements additional operations as well. The implementation of an interface operation is called a method and indirectly is referenced by a signature with the operation and either interface type or the class type implementing the interface type. The former is called a remote (net) signature, tle latter a local (object) signature. A net signature refers to remote providers while a local signature to locally created and used objects at runtime.
An exertion acts as the service model for a federations of local/remote providers. The federation is dynamic as it aggregates (federates) providers at runtime (late binding). A local provider can be created as needed, remote one can be found or provisioned autonomically in the network. The exertion specifies members of the federation via its service signatures. Each signature is responsible for carrying out the method invocation on the remote/local object as specified by signature’s interface/class and operation, and the associated data context of the exertion. Also, a exertion’s control strategy that defines the order of executing nested signatures is defined by exertion control context.
In SORCER, a proxy for a remote provider implements the same set of interfaces that the remote provider implements. Service interfaces can be exposed to requestors as remote or local. This property enables a proxy to be cast to any of the interfaces that the remote object implements. However, in the case of remote calls only those methods defined in a remote interface are available to be called from the implementing service provider.
An object becomes remote by implementing a remote interface, which has the following characteristics:
- Declare the service operations you’d like to call remotely
- The single parameter and returned value of each operation is of the type sorcer.service.Context (contextual interface method)
- The interface can extend java.rmi.Remote (not required for service beans)
- Each method must declare java.rmi.RemoteException in its throws clause
- Can also declare application-specific exceptions
- Remote objects must be passed as remote interface types
- Local objects must be serializable
Local interfaces (not extending java.rmi.Remote) are used with service components (beans) that are embedded in a hosting SORCER provider that publishes them in the network for remote invocations. A service provider that subclasses one of SORCER provider’s (e.g., sorcer.core.provider.ServiceTasker) has to implement the java.rmi.Remote.
Example: Adder Contextual Interface
The interface defined below is used in examples/service/src/main/java/sorcer/provider/adder/Adder.java
package sorcer.provider.adder; import sorcer.service.Context; import sorcer.service.ContextException; import java.rmi.RemoteException; public interface Adder { public Context add(Context context) throws RemoteException, ContextException; }