Skip to content

Latest commit

 

History

History
39 lines (32 loc) · 2.53 KB

File metadata and controls

39 lines (32 loc) · 2.53 KB

Extending the adapter

← Back to README

Adding a new connection (transport)

  1. Add a new value to the PlotJugglerConnectionType enum.
  2. Create a XxxConnectionConfiguration class implementing PlotJugglerConnectionConfiguration (its only required method is getType(), returning the new enum value). Follow the existing MqttConnectionConfiguration/UdpConnectionConfiguration/WebSocketConnectionConfiguration pattern: a no-arg constructor (for YAML), a convenience constructor, plain getters/setters, and a static fromYaml(String) delegating to YamlConfigLoader.
  3. Create a XxxPlotJugglerConnection class implementing PlotJugglerConnection (connect()/disconnect()/isConnected()/send(String channel, byte[] payload)).
  4. Wire the new pair into the switch in PlotJugglerConnectionFactory.create(...).

If the transport needs to know the configured wire format to behave correctly (as WebSocket does, to pick TEXT vs BINARY frames), accept a PlotJugglerMessageFormat parameter in the connection's constructor - it is already threaded through PlotJugglerConnectionFactory.create(configuration, messageFormat) and PlotJugglerConnectionManager, so no further plumbing is needed; other transports simply ignore it.

Adding a new message format

  1. Add a new value to the PlotJugglerMessageFormat enum.
  2. Create a XxxMessageSerializer class implementing PlotJugglerMessageSerializer (serialize(Object message, PlotJugglerChannelKind channelKind): byte[] and deserialize(byte[] payload): Map<String, PlotJugglerOutgoingMessage>).
    • For a self-describing format (like JSON/CBOR/MessagePack/BSON), this is usually a ~20-line wrapper around a Jackson ObjectMapper configured with the format's JsonFactory - see CborMessageSerializer/BsonMessageSerializer for the exact pattern to copy. The channelKind parameter can simply be ignored.
    • For a schema-based format (like Protobuf), channelKind (STATE/PROPERTY/EVENT/RELATIONSHIP, from PlotJugglerChannelKind) tells you which concept-specific shape to produce - see ProtobufMessageSerializer and the .proto files in proto/ as a full worked example, including how to ship/version a schema PlotJuggler needs to be told about separately.
  3. Wire the new serializer into the switch in PlotJugglerMessageFactory.getSerializer(...).

No other code needs to change: every transport already calls serializer.serialize(...) generically through PlotJugglerDigitalAdapter.sendOnChannel(...).