Abstract Plugin Classes

Overview

The Hobson API has an AbstractHobsonPlugin class which provides plugin implementors convenience methods for performing tasks such as:

  • Managing plugin configuration
  • Publishing devices
  • Publishing global and device variables
  • Firing variable update notifications
  • Providing an event loop so that all plugin callbacks are invoked on the same thread

It is highly recommended to use AbstractHobsonPlugin as a starting point rather than implementing the HobsonPlugin interface directly.

Communication Channels

Is the job of all plugins to communicate with one or more smart devices. The channel used for communication will be dependent on the smart devices themselves. AbstractHobsonPlugin makes no assumptions about how communication with the smart devices it controls will occur. Those details are completely up to the plugin implementation.

Recognizing that there are certain communication channels that are frequently used, the Hobson API provides additional classes to support the following:

  • socket-based communication
  • serial-based communication
  • HTTP-based communication (e.g. REST)

The implementation of these classes use the excellent Netty asynchronous networking library. However, every effort is made to encapsulate that fact so extensive knowledge of Netty is unnecessary in most cases.

Socket and Serial Communication

For smart devices that require socket (TCP) or serial (RS-232) communication, the Hobson API provides the AbstractChannelObjectPlugin class. Socket-based and serial-based data channels are very similar in that they provide a readable stream of incoming bytes and a writable stream of outgoing bytes.

AbstractChannelObjectPlugin includes abstract method definitions for the following tasks:

  • Define how incoming bytes are converted into Java objects
  • Define how outgoing Java objects are converted into bytes
  • Configure the data channel prior to its use
  • Alert when the data channel has connected
  • Provide data that has been read from the data channel
  • Provide a method to write a Java object to the data channel
  • Alert when the data channel has disconnected

Additionally, AbstractChannelObjectPlugin will handle reconnection attempts should the data channel close unexpectedly.

HTTP Communication

For smart devices that require HTTP-based communication, the Hobson API provides the AbstractHttpClientPlugin class. This includes methods to perform various HTTP request methods (e.g. GET, POST, PUT, DELETE, etc.) in an asynchronous manner. When the HTTP request completed (successfully or unsuccessfully), callback methods are invoked to allow the plugin to take appropriate action.

Class Diagram

Below is a class diagram showing the plugin classes and a non-exhaustive list of the methods they provide: