Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Tutorial: Building your first OSGi Remote Service"

(Define a Service Interface)
(Define a Service Interface)
Line 23: Line 23:
  
 
The purpose of this service is to provide the current time...in the form of a long value specifying the number of milliseconds since 1970.  Of course, declarations of much more complex services (and remote services) are possible, with multiple methods, multiple arguments for each method, and complex types as arguments and return values.  In essence, any semantics that can be represented as a java interface can be used as the service interface.
 
The purpose of this service is to provide the current time...in the form of a long value specifying the number of milliseconds since 1970.  Of course, declarations of much more complex services (and remote services) are possible, with multiple methods, multiple arguments for each method, and complex types as arguments and return values.  In essence, any semantics that can be represented as a java interface can be used as the service interface.
 +
 +
With OSGi Services Interfaces (and Remote Services) it's a best practice to put the service interface (and any referred to by the service interface) in a distinct bundle.  This creates a clear, modular separation between the service interface API and both the service implementation and any code that uses the service.  For Remote Services this separation is particularly important, since the client/consumer of the remote service only needs to reference the service interface.

Revision as of 23:54, 5 December 2013

Introduction

The OSGi Framework provides a very simple model to expose services within a local runtime. Also available, however, is a specification of Remote Services...services that are exported by a distribution provider to allow remote access. The ECF project implements a specification-compliant distribution provider.

This tutorial will show how to

  1. define and implement a simple OSGi service
  2. expose that service for remote access via ECF's implementation of the OSGi Remote Services standard

Define a Service Interface

The key to building a system with low coupling and high cohesion is to create clear and coherent boundaries between different parts of your system. Central to this is defining simple, clear interfaces between subsystems...to allow to interact, but only in clearly defined ways.

For example, here's a simple time service:

public interface ITimeService {
 
	public Long getCurrentTime();
 
}

The purpose of this service is to provide the current time...in the form of a long value specifying the number of milliseconds since 1970. Of course, declarations of much more complex services (and remote services) are possible, with multiple methods, multiple arguments for each method, and complex types as arguments and return values. In essence, any semantics that can be represented as a java interface can be used as the service interface.

With OSGi Services Interfaces (and Remote Services) it's a best practice to put the service interface (and any referred to by the service interface) in a distinct bundle. This creates a clear, modular separation between the service interface API and both the service implementation and any code that uses the service. For Remote Services this separation is particularly important, since the client/consumer of the remote service only needs to reference the service interface.

Copyright © Eclipse Foundation, Inc. All Rights Reserved.