67
1

Pushing Java EE outside of the Enterprise - Home Automation

Embed Size (px)

DESCRIPTION

Presented during JavaOne (San Francisco Sept.2014)

Citation preview

Page 1: Pushing Java EE outside of the Enterprise - Home Automation

1

Page 2: Pushing Java EE outside of the Enterprise - Home Automation

Pushing  Java  EE  outside  of  the  EnterpriseHome  Automation

David  Delabassee  -­‐  @delabassee  Software  Evangelist  –  Java  EE  Oracle  September,  2014

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

2

Page 3: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Safe  Harbor  Statement

The  following  is  intended  to  outline  our  general  product  direction.  It  is  intended  for  information  purposes  only,  and  may  not  be  incorporated  into  any  contract.  It  is  not  a  commitment  to  deliver  any  material,  code,  or  functionality,  and  should  not  be  relied  upon  in  making  purchasing  decisions.  The  development,  release,  and  timing  of  any  features  or  functionality  described  for  Oracle’s  products  remains  at  the  sole  discretion  of  Oracle.

3

Page 4: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Program  Agenda

Home  Automation  

Java  EE  

Demo  

Wrap-­‐up  

1

2

3

4

4

Page 5: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Program  Agenda

Home  Automation  

Java  EE  

Demo  

Wrap-­‐up  

1

2

3

4

5

Page 6: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Home  Automation

• “Devices”  control  - Lights,  windows,  blinders,  audio,  doors,  wall-­‐plugs,  heating,  etc.    - From  different  “terminal”  

• Monitoring  &  dashboard  - Power  consumption,  weather,  motion/presence,  intrusion,  etc.  

• Scenario,  scene,  scheduling  &  automation  • “Flexible”  configuration  

Features

6

Page 7: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Home  Automation

• Better  control  • Improves  day-­‐to-­‐day  life  • Improves  security  • More  Eco  friendly  • …

Benefits

7

Page 8: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Home  Automation

• Crowded  space  • Just  the  beginning!    • IoT

Market

8

Page 9: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Home  Automation

• X10  /  PCLBUS  • RF433  • EnOcean  • Z-­‐Wave  • ZigBee  • Domologic

Technologies

9

• Domintell  • NikoBus  /  HomeControl  • Chacon  /  DI-­‐O  • Somfy  RTS  • io-­‐homecontrol  • VelBus  

• Domologic  • KNX  • BLE  • HomeKit  • Thread  • …  

Page 10: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Home  Automation

• Sensors  - Switches,  motion,  temperature,  CO2,  humidity,  wind  speed,  etc.  

• Actuators  - Lights,  blinders,  windows,  doors,  audio,  wall-­‐plugs,  etc.    

• Network  - Wired  or/and  wireless  +  TCP/IP  

• Hub,  box,  gateway  - Provides  added  values

Actors

10

Page 11: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Z-­‐Wave

• “Interoperable  wireless  RF-­‐based  communications  technology  designed  for  control,  monitoring  and  status  reading  applications  in  residential  and  light  commercial  environments.”  

• Proprietary  • Z-­‐Wave  Alliance  

- Consortium  of  250  manufacturers  and  service  providers  worldwide  

!http://www.z-­‐wavealliance.org

“Z-­‐Wave,  The  Interoperable  Standard”

11

Page 12: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Z-­‐Wave

• Meshed  wireless  network  • Range  100  ft  (open-­‐sight)  • 232  modules  per  controller  • Cheap  and  simple

“Z-­‐Wave,  The  Interoperable  Standard”

12

Page 13: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Connectivity

• Physical  connectivity  - Razberry-­‐Pi  Daughter  Card  

- Aeon  Labs  Z-­‐Stick,  …  

• Middleware  - OpenZwave  

- RaZberry  /  Z-­‐Wave-­‐me  /  Z-­‐Way  

- Domoticz,  …

13

Page 14: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Principles

14

Switch Z-­‐Wave  Chip

Z-­‐Wave  Midd. App.

11

Set(0)Set(0)Set(0)

Get()Get()

1  (inv.)

0  (valid.) 0

Page 15: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

In  real  life

15

Page 16: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

KNX

• ISO/IEC  14543-­‐3  • KNX  Association  

- 340  KNX  Members  in  37  countries  

- 40  KNX  National  Groups  

- 275  Training  Centres  in  51  countries  

!http://www.knx.org

“The  worldwide  STANDARD  for  home  and  building  control”

- 40,189  KNX  Partners  in  125  countries  

