48
Java 5 PSM for DDS: Revised Submission 2 MARS – Santa Clara, CA – December 2010 Presenter: Rick Warren, RTI Submitting POCs: Rick Warren, RTI: [email protected] Angelo Corsaro, PrismTech: [email protected] document number: mars/2010-12-22 1 Tuesday, December 7, 2010

Java 5 Language PSM for DDS: Final Submission

Embed Size (px)

DESCRIPTION

This presentation describes the specification "Java 5 Language PSM for DDS." It was given to the MARS Task Force on Tuesday, December 7, 2010. The specification was recommended for adoption later in the week. The specification improves code portability, usability, and performance for applications that use Data Distribution Service (DDS) technology. See also http://code.google.com/p/datadistrib4j/.

Citation preview

Page 1: Java 5 Language PSM for DDS: Final Submission

Java 5 PSM for DDS:Revised Submission 2MARS – Santa Clara, CA – December 2010

Presenter: Rick Warren, RTI

Submitting POCs: Rick Warren, RTI:

[email protected] Angelo Corsaro, PrismTech:

[email protected]

document number: mars/2010-12-22

1Tuesday, December 7, 2010

Page 2: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Agenda

2

2Tuesday, December 7, 2010

Page 3: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Agenda

Specification Overview Goals and Principles Process

Better Living Through Source Code License Bootstrapping Publishing Data Reading Data Getting and Setting QoS Java Type Representation

2

2Tuesday, December 7, 2010

Page 4: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Goals & Design Principles

3

3Tuesday, December 7, 2010

Page 5: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Goals & Design Principles

Improve user experience standardNamingConvention Standard containers (e.g. java.util.List) Standard enumerations Error conditions reported with exceptions Serializable, Cloneable value types Simplified method overloads

3

3Tuesday, December 7, 2010

Page 6: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Goals & Design Principles

Improve user experience standardNamingConvention Standard containers (e.g. java.util.List) Standard enumerations Error conditions reported with exceptions Serializable, Cloneable value types Simplified method overloads

Improve type safety Generics

3

3Tuesday, December 7, 2010

Page 7: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Goals & Design Principles

Improve user experience standardNamingConvention Standard containers (e.g. java.util.List) Standard enumerations Error conditions reported with exceptions Serializable, Cloneable value types Simplified method overloads

Improve type safety Generics

Improve performance Loanable memory No critical-path memory allocation (unlike IDL PSM)

3

3Tuesday, December 7, 2010

Page 8: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Goals & Design Principles

Improve user experience standardNamingConvention Standard containers (e.g. java.util.List) Standard enumerations Error conditions reported with exceptions Serializable, Cloneable value types Simplified method overloads

Improve type safety Generics

Improve performance Loanable memory No critical-path memory allocation (unlike IDL PSM)

Improve portability Build apps against standard interfaces; decide at run time which impl to use Host multiple implementations (or versions) within same JVM Dynamic loading and unloading

Play nicely with containers, e.g. Java EE and OSGi Don’t require non-constant static state

3

3Tuesday, December 7, 2010

Page 9: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

State of the Proposal

4

4Tuesday, December 7, 2010

Page 10: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

State of the Proposal

Ready for implementation All mandatory requirements satisfied User vetting process begun

Private conversations with Java power users Publicly available code repository at http://

code.google.com/p/datadistrib4j/ So far, reviewers enthusiastic

Positive AB review Doug Tolbert: content Sridhar Iyengar: license

Will ask for vote to recommend adoption this week

4

4Tuesday, December 7, 2010

Page 11: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Source Code License & Copyright

5

5Tuesday, December 7, 2010

Page 12: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Source Code License & Copyright

Principles Every vendor, user will receive code from OMG

Need to know their rights Need free access to spec, according to OMG principles

OMG must not dictate vendors’ business models Open source, shared source, closed source must be allowed ...under variety of licenses

5

5Tuesday, December 7, 2010

Page 13: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Source Code License & Copyright

Principles Every vendor, user will receive code from OMG

Need to know their rights Need free access to spec, according to OMG principles

OMG must not dictate vendors’ business models Open source, shared source, closed source must be allowed ...under variety of licenses

License Apache 2.0 (permissive but GPL-compatible) Use is royalty-free, unlike BSD (proposed last time) Requires acknowledgement of license, copyright holders

from redistributors

5

5Tuesday, December 7, 2010

Page 14: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Source Code License & Copyright

Principles Every vendor, user will receive code from OMG

Need to know their rights Need free access to spec, according to OMG principles

OMG must not dictate vendors’ business models Open source, shared source, closed source must be allowed ...under variety of licenses

License Apache 2.0 (permissive but GPL-compatible) Use is royalty-free, unlike BSD (proposed last time) Requires acknowledgement of license, copyright holders

from redistributors

Copyright OMG, RTI, PrismTech hold copyright

i.e. OMG + submitters, per OMG conventions

5

5Tuesday, December 7, 2010

Page 15: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Bootstrapping a DDS Java Application

6

6Tuesday, December 7, 2010

Page 16: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Bootstrapping a DDS Java Application

Design pattern: API is abstract, stateless Interfaces when possible; stateless abstract classes when not Doesn’t dictate state or other implementation to vendors

Design pattern: multiple DDS’s coexist in JVM i.e. Even “singletons” are not

Challenge: How do you create the first object?

6

6Tuesday, December 7, 2010

Page 17: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Bootstrapping a DDS Java Application

Design pattern: API is abstract, stateless Interfaces when possible; stateless abstract classes when not Doesn’t dictate state or other implementation to vendors

Design pattern: multiple DDS’s coexist in JVM i.e. Even “singletons” are not

Challenge: How do you create the first object?

Solution: Bootstrap class Represents DDS implementation Step 1: Bootstrap.createInstance(/*system property*/) Singletons: DomainParticipantFactory.getInstance(myBstrap) If no PIM factory: Duration.newDuration(myBstrap) Get back there from anywhere: myDuration.getBootstrap() * Note: API change since previous submission

6

6Tuesday, December 7, 2010

Page 18: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Example: Publishing Dataimport org.omg.dds.domain.*; import …;

// Join domain:DomainParticipantFactory factory = DomainParticipantFactory.getInstance( Bootstrap.createInstance());DomainParticipant dp = factory.createParticipant();

// Create topic with implicit type registration:Topic<Greeting> tp = dp.createTopic( "My Topic", Greeting.class);

// Create publishing entities:Publisher pub = dp.createPublisher();DataWriter<Greeting> dw = pub.createDataWriter(tp);

// Publish data:try { dw.write(new Greeting("Hello, World"));} catch (TimeoutException tx) { tx.printStackTrace();}

// Dispose of all entities:dp.close();

7

7Tuesday, December 7, 2010

Page 19: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Example: Publishing Dataimport org.omg.dds.domain.*; import …;

// Join domain:DomainParticipantFactory factory = DomainParticipantFactory.getInstance( Bootstrap.createInstance());DomainParticipant dp = factory.createParticipant();

// Create topic with implicit type registration:Topic<Greeting> tp = dp.createTopic( "My Topic", Greeting.class);

// Create publishing entities:Publisher pub = dp.createPublisher();DataWriter<Greeting> dw = pub.createDataWriter(tp);

// Publish data:try { dw.write(new Greeting("Hello, World"));} catch (TimeoutException tx) { tx.printStackTrace();}

// Dispose of all entities:dp.close();

7

// Explicit TypeSupport w/ default name:Topic<Greeting> tp = dp.createTopic( "My Topic", TypeSupport.newTypeSupport( Greeting.class, dp.getBootstrap()));

// Explicit TypeSupport w/ custom name:Topic<Greeting> tp = dp.createTopic( "My Topic", TypeSupport.newTypeSupport( Greeting.class, "MyType", dp.getBootstrap()));

}or

7Tuesday, December 7, 2010

Page 20: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Example: Reading Data

...// Create subscribing entities:Subscriber sub = dp.createSubscriber();DataReader<Greeting> dr = sub.createDataReader( topic, sub.getDefaultDataReaderQos(), listener, null /* all status changes */);

...

class MyListener extends DataReaderAdapter<Greeting> { @Override public void onDataAvailable(DataAvailableStatus<Greeting> status) { DataReader<Greeting> dr = status.getSource(); Sample.Iterator<Greeting> it = dr.take(/* loan, or pass List to copy */); try { while (it.hasNext()) { Sample<Greeting> smp = it.next(); // SampleInfo stuff is built into Sample: InstanceHandle inst = smp.getInstanceHandle(); // Data accessible from Sample; null if invalid: Greeting dt = smp.getData(); // ... } } finally { it.returnLoan(); } }}

8

8Tuesday, December 7, 2010

Page 21: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Example: Reading Data

...// Create subscribing entities:Subscriber sub = dp.createSubscriber();DataReader<Greeting> dr = sub.createDataReader( topic, sub.getDefaultDataReaderQos(), listener, null /* all status changes */);

...

class MyListener extends DataReaderAdapter<Greeting> { @Override public void onDataAvailable(DataAvailableStatus<Greeting> status) { DataReader<Greeting> dr = status.getSource(); Sample.Iterator<Greeting> it = dr.take(/* loan, or pass List to copy */); try { while (it.hasNext()) { Sample<Greeting> smp = it.next(); // SampleInfo stuff is built into Sample: InstanceHandle inst = smp.getInstanceHandle(); // Data accessible from Sample; null if invalid: Greeting dt = smp.getData(); // ... } } finally { it.returnLoan(); } }}

8

“Listener” is interface: implement all.

“Adapter” is no-op class: override what

you want.

8Tuesday, December 7, 2010

Page 22: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Example: Reading Data

...// Create subscribing entities:Subscriber sub = dp.createSubscriber();DataReader<Greeting> dr = sub.createDataReader( topic, sub.getDefaultDataReaderQos(), listener, null /* all status changes */);

...

class MyListener extends DataReaderAdapter<Greeting> { @Override public void onDataAvailable(DataAvailableStatus<Greeting> status) { DataReader<Greeting> dr = status.getSource(); Sample.Iterator<Greeting> it = dr.take(/* loan, or pass List to copy */); try { while (it.hasNext()) { Sample<Greeting> smp = it.next(); // SampleInfo stuff is built into Sample: InstanceHandle inst = smp.getInstanceHandle(); // Data accessible from Sample; null if invalid: Greeting dt = smp.getData(); // ... } } finally { it.returnLoan(); } }}

8

“Listener” is interface: implement all.

“Adapter” is no-op class: override what

you want.

Statuses extend java.util.EventObject

8Tuesday, December 7, 2010

Page 23: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Example: Get QoS

// QoS is a bean-style property of the entity:DataReaderQos qos = myReader.getQos();

// Get specific policy:ReliabilityQosPolicy.Kind rKind = qos.getReliability().getKind();

// EntityQos is a Map from QosPolicy.Id to QosPolicy:for (QosPolicy policy : qos.values()) { // Iterate over all policies, standard or not. // ...}

9

9Tuesday, December 7, 2010

Page 24: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Example: Set QoS

// Call modify() to get a mutable copy of the QoS:ModifiableDataReaderQos qos = myReader.getQos().modify();

// Modifiable version provides setters:qos.getReliability().setKind( ReliabilityQosPolicy.Kind.RELIABLE);

// QoS setter accepts modifiable or unmodifiable objects:myReader.setQos(qos);myReader.setQos(myOtherReader.getQos());

10

10Tuesday, December 7, 2010

Page 25: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Why the modifiable/unmodifiable pattern?

11

11Tuesday, December 7, 2010

Page 26: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Why the modifiable/unmodifiable pattern?

Easy to use correctly qos = entity.getQos();

Hard to get wrong qos = new DataReaderQos(); // ERROR!

// What state does ‘qos’ have before the next line?entity.getQos(qos);

What does this mean:myDataReader.getQos().setReliability(…)

11

11Tuesday, December 7, 2010

Page 27: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Why the modifiable/unmodifiable pattern?

Easy to use correctly qos = entity.getQos();

Hard to get wrong qos = new DataReaderQos(); // ERROR!

// What state does ‘qos’ have before the next line?entity.getQos(qos);

What does this mean:myDataReader.getQos().setReliability(…)

Fast to get Just return a pointer No allocation or deep copy needed

Good for concurrency Share immutable objects freely without locking

11

11Tuesday, December 7, 2010

Page 28: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Java Type Representation

12

12Tuesday, December 7, 2010

Page 29: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Java Type Representation

Goal: Write the following code:

public class MyPojo /*extends/implements…*/ { private int foo; private Bar[] baz; public void doStuff() { … }}…Topic<MyPojo> t = dp.createTopic( "My Topic", MyPojo.class);

12

12Tuesday, December 7, 2010

Page 30: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Java Type Representation

13

13Tuesday, December 7, 2010

Page 31: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Java Type Representation

Leverage the knowledge of Java developersLeverage the code they already have

13

13Tuesday, December 7, 2010

Page 32: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Java Type Representation

Leverage the knowledge of Java developersLeverage the code they already have

Observations: JRE already provides type definition constructs

Primitive types, strings, lists (sequences), classes (structures), enumerations, annotations

Types to be sent over network already indicate that …by implementing java.io.Serializable

…including which fields should not be sent …with the transient keyword

13

13Tuesday, December 7, 2010

Page 33: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Java Type Representation

14

14Tuesday, December 7, 2010

Page 34: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Java Type Representation

Approach: Define DDS type on the fly based on run-time introspection of Java class

14

14Tuesday, December 7, 2010

Page 35: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Java Type Representation

Approach: Define DDS type on the fly based on run-time introspection of Java class

Convenience feature for non-real-time Java systems Reflection slower than compiled generated code If other languages are used, type definitions must

be “duplicated”

Does not: ...replace, modify other Language Bindings ...impact serialization, therefore is interoperable

14

14Tuesday, December 7, 2010

Page 36: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Java Type Representation: What It Does

15

15Tuesday, December 7, 2010

Page 37: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Java Type Representation: What It Does

Defines mappings JRE concepts DDS concepts int Int32 (IDL long) double Float64 (IDL double) java.util.List Sequence Serializable class Structure

Allows customization to support non-Java DDS concepts e.g. unsigned primitives, narrow vs. wide strings, unions Mechanism: @SerializeAs and other annotations

15

15Tuesday, December 7, 2010

Page 38: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Java Type Representation: Example

Java IDL

16

16Tuesday, December 7, 2010

Page 39: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Java Type Representation: Example

Javapackage com.acme;

IDLmodule com { module acme {

16

16Tuesday, December 7, 2010

Page 40: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Java Type Representation: Example

Javapackage com.acme;

class Fooimplements Serializable {

IDLmodule com { module acme {

struct Foo {

16

16Tuesday, December 7, 2010

Page 41: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Java Type Representation: Example

Javapackage com.acme;

class Fooimplements Serializable { @Key int theInt;

IDLmodule com { module acme {

struct Foo { @Key long theInt;

16

16Tuesday, December 7, 2010

Page 42: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Java Type Representation: Example

Javapackage com.acme;

class Fooimplements Serializable { @Key int theInt; transient float theFlt;

IDLmodule com { module acme {

struct Foo { @Key long theInt;

16

16Tuesday, December 7, 2010

Page 43: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Java Type Representation: Example

Javapackage com.acme;

class Fooimplements Serializable { @Key int theInt; transient float theFlt; String theStr;

IDLmodule com { module acme {

struct Foo { @Key long theInt;

string theStr;

16

16Tuesday, December 7, 2010

Page 44: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Java Type Representation: Example

Javapackage com.acme;

class Fooimplements Serializable { @Key int theInt; transient float theFlt; String theStr; @SerializeAs(UINT_64) BigInteger theUInt;

IDLmodule com { module acme {

struct Foo { @Key long theInt;

string theStr;

unsigned long theUInt;

16

16Tuesday, December 7, 2010

Page 45: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Java Type Representation: Example

Javapackage com.acme;

class Fooimplements Serializable { @Key int theInt; transient float theFlt; String theStr; @SerializeAs(UINT_64) BigInteger theUInt; String[] theArr;}

IDLmodule com { module acme {

struct Foo { @Key long theInt;

string theStr;

unsigned long theUInt; sequence<string> theArr;};

}}

16

16Tuesday, December 7, 2010

Page 46: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Summary

Proposed specification is complete Provides (the first) run-time-portable API for DDS Improves performance over IDL-based API Improves type safety over IDL-based API Simplifies type handling Satisfies all mandatory requirements

We will ask for your vote on Thursday Vote to vote Vote to recommend adoption

17

17Tuesday, December 7, 2010

Page 47: Java 5 Language PSM for DDS: Final Submission

Q & A

18

18Tuesday, December 7, 2010

Page 48: Java 5 Language PSM for DDS: Final Submission

Copyright © 2010 RTI - All rights Reserved

Appendix: Changes Since Cambridge

Changed license from BSD to Apache

Modified package organization Modifiable value type variants in parallel packages

to simplify package lists Moved contents of org.omg.dds.type.annotation to

org.omg.dds.type Consolidated statuses in org.omg.dds.core.status

package to match C++ proposal Moved built-in topic data interfaces to

org.omg.dds.topic package to match C++ proposal

All new unchecked exceptions now extend common base class

Improvements to value types All setters return enclosing object to facilitate

method chaining Improvements to Time and Duration

Leverage TimeUnit Address Y2038 problem

Renamed Qos to EntityQos to match C++ proposal

19

Simplified object creation Renamed Context to Bootstrap to avoid confusion with

JNDI Reduced number of entity and condition factory

method overloads Pass Bootstrap as argument to factories; don’t make it

the factory for everything (required changing some interfaces into abstract classes)

Improved DDS-XTypes APIs, aligned with FTF Simplified Dynamic Language Binding by removing

unneeded methods Improved overloads in built-in type writers Fixed method names in TypeLibraryElement “union”

Added JavaDoc Added JavaDoc building to packaging script Included some documentation from DDS specification

(not done yet)

Made some “enumerations” more extensible by vendors Replaced status kind mask with collection of status

classes Made QosPolicy.Id an abstract class, not an

enumeration

19Tuesday, December 7, 2010