Java Implementation for Java Callback
In order to invoke an xUML implementation from a Java object, the Java implementation has to:
implement the Java interface BridgeJavaService, and optional the BridgeJavaServiceStartStopInterface
provide an interface to be implemented in the Designer
Java Code Particularities
Generic Interface
The generic interface BridgeJavaService needs to be implemented in the Java class. Optionally, if you also want to add code to be executed upon service start and/or stop, you can implement the BridgeJavaServiceStartStopInterface.
import ch.e2e.bridge.server.BridgeJavaService;
import ch.e2e.bridge.server.BridgeJavaServiceStartStopInterface;
import ch.e2e.bridge.server.XumlLibraryClass;
@XumlLibraryClass(name = "HttpServer")
public class SimpleHttpServer
implements BridgeJavaService<SimpleHttpServerCallback>, BridgeJavaServiceStartStopInterface {
/**
* Initialize the service; should not access other components or may cause race conditions.
* DO NOT call callback methods here.
*
* @param callback parameter with one or more member functions having an activity diagram
*/
@Override
public void initialize(SimpleHttpServerCallback callback) {
}
/**
* Stop accepting new requests, wait for all active processing to finish.
* DO NOT call callback methods here.
*/
@Override
public void shutDown() {
}
/**
* Start serving requests. From this point on all components can be freely accessed.
*/
@Override
public void start() {
}
/**
* Do some necessary cleanup.
* DO NOT call callback methods here.
*/
@Override
public void stop() {
}
}
The annotation @XumlLibraryClass
is mandatory. It defines the name under which the class should be generated to the xUML service. This class is not visible in the Designer.
The interface contain the following methods (listed in order of execution) that can be implemented:
Method | Location | Mandatory | Description |
---|---|---|---|
initialize | BridgeJavaService | Is invoked when the xUML service is started. initialize should not access other components or this may cause race conditions. Do not call callback methods in initialize. | |
start | BridgeJavaServiceStartStopInterface | Is invoked after all service components are initialized. | |
shutdown | BridgeJavaService | Are invoked when all service components are shut down. Do not call callback methods in shutdown or stop. | |
stop | BridgeJavaServiceStartStopInterface |
In the example, the Java class SimpleHttpServer implements the interfaces BridgeJavaService and BridgeJavaServiceStartStopInterface, and their operations.
Inherited Interface
Furthermore, within the Java application, an interface needs to be defined, which inherits from the generic interface BridgeJavaCallback. In the example, the Java Interface SimpleHttpServerCallback is defined. This interface and its operations will later on be implemented by a class operation in the Designer, as defined in the following section xUML Service Model for Java Callback.
@XumlLibraryClass(name = "HttpServerCallback")
public interface SimpleHttpServerCallback extends BridgeJavaCallback {
...
}
The annotation @XumlLibraryClass
is mandatory. It defines the name under which the interface should be exposed to the xUML service. All operations of this interface are visible in the Designer to be implemented there.
Use the build tools as explained on Java Development: Build Tasks to generate an xLib library that can be imported to the Designer.