- 100  Scientific  Partners  in  28  countries  

- 13  User  clubs  in  12  countries

16

Page 17: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

KNX

• Media  - TP,  PL,  RF  and  IP  

• Engineering  Tool  Software  - Manufacturer  independent  configuration  software  tool  

- Design  and  configure  intelligent  home  and  building  KNX  installations

“The  worldwide  STANDARD  for  home  and  building  control”

17

Page 18: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Connectivity

• Physical  connectivity  - KNX/USB  Router  

- KNX/IP  Router  

- Eelectron  Raspberry  Pi  KNX  interface

18

Page 19: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Calimero

• Java  library  for  KNX/EIB  applications  - KNX  Network  services  and  data  encodings  

- Routing  

- Local  device  management  

- Datapoint  type  and  property  type  translation  

- ETS4  import,  …  

• Min  Java  2  Micro-­‐Edition  CDC  Foundation  Profile  • http://calimero.sourceforge.net

19

Page 20: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Config  only Optional

Principles

KNX  Bus

Bus  Power  Supply

IP  KNXKNX  

Output  module

KNX  Input  module

ETS

IP

Controller  Gateway  

110/220v

20

Page 21: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

In  real  life

21

Page 22: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Z-­‐Wave  Vs.  KNX  • Proprietary  • 232  devices  per  controller  • Residential  grade  • Wireless,  more  sensible  • Powered  via  batteries  and  PL  • Controller  is  the  Single  PoF  • Simple,  non  intrusive  • Cheap

• ISO  Standard  • Up  to  58.000  bus  devices  • Industrial,  professional  grade  • Wired,  more  reliable  • Powered  through  the  Bus  • No  real  PoF  • Complex,  intrusive  • Expensive

22

Page 23: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Program  Agenda

Home  Automation  

Java  EE  

Demo  

Wrap-­‐up  

1

2

3

4

23

Page 24: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Java  EE

ENTERPRISE EDITION

▪Batch ▪Concurrency ▪Simplified JMS

▪More annotated POJOs ▪Less boilerplate code ▪Cohesive integrated platform

DEVELOPER PRODUCTIVITY

▪WebSockets ▪JSON ▪Servlet 3.1 NIO ▪REST

MEETING ENTERPRISE

DEMANDS

Java EE 7

24

Page 25: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Java  EEENTERPRISE

EDITION

Java EE

25

• Connectivity  - EE  to  clients  

- EE  to  HA  

• Events

Page 26: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

JSON-­‐P

• API  to  parse  and  generate  JSON  • Streaming  API  (javax.json.stream)  

- Low-­‐level,  efficient  way  to  parse/generate  JSON  

- Similar  to  StAX  API  in  XML  world  

• Object  model  API  (javax.json)  - Simple,  easy  to  use  high-­‐level  API  

- Similar  to  DOM  API  in  XML  world

JSR  353

26

Page 27: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

