2. What is DeviceHive?
DeviceHive is an Open Source Machine-to-Machine
(M2M) framework. It contains a set of services and
components that allow establishing a two-way
communication with remote devices using cloud as a
middleware. The devices can be anything connected: sensor
networks, smart meters, security systems, telemetry, or
smart home devices.
3. What is inside?
• JavaEE or .NET-based server
• REST и Websocket APIs for devices and Clients
• Data storage: Postgresql and NoSQL (MongoDB).
• Device: Linux C/C++, .NET, .NET Micro Framework, Java,
Python, MicroChip and AVR native C.
• Client: Windows 8, iOS, Android, Windows Phone 7 and
8,.NET, HTML5/JavaScript.
4. What is inside?
REST, Websockets
REST, Websockets
REST, Websockets
binary
Client: something that manages DevicesDevice: almost everything.
Gateway: fake Device that quite smart to connect to
DH and to manage other Devices.
Future: merge everything to one entity.
5. How does it work?
Client
Device
commandsnotifications
commands
notifications
6. Access control system: Networks
Client DeviceNetwork
1n n n
AccessKey: allows authenticated client to act on behalf of Device
• Network list
• Device list
• IP/Domain
• Actions
Basic access control. User has access to Device if and only if he has access to network
7. Access control system: AccessKeys
AccessKey: more smart security system similar to MAC
Privilege contains
• Network list
• Device list
• IP/Domain
• Actions
Client PrivilegeAccessKey
11 n n
8. Java server implementation
• Java EE 7 platform:
• JAX-RS 2.0
• Websocket API 1.0
• JPA 2.1
• EJB 3.2
• CDI 1.1
• PostgreSQL 9.x
• Glassfish 4, 4.1 as reference JEE7 implementation
• Wildfly 8, 8.1 was preliminary tested. There were some issues with
websockets, but now the application works generally fine.
9. Feedback
• “We’d like to be able to deploy it to Tomcat”
Existing code is built to .war application.
• “Do I need JEE application server? Oh.”
• “Deployment procedure is quite hard.”
10. OK, let’s try to simplify it. Spring?
• Again not so new technology stack, but quite rich.
• Application can be deployed almost everywhere. Only servlet container is needed (Tomcat, Jetty,..)
• Migration would not be so hard.
• JAX-RS -> Spring MVC or using Jersey (no code migration in fact)
• EJB -> Spring @Service + spring-tx
• Bean Validation API -> the same, just configuration changes.
• JPA -> no changes again
• CDI -> Spring DI (CDI events may be an issue).
• Spring Boot.
11. Spring Boot.
• Easy deployment
There are many “default” configurations that could be applied
automatically.
• Standalone Spring-based applications
• “fat” executable jar
• archive with two directories: /lib with jars and /bin with unix
shell and windows batch scripts.
• .war packaging is still possible
15. Starter POMs
• dependency descriptors, cover all required dependencies.
• named spring-boot-starter-*
Web applications: Use spring-boot-starter-web – attaches default servlet container and spring web dependencies.
spring-boot-starter-tomcat (default one)
spring-boot-starter-jetty
spring-boot-starter-undertow
• Versions
• sprint-boot-starters parent pom
• your own one.
16. Customizing the application
• Main configuration file: application.properties
• Read from classpath or location can be overridden:
java -jar myproject.jar --spring.config.location=...
• Spring Profiles
--spring.profiles.active=dev,qa,etc…
application-{profile}.properties is used
17. DataSources deployment
• Embedded datasources:
• embedded H2, HSQL and Derby databases
• just specify spring-jdbc and add runtime DB dependency
• useful for testing
• Production datasource
• add ‘spring-boot-starter-jdbc’ started pom
• specify spring.datasource.* properties (url, user, pw, driver)
• JNDI is also supported
18. Databases initialization
• JPA - spring.jpa.generate-ddl (good for testing only)
• Spring JDBC
Two files: schema.sql, data.sql or schema-${db}.sql and data-{db}.sql
Again looks file for testing purposes only.
• Embedded Database migration tools
• Flyway
SQL files in classpath:db/migration
• Luqibase
Looks fine for production deployments.
20. Servlet container customization and other features
• Since container is embedded, it can be customized by the application
• Basic options, e.g.
server.port
server.address
server.sessionTimeout
• Container-specific customizations:
TomcatEmbeddedServletContainerFactory
JettyEmbeddedServletContainerFactory
UndertowEmbeddedServletContainerFactory