Apama Capital Markets Foundation Documentation : Capital Markets Foundation Guide : Utilities : Service Framework : ServiceInterface examples
ServiceInterface examples
The ServiceInterface object provides the following actions:
*initialise() creates a new Service Interface instance, and will inform the application (using the specified callback) when all services in the system are available. After that callback occurs, the second stage may proceed.
*initialiseWithConfig() does the same as initialise(), but also allows the application monitor to be called back using the specified callback action when the Service Manager has been activated (it has received the com.apama.config.Activate() event). This allows the monitor to perform necessary configuration before services are made available. The callback action also provides a set of default, service-specific, configuration parameters that can be provided prior to the Service Framework activation by using the com.apama.service.framework.ServiceParameters() event.
*getServiceConfig() returns a sequence of service configuration objects that match the service name and type that were provided. The service configuration object defines the service name and type, the set of parameters that the service was created with, and also defines the context that the service was created on.
*waitForService() will call the user-defined callback action when a service that matches the name and type requested service with the name and type provided has been fully initialised, and the service framework has been activated. This callback will also provide details of any configuration that was applied to that service when it was initialised, and also defines the context that the service was created on. This action can be very useful when building applications that rely on other services in the Capital Markets Foundation.
The following example demonstrates use of initialise():

monitor Example {
 
action onload() {
integer id := (
new com.apama.service.framework.ServiceInterface).initialise(
"serviceType", "serviceName", context.current(),
allServicesInitialised );
}
 
action allServicesInitialised( integer serviceId ) {
 
// Application code
 
}
}
An alternate example for a multi-context environment:


monitor Example {
context mainContext := context.current();
 
action onload() {
context myContext := context( "MY_EXAMPLE_CONTEXT", false);
spawn myNewContext() to myContext;
}
 
action myNewContext() {
integer id := (
new com.apama.service.framework.ServiceInterface).initialise(
“serviceType”, “serviceName”,
mainContext, allServicesInitialised );
}
 
action allServicesInitialised( integer serviceId ) {
 
// Application code
 
}
}
The following example demonstrates use of the waitForService() action :

event MyEvent {
}
 
monitor Example {
 
action onload() {
integer id := (
new com.apama.service.framework.ServiceInterface).waitForService(
"serviceType", "serviceName", context.current(),
cbOnDepedentServiceReady );
}
 
action cbOnDepedentServiceReady(
com.apama.service.framework.ServiceConfig serviceConfig ) {
// We can now interrogate the ServiceConfig to find out where
// the service was created so that we can send an event to it.
enqueue MyEvent() to serviceConfig.serviceCtx;
}
}
The following example demonstrates use of the initialiseWithConfig() action :

monitor Example {
 
action onload() {
integer id := (
new com.apama.service.framework.ServiceInterface).initialiseWithConfig(
"serviceType", "serviceName", context.current(),
myServiceIntialised, allServicesInitialised );
}
 
action myServiceInitialised( integer serviceId, dictionary
<string, string> defaultConfig, action<> configCompleted ) {
 
// Application code to configure this service
 
// Asynchronously inform Service Interface configuration is complete
configCompleted();
}
 
action allServicesInitialised( integer serviceId ) {
 
// Application code
 
}
}
The delete() action correctly cleans up any resources used by a Service Interface instance that is no longer required.
Copyright © 2013-2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback