30
© 2002 - 2014 V2COM - Hardware + Software. All rights reserved Building a Reliable Remote Communication Device with Java ME 8 JavaOne San Francisco 2014 - CON2285 Leonardo Lima – V2COM ([email protected] , @leomrlima)

Building a Reliable Remote Communication Device with Java ME8 [CON2285]

Embed Size (px)

DESCRIPTION

JavaOne 2014 presentation about how to use Java ME 8 for building reliable devices!

Citation preview

Page 1: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Building a Reliable Remote Communication Device with Java ME 8

JavaOne San Francisco 2014 - CON2285 

Leonardo Lima – V2COM ([email protected], @leomrlima)

Page 2: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

About Leonardo Lima• Software Development Manager at V2COM

• V2COM representative at the JCP-EC: Java Community Process – Executive Committee

• Spec Lead - JSR 363 – Units of Measurement

[email protected] and/or @leomrlima

Page 3: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

• V2COM is a leading Latin American provider of Smart Grid technologies and Advanced Metering Infrastructure (AMI). Our offer includes hardware, software and services that can reduce losses and increase water and energy efficiency, currently connecting more than 1.000.000 devices.

Page 4: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Agenda• The definition of reliable

• What it means to be a reliable device?

• Java ME 8 improvements• What Java ME 8 brought to the game

• Java ME 8 applied• Improvements, applied

• More improvements to come• New JSRs and room for improvements

Page 5: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

The definition of reliableWhat it means to be a reliable device?

Page 6: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

What does reliable mean?• re·li·a·ble (adjective): that may be relied on; dependable in

achievement, accuracy, honesty, etc.

• Do not fail!

• Do not lose data!

• Do not let others tamper with your data!

Page 7: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Do not fail!• Protected against the environment

• Protected against hardware failures

• Protected against software failures

• Protected against attackers

Page 8: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Do not lose data!• It’s the device mission to ensure the data acquired is safely

stored in itself.

• It’s the device mission to ensure that data is safely transferred to the backend services.

Page 9: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Do not let others mess with your data!• Take into account all security aspects

• Authenticity: data you sent is sent from you, really

• Confidentiality: Only you and the right server sees the data

• Integrity: data received == data sent

Page 10: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Java ME 8 improvementsWhat Java ME 8 brought to the game

Page 11: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Improvements• Language Improvements (less bugs!)

• Service Loader pattern• Events and Inter-Midlet Communication

• Device I/O

• Security Improvements

• Shared Libraries

Java SE 8

Java ME 8 (CLDC 8)

Page 12: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Shared Libraries (LIBlets) • Can be uniquely updated, disabled/enabled.

• A shareable software component that one or more applications MAY use at runtime

• Save static footprint size by enabling multiple application suites to share the same common code without packaging them redundantly

• Reduced download times for applications that declare dependencies on shared components

Page 13: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Service Loader• Enables creation of microservices inside your device

• Independent services that can be uniquely updated, disabled/enabled.

• Monolithic firmware is now split into different services

Page 14: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Events• Object driven communication

• Publisher/Subscriber pattern• One-To-Many communication• Asynchronous delivery

• Caveat: Events are (silently) discarded if there are no subscribers

Page 15: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Inter-MIDlet Communication• Raw, bidirectional socket communication

• Fast and Synchronous!

• Reliable one-to-one communication• You know when the peer is there

• Just like “localhost” sockets

Page 16: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Network Security• TLS protocol enhancements

• SecureConnection and SecureServerConnection support TLS 1.2 • SecureServerConnection provides the server-side of a TLS connection

• DTLS protocol support for TLS over UDP •  SecureDatagramConnection provides client-side support for DTLS

Page 17: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Application Provisioning & Management

• Application Management System (AMS) allows fine grained control on what get installed

• App Management Agent manages local applications via the AMS api

Page 18: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Device I/O• Unified, object-oriented way to interact with I/O

• Basic I/Os already mapped• I2C, GPIO, SPI, UART, ADC, Watchdog, PWM, Pulse Counter

• Architecture is ready for extension with generic AbstractDevice, DeviceProvider

Page 19: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Language improvements• Improved collections

• Generics

• Autoboxing

• Static imports

• Enumerations

• Try with resources

• Better byte and string manipulation

• Events

• Logging

Page 20: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Java ME 8 appliedImprovements, applied to our use cases

Page 21: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Before…• We had 3 big blocks of code, merged as one on deploy

• Hardcore for hardware abstraction• Zion for commons infrastructure and AT• App for application logic

• One big file to manage (OTAP)

• Java 1.3 language…• Did I mean Latin?

Page 22: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

… and now• Multiple services and libraries

• Instead of big libraries

• Less boilerplate code• Enum, foreach, try with resources makes it less verbose, more agile

• Less ancient code• Easier for “desktop developers” to understand and join the fun

• Less “made in home” code• Many pieces are now already in the platform, like Device I/O, Events,

Logging• Less code for us to mantain

Page 23: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Shared Libraries

Crypto / Hashes

Concurrency

QueuesAdvanced String

& Byte Manipulation

Advanced Math Device protocols

Units and Measurements

Event and Bus

Page 24: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Services

(Safe) Storage

Data acquisition(Application) Remote transfer

LoggingBlack Box

External Sensor

Power management

WAN Management

Watchdogs

System Configuration

Firmware Update Management

Resource Management

Page 25: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

More improvements to come

New JSRs and room for improvements

Page 26: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

JSR 363 – Units of Measurement• JSR to beter type data that we acquire, targeting ME 8

• https://java.net/projects/unitsofmeasurement

import javax.measure.quantity.*;public class TemperatureRecord { private Time timestamp; private Temperature temperature; private String sensor;...getters, setters...}

Page 27: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

JSR 363 – Units of Measurement in JDK• Otávio Santana (SouJava, OpenJDK) is actively working in a SE

8 port of the JSR!

• Streams, Lambda, High precision (BigDecimal): guaranteed!

• Reducers, sorters, summation, group and filters.

List<Quantity<Time>> sortNaturalList = times

.stream()

.sorted(QuantityFunctions.sortNaturalDesc())

.collect(Collectors.toList());

Page 28: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Room for improvement• Configuration

• Concurrency utilities

• Standard protocols (MQTT, CoAP, JSON, HTTP, REST)

Page 29: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

Q?

Page 30: Building a Reliable Remote Communication Device with Java ME8 [CON2285]

© 2002 - 2014 V2COM - Hardware + Software. All rights reserved

[email protected]

@leomrlima

www.v2com.mobi