More Related Content Similar to Leveraging the Latest OSGi R7 Specifications - C Ziegeler & D Bosschaert (20) Leveraging the Latest OSGi R7 Specifications - C Ziegeler & D Bosschaert1. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Leveraging the lastest OSGi R7 Specifications
David Bosschaert & Carsten Ziegeler | Adobe
2. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Carsten Ziegeler
§ Principal Scientist @ Adobe Research Switzerland
§ Member of the Apache Software Foundation
§ VP of Apache Felix and Sling
§ OSGi Expert Groups and Board member
2
3. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
David Bosschaert
§ R&D Adobe Ireland
§ Co-chair OSGi Enterprise Expert Group
§ Apache Felix, Aries PMC member and committer
§ … other opensource projects
§ Cloud and embedded computing enthusiast
3
4. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Basics
5. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Versioning Annotations
§ Old Friends:
§ @Version, @ProviderType, @ConsumerType
§ New Friend:
§ @Export
5
D
6. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Bundle Annotations
§ More New Friends:
§ @Capability, @Requirement, @Header
@Requirement(namespace="osgi.implementation",
name="osgi.http", version="1.1.0")
@Header(name=Constants.BUNDLE_CATEGORY, value="eclipsecon")
6
D
7. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Converter
8. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Object Conversion
§ Wouldn’t you like to convert anything to everything?
§ Peter Kriens’ work in Bnd started it
§ Convert
§ Scalars, Collections, Arrays
§ Interfaces, maps, DTOs, JavaBeans, Annotations
§ Need predictable behaviour – as little implementation freedom as possible
§ Can be customized
RFC 215 – Implementation in Apache Felix (/converter)
8
D
9. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Sample conversions
§ Examples:
Converter c = Converters.standardConverter();
// Convert scalars
int i = c.convert("123").to(int.class);
UUID id = c.convert("067e6162-3b6f-4ae2-a171-2470b63dff00").to(UUID.class);
List<String> ls = Arrays.asList("978", "142", "-99");
short[] la = c.convert(ls).to(short[].class);
9
D
10. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Convert configuration data into typed information with defaults
Map<String, String> myMap = new HashMap<>();
myMap.put("refresh", "750");
myMap.put("other", "hello");
// Convert map structures
@interface MyAnnotation {
int refresh() default 500;
String temp() default "/tmp";
}
MyAnnotation myAnn = converter.convert(someMap).to(MyAnnotation.class)
int refresh = myAnn.refresh(); // 750
Strine temp = myAnn.temp(); // "/tmp"
10
D
11. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Customize your converter
The converter service itself always behaves the same
§ Need customizations? Create a new converter: ConverterBuilder
§ Change default behaviour of array to scalar conversion
§ Convert String[] to String via adapter
// Default behaviour
String s = converter.convert(new String[] {“hi”, “there”}).to(String.class); // s = “hi”
Converter c = converter.newConverterBuilder()
.rule(String[].class, String.class, MyCnv::saToString)
.build();
String s2 = c.convert(new String[] {“hi”, “there”}).to(String.class); // ss=“hi there”
11
D
12. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Basics in R7
§ Bundle Annotations
§ Converter
§ Promises
§ PushStreams
12
D
13. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Service Development
14. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Simply Simple
§ POJOs
§ Annotations based
§ org.osgi.service.component.annotations.*
§ org.osgi.service.metatype.annotations.*
§ Declarative Services does the hard work
C
15. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Declarative Services
15
Bundle
XML
Service Component Runtime (DS Implementation)
reads
Service Registry
manages
Components Services
registers
C
16. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Components
16
@Component(service = {})
public class MyComponentImpl {
...
C
17. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Lifecycle
17
@Component(service = {})
public class MyComponentImpl {
@Activate
protected void activate() {
...
}
@Deactivate
private void deactivate() {
...
}
C
18. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Services and Properties
18
@Component(service = {MyComponent.class},
property = {
Constants.SERVICE_DESCRIPTION + "=The best service in the world",
"service.ranking:Integer=5",
"tag=foo", "tag=bar"
}
)
@ServiceDescription("The best service in the world")
@ServiceRanking(5)
@Tag({"foo", "bar"})
public class MyComponentImpl implements MyComponent {
...
C
19. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Mandatory Unary References
19
@Component(service = {MyComponent.class})
public class MyComponentImpl implements MyComponent {
@Reference(policyOption=ReferencePolicyOption.GREEDY)
private ResourceResovlerFactory factory;
... {
factory.getResourcResolver();
}
C
20. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Multiple Cardinality Reference
20
@Reference(cardinality=ReferenceCardinality.MULTIPLE)
private volatile List<Filter> filters;
... {
final List<Filter> localFilters = filters;
for(final Filter f : localFilters) {
...
}
}
C
21. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Configuration Admin
21
Configuration Admin
Persistent Store
Configuration
- PID
- Properties
create, update, delete
Configuration(s)
- Factory PID
- Name
- Properties
C
22. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Define Configuration Property Type….
§ Example configuration
§ Boolean for enabled
§ String array with topics
§ String user name
22
@interface MyConfig {
boolean enabled() default true;
String[] topic() default {"topicA", "topicB"};
String userName();
}
C
23. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 23
@Component(service = {})
public class MyComponentImpl {
@Activate
private MyConfig configuration;
@Activate
protected void activate(final MyConfig config) {
// note: annotation MyConfig used as interface
this.configuration = config;
}
}
..and use in activation
C
24. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Constructor Injection
24
@Component
public class MyComponent {
@Activate
public MyComponent(
BundleContext bundleContext,
@Reference EventAdmin eventAdmin,
Config config,
@Reference List<Receivers> receivers) {
C
25. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Metatype
§ Define type information of data
§ ObjectClassDefinition with Attributes
§ Common use case: Configuration properties for a component
§ But not limited to this!
25
C
26. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Configuration Metatype
26
@ObjectClassDefinition(label="My Component",
description="Coolest component in the world.")
@interface MyConfig {
@AttributeDefinition(label="Enabled",
description="Topic and user name are used if enabled")
boolean enabled() default true;
@AttributeDefinition(...)
String[] topic() default {"topicA", "topicB"};
@AttributeDefinition(...)
String userName();
}
C
27. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Connect Component Configuration with Metatype
27
@Component ( service = {})
@Designate( ocd = MyConfig.class )
public class MyComponentImpl {
@Component ( service = {Logger.class})
@Designate( ocd = MyConfig.class , factory = true)
public class LoggerImpl implements Logger {
C
28. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Properties, Properties, Properties
28
@Component(property = {})
Component Property Types
(defaults)
Configuration properties
(runtime)
Component Properties
(runtime)
Service Registry
activate()
C
29. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Declarative Services
§ Developing OSGi Services made easy
§ Configuration support
§ Reference management
§ Dealing with dynamics
29
C
30. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Service Development in R7
§ Configuration Admin
§ Metatype
§ Declarative Services
30
C
31. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Web Development
32. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
JAX-RS Services
§ JAX-RS in OSGi
§ Service / Whiteboard Model
32
D
33. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Simple Resource
33
@Component(service = TestService.class,
scope = ServiceScope.PROTOTYPE)
@JaxrsResource
@Path("service")
public class TestService {
@GET
@Produces("text/plain")
public String getHelloWorld() {
return "Hello World";
}
}
D
34. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
DS-Enabled
34
@Component(service = TestService.class,
scope = ServiceScope.PROTOTYPE)
@JaxrsResource
@Path("service")
public class TestService {
@Reference
private GameController game;
@Activate
protected void activate(final Config config) {}
@GET
public String getHelloWorld() {
return "Hello World";
}
}
D
35. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Application and Parameters
35
@Component(service = TestService.class,
scope = ServiceScope.PROTOTYPE)
@JaxrsApplicationSelect("(osgi.jaxrs.name=myapp)")
@JaxrsResource
@Path("service/{name}")
public class TestService {
@GET
public String getHelloWorld(@PathParam("name") String name) {
return "Hello " + name;
}
}
D
36. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
JAX-RS Support
§ Get, Post, Delete with Parameters
§ Application support
§ JAX-RS extension support (Filters, Interceptors, etc)
§ Annotations for Declarative Services
36
D
37. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Web Development in R7
§ JAXRS integration
§ Http Whiteboard Update
37
D
38. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Provisioning
39. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Reusable Configuration Format
{
"my.special.component" : {
"some_prop": 42,
"and_another": "some string"
},
"and.a.factory.cmp~foo" : {
...
},
"and.a.factory.cmp~bar" : {
...
}}
39
C
40. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
OSGi Configurator
§ Configurations as bundle resources
§ Binaries
§ State handling and ranking
40
C
41. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Clusters, Containers, Cloud!
42. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Cluster Information
OSGi frameworks running in a distributed environment
§ Cloud
§ IoT
§ <buzzword xyz in the future>
Many frameworks
§ New ones appearing
§ … and disappearing
§ Other entities too, like databases
42
D
43. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Cluster Information
Discovery of OSGi frameworks in a distributed environment
§ Find out what is available
§ get notifications of changes
§ Provision your application within the given resources
§ Also: non-OSGi frameworks (e.g. Database)
§ Monitor your application
§ Provision changes if needed
RFC 183 – Implementation in Eclipse Concierge
43
D
44. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Cluster Information
FrameworkNodeStatus service provides metadata
§ Java version
§ OSGi version
§ OS version
§ IP address
§ Physical location (country, ISO 3166)
§ Metrics
§ tags / other / custom
§ Provisioning API (install/start/stop/uninstall bundles etc…)
44
D
45. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
OSGi R7 Release
46. © 2016 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
R7 Early Spec Draft Available
§ More Updates
§ Transaction Control
§ JPA Updates
§ Remote Service Intents
§ https://www.osgi.org/developer/specifications/drafts/
46
C