public  class  Notification  {  !        //  bunch  of  Getters  &  Setters  !        public  String  toJson()  {                  JsonObject  model  =  Json.createObjectBuilder()                                  .add("source",  getSource())                                  .add("target",  getTarget())                                  .add("val",  getValue())                                  .add("type",  getType())                                  .add("medium",  getMedium())                                  .add("cyclic",  isCyclic())                                  .add("time",  getTimestamp())                                  .build();                  return  model;  }

27

JSON-­‐P

Page 28: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Java  API  for  Web  Socket

• Bidirectional  full-­‐duplex  messaging  - Initial  HTTP  handshake  - Over  a  single  TCP  connection  

• IETF  defined  protocol:  RFC  6455  • HTML5  /  W3C  defined  JavaScript  API  • JSR  356  - Client  &  Server  API

JSR  356

28

Page 29: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

@ServerEndpoint("/wsEndPt")  public  class  InboundWebsocket  implements  Serializable  {  !        static  Queue<Session>  queue  =  new  ConcurrentLinkedQueue<>();                  @OnOpen          public  void  openConnection(Session  session)  {                  queue.add(session);          }  !        public  void  onEvent(Notification  notif)  {                  sendAllEndpoints(notif.toJson());          }  !        …

WebSocket  Server  Endpoint  (1/2)

29

Page 30: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

!      …        public  static  synchronized  void  sendAllEndpoints(String  payload)  {                  try  {                          for  (Session  session  :  queue)  {                                  if  (session.isOpen())  {                                          session.getBasicRemote().sendText(payload);                                  }                          }                  }  catch  (IOException  e)  {                          //  Oooops                  }          }

WebSocket  Server  Endpoint  (2/2)

30

Page 31: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

       function  connect()  {                  wsocket  =  new  WebSocket('ws://'  +  window.location.host  +  '/dashboard/wsEndPt');                  wsocket.onmessage  =  onMessage;          }  !        function  onMessage(evt)  {           jsonData  =  JSON.parse(evt.data);     targetDiv  =  jsonData.target;     var  myDiv  =  document.getElementById(targetDiv);  !           if  (jsonData.type  ===  "switch")  {                     if  (jsonData.val  ===  "true")  value  =  "ON";                     else  value  =  "OFF";             }             else  value  =  jsonData.val;             $(myDiv).text(value);          }

WebSocket  Client  Endpoint  

31

Page 32: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Contexts  and  Dependency  Injection  for  Java  EE  1.1

• Core  component  model  - Enabled  by  default  in  implicit  bean  archives  

• Expanded  use  of  CDI  Interceptors  - Transactional  interceptors  - Method-­‐level  validation  interceptors  

• New  CDI  scopes  - @TransactionScoped  

- @FlowScoped

JSR  346

32

Page 33: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

CDI  Events

• Observer  Design  Pattern  • Defined  by    - A  java  object  (the  event  object)  - Event  Qualifier(s)

JSR  346

33

Page 34: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

CDI  EventsJSR  346

34

public  class  producerClass  {  !   @Inject  Event<SomeEvent>  someEvent;  !   public  void  someMethod(...)  {       ...       someEvent.fire(myEvent);     }  }

public  class  anotherClass  {  !   public  void  someObserver(@Observes  SomeEvent  someEvent  )  {       ...     }  !}

Page 35: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    | 35

!@MessageDriven(          …  )  public  class  KnxMdb  implements  KnxListener  {  !        @Inject          @HomeEvent          Event<Notification>  homeEvent;    !        @KnxMessage(type="sensor")          public  void  handleKnxSensor(Notification  notif)  {                  …                  homeEvent.fire(notif);                        }          !}

MDB

CDI  Events

Page 36: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

@ServerEndpoint("/wsEndPt")  public  class  InboundWebsocket  implements  Serializable  {  !!        @Inject          @HomeEvent          Event<Notification>  homeEvent;  !        @OnOpen          public  void  openConnection(Session  session)  {                  …          }  !        public  void  onEvent(@Observes  @HomeEvent  Notification  notif)  {                  sendAllEndpoints(notif.toJson());          }          …

CDI  Events

36

WebSocker  Server  Endpoint

Page 37: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Java  API  for  RESTful  Web  Services    2.0

• Filters  and  Interceptors  • Asynchronous  Processing  • Hypermedia  • Validation  • Client  API

JSR  339

37

Page 38: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

!!      private  void  zwaveCommand(String  url,  String  node,  boolean  val)  {         //http://host/ZWaveAPI/Run/devices[3].instances[0].commandClasses[0x25].Set(false)  !   String  zwaveUrl  =  url  +  node  +  ".Set("  +  val  +  ")";  !              private  final  Client  jaxrsClient  =  ClientBuilder.newClient();  !              String  zwaveResp  =  jaxrsClient.target(zwaveUrl)                                  .request(MediaType.TEXT_PLAIN_TYPE)                                  .get(String.class);        }  

JAX-­‐RS  Client

38

Page 39: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

!@Path("/zwave")  public  class  ZwaveEndpoint  {                  @Inject          @HomeEvent          Event<Notification>  homeEvent;  !        @PUT          @Path("/{id}/{val}/")          @Produces("text/plain")          public  String  swithZ(@PathParam("id")  String  id,  @PathParam("val")  String  val)  {                  Notification  notif  =  new  Notification(id,  "switch"  ,  val,  "ZWAVE");                  notif.setTarget(id);  //  target  is  required  to  identify  the  Zwave  device                  notif.setValue(val);                  homeEvent.fire(notif);                        }  !}

REST  Endpoint

39

Page 40: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Java  Connector  Architecture  1.7

• Resource  Adapter  - JCA  component  for  a  specific  EIS  

- Mediates  communication  between  the  container  and  the  EIS  by  means  of  contracts  

- Packaged  as  a  RAR  

• EIS  - Packaged  Applications,  ERP,  CICS,  mail  server,  MoM,  etc.  

• Contracts  - Lifecycle,  Connection  (inc.  pooling),  TX,  Work  Management,  CCI,  …

40

JSR  322

Page 41: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Java  Connector  Architecture  1.7

41

JSR  322

Java  EE  Application

Java  EE  Container

Resource  Adapter

EISOutbound

Inbound

Page 42: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Java  Connector  Architecture  1.7

42

JSR  322

Java  EE  Application

Java  EE  Container

Resource  Adapter

EISInboundMDB

Page 43: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

@MessageDriven  (              activationConfig  =  {                      @ActivationConfigProperty(                                propertyName="destinationLookup",  propertyValue="…"),                      @ActivationConfigProperty(                                propertyName="destinationType",  propertyValue="javax.jms.Queue")     }  )  !public  class  MyJmsMdb  implements  MessageListener  {                              @Override            public  void  onMessage(Message  message)  {            //do  the  work              }  !}

43

JMS

Message  Driven  Bean

Page 44: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Message  Driven  Bean

44

• “A  MDB  is  an  asynchronous  message  consumer…”  

• “A  MDB  is  invoked  by  the  container  as  a  result  of  the  arrival  of  a  message  at  the  destination  or  endpoint  that  is  serviced  by  the  MDB…”  

• “MDB  listen  to  an  Inbound  Ressource  Adapter”  

- Eg.  JMS  

Page 45: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    | 45

@MessageDriven(          activationConfig  =  {                    @ActivationConfigProperty(       propertyName  =  “knx",  propertyValue  =  "10.0.0.60")          }  )  !public  class  KnxMdb  implements  KnxListener  {  !          @Override            public  void  onMessage(Message  message)  {            //handle  the  KNX  Message              }  !}

Message  Driven  BeanKNX

Page 46: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    | 46

@MessageDriven(          activationConfig  =  {                    @ActivationConfigProperty(       propertyName  =  “knx",  propertyValue  =  "10.0.0.60")          }  )  !public  class  KnxMdb  implements  KnxListener  {  !        @KnxMessage(type="sensor")          public  void  handleKnxSensor(Notification  notif)  {                  …          }            

       @KnxMessage(type=“switch")          public  void  switchKnx(Notification  notif)  {                  …          }  !}

Message  Driven  BeanKNX

Page 47: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

• public  interface  KnxListener  {  }  - Will  be  implemented  by  the  MDB  • public  class  KnxResourceAdapter  implements  ResourceAdapter  {…}    - Do  the  actual  work,  without  real  constraints  (e.g.  threads)  - Handle  MDB  activation  

- Will  listen  on  the  KNX  bus  via  WorkManager  • public  class  KnxActivationSpec  implements  ActivationSpec  {…}    - Expose  RA  configuration  to  the  application  !

!

Inbound  RA

47

Page 48: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

       @Override          public  void  endpointActivation(MessageEndpointFactory  endpointFactory,               ActivationSpec  spec)             throws  ResourceException  {                    

               tSpec  =  (TrafficActivationSpec)  spec;                  Class  endpointClass  =  endpointFactory.getEndpointClass();                  tSpec.setBeanClass(endpointClass);                  tSpec.findCommandsInMDB();                    

               ObtainEndpointWork  work  =  new  ObtainEndpointWork(this,  endpointFactory);                  workManager.scheduleWork(work);                      }

Inbound  RA

48

Page 49: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

       public  void  findCommandsInMDB()  {  !                for  (Method  method  :  beanClass.getMethods())  {                          if  (method.isAnnotationPresent(KnxMessage.class))  {                                  KnxMessage  tCommand  =  method.getAnnotation(KnxMessage.class);                                  commands.put(tCommand.type(),  method);                          }                  }                       …          }

Inbound  RA

49

Page 50: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

//  KNX  ProcessedEvent  from  the  Calimero  stack  switch  (actor)  {                          case  "0/7/4":                                  messageType  =  "sensor";                                  notif.setType("humidity");                                  processedEvent  =  Float.toString(knxSensorHumidity(pe));                                  notif.setValue(processedEvent);  //  and  so  on…                                  break;          }          !if  (spec.getCommands().containsKey(messageType))  {  //  Does  the  MDB  support  this  message?            Method  mdbMethod  =  spec.getCommands().get(messageType);            try  {                      callMdb(mdb,  mdbMethod,  notif);            }  catch  (ResourceException  ex)  {  //  Ooops!  }  }  else  {  //  Unknown  command  ?!  }

KNX  (real)  Listener

50

Page 51: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

!        /*  Annotation  to  decorate  methods  in  the  MDB  */          @Target({ElementType.METHOD})          @Retention(RetentionPolicy.RUNTIME)          public  @interface  KnxMessage  {       String  type()  default  "";       String  info()  default  "";          }

KnxMessage

51

Page 52: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

private  Notif  callMdb(MessageEndpoint  mdb,  Method  command,  Notification  param)                          throws  ResourceException  {  !          try  {                        mdb.beforeDelivery(command);                        Object  ret  =  command.invoke(mdb,  param);                        notif  =  (Notif)  ret;            }  catch  (NoSuchMethodException  |  ResourceException  |  IllegalAccessException  |                              IllegalArgumentException  |InvocationTargetException  ex)  {                        //  MDB  invocation  error  :(                        …            }            mdb.afterDelivery();            return  notif;  }  

Inbound  connector

52

Page 53: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

KNX  MDB

53

@MessageDriven(          activationConfig  =  {                    @ActivationConfigProperty(       propertyName  =  “knx",  propertyValue  =  "10.0.0.60")          }  )  !public  class  KnxMdb  implements  KnxListener  {  !        @KnxMessage(type="sensor")          public  void  handleKnxSensor(Notification  notif)  {                  …          }                    @KnxMessage(type=“switch")          public  void  switchKnx(Notification  notif)  {                  …          }  !}

Page 54: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Java  Connector  Architecture  1.7

54

JSR  322

Java  EE  Application

Java  EE  Container

Resource  Adapter

EISOutbound

Page 55: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

And  more…

• EJB  • CDI  Interceptors  • JAX-­‐RS  Interceptors    • Concurrency  Utilities  for  Java  EE  • Java  Persistence  API  • JavaServer  Faces  • OpenMQ  Stomp  support  • Jersey  SSE,  MVC…

55

Page 56: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Program  Agenda

Home  Automation  

Java  EE  

Demo  

Wrap-­‐up  

1

2

3

4

56

Page 57: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Dashboard

• HTML  Client    - “Pure”  JS  - Real-­‐time  notifications  via  WebSocket  

- Control  devices  via  REST  

• Java  EE  7  backend  - KNX  (JCA)  &  Z-­‐Wave  (REST)  

- In  &  Outbound

57

Page 58: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

KNX  Sensors

KNX  Bus

Bus  Power  Supply

IP  KNXKNX  

Output  module

VPN

IP

Java  EE

110/220v

58

KNX  Output  module

KNX  Input  module

KNX  Input  module

KNX  Input  module

Z-­‐Wave  Output  module

Z-­‐Wave

KNX  Sensors

Z-­‐Wave  Input  module

Demo

JCA

REST

Page 59: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Program  Agenda

Home  Automation  

Java  EE  

Demo  

Wrap-­‐up  

1

2

3

4

59

Page 60: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

• Connectivity  - JAX-­‐RS,  JCA,  WebSocket,  JMS…  

• ‘Event’  driven  capabilities  - MDB,  CDI  event  

• Non  blocking  IO  • Asynchronous  • Scheduling  • Persistence

• Component  models  • UI  - JSF,  JAX-­‐RS  

• Container  - Lifecycle  - Monitoring  &  Management  

- Ressources  pooling  - Logging  - …

Java  EE  for  Home  Automation

60

Page 61: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

What’s  next

• PoC  - KNX,  Z-­‐Wave  &  InfraRed  

• Improvements  - Additional  ‘connectors’,  e.g.  RF433  - More  types,  e.g.  range  for  blinders  - State  Management  - User  interface  - Add  ‘scenario’s  - Leverage  Java  EE  more,  e.g.  CDI  Interceptors

61

Page 62: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Java  EE  and  IoT

• Connected  devices  • Messages    /  data  producer  • Data  aggregation  /  processing  - Deeper  in  the  network    

• Scaling  • Security

62

Page 63: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Java  EE  8

• CDI  2.0  • JMS  2.1  • MVC  1.0  • JAX-­‐RS  2.1  • JSON-­‐B  +  JSON-­‐P

TBC!

63

Page 64: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Resources

• The  Java  EE  7  Tutorial  - http://docs.oracle.com/javaee/7/tutorial/doc/home.htm  

• GlassFish  4.1  - http://glassfish.org  

• NetBeans  8.0.1  - http://netbeans.org

64

Page 65: Pushing Java EE outside of the Enterprise - Home Automation

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    | 65

Page 66: Pushing Java EE outside of the Enterprise - Home Automation

66

Page 67: Pushing Java EE outside of the Enterprise - Home Automation

67