Create And Register A COR•REC Service

We highly recommend that you visit our COR•REC Sandbox first if you haven't already. This will help you understand and contextualize the information that follows. If you stumbled upon this without checking the COR•REC Service Overview, please make sure to do that before continuing.

Creating a COR•REC Service class

COR•REC Service CorrecService.class is how others access your service. The CorrecService.class that you extend is the class you ultimately register as a service.

Creating a COR•REC Service begins by downloading COR•REC Sandbox that contains the sandbox-target. From the sandbox target add the following three plug-ins to your target.

 
  • • com.corgroup.bmp
  • • com.corgroup.bmp.client
  • • com.corgroup.bmp.osgi.service
Create a class that extends the abstract class com.corgroup.bmp.osgi.service.CorrecService.

You may not need to override any methods in the CorrecService.class but you will need to add the following methods:

<@Override
    public Object collaborate(Integer action, Map>String, Object> map)
<@Override
    public String getID();//unique ID given to your service

Once a consumer has acquired your service and confirmed its availability, they can make their request using the collaborative method. COR•REC Services regards the "action" parameter as the request itself and the "map" parameter as the necessary data to execute the action. You have the freedom to define whatever you wish for the action and map parameters. The action parameter may align with the static action values found in com.corgroup.bmp.osgi.service.CorrecService_I however this is not required.

Registering a COR•REC Service

Most services should be registered at startup.  But again where and when you register and or unregister your service is wholly at your discretion. Here we extend org.eclipse.ui.IStartup.class utilizing the org.eclipse.ui.startup extension.  Registering a CorrecService may also be done in a plugins Activator if the plugin is loaded at startup.

Create a Startup class that implements IStartup.

This requires the MANIFEST.MF/Extensions to contain the org.eclipse.ui.startup extension with its class attribute pointing to the Startup class created.

 

The actions required to register your service are described next:

  1. Designate a unique static String ID to identify your service. One method would be to use your plugin name and append a reference key. i.e.: com.corgroup.bms.accounting.ar#ACCOUNTS
  2. Get String[] of consumer plugins authorized to access your service. The method for authorizing plugin access is demonstrated in the COR•REC Sandbox. If no consumers are found do not register your service.  Any other conditions are at your discretion.
  3. Instantiate the CorrecService class.
  4. Register your service with a call to CorrecServiceRegistry.REGISTER_SERVICE(BundleContext, your-CorrecService.class, null, Consumers[], your-ID)
  5. An org.osgi.framework.ServiceRegistration is returned by REGISTER_SERVICE. This is required to unregister your service. 

When the plugin in shutdown un-register your registered services.

CorrecServiceRegistry.UNREGISTER_SERVICE is called once for each consumer. 

  1. CorrecServiceRegistry.UNREGISTER_SERVICE(Consumer, yourID, BundleContext, ServiceRegistration)

Reference Links:

© CORGROUP® LLC 2025 All right reserved