-
Notifications
You must be signed in to change notification settings - Fork 0
Connector Spec
BUGSwarm-Connector Connector
is a BUG application designed to showcase the BUGswarm middleware system. The connector uses a combination of ReST web services and XMPP messages to
publish information, respond to peer requests, and expose device and status information online.
Connector is designed to be usable by any general purpose Swarm peer but is optimized for the Bug Labs Swarm Management Application (Manager). This web app communicates with connector via XMPP. Any data that is registered or sent to Swarm server by default is meant for consumption by the Manager.
-
BUG
: The Bug Labs' BUG device. -
Connector
: Software running on a BUG device that's able to use BUGswarm messaging and access device information. -
Feed
: A named set of key/value pairs. Keys are Strings and values may be various serializable types. -
Management UI
: The web application used to manage and view BUG devices on a Swarm server. Serves as the primary internal application for BUGswarm. -
XMPP
: A messaging oriented middleware used in BUGswarm.
Connector deploys as a single OSGi bundle. It relies on an OSGi framework to call start() on its Activator class. It is an event-based application that listens for events from:
- The Configuration Admin Service : for local configuration changes via the web user interface.
- The OSGi Service Registry : for changes to services and hardware state.
- The Swarm XMPP server: for messages from peers.
Additionally, if active, Connector polls Swarm server for the set of member swarms via the ReST interface.
Connector will register the identity configuration web page with the local web server and load the stored identity configuration. If the identity information is missing or invalid the connector will then go into a passive mode.
A basic web interface will be present via the BUG web server that will allow a user to set the identity information. When the 'ACTIVATE' button on the webform is triggered the Connector bundle will receive an event. Once Connector receives valid identity information, it will initialize a connection with the Swarm Server.
The connector initializes itself with the Swarm server in the following steps:
- Determines if a
resource id
has already been set.Resource ID
s are server generated. If aresource id
is not available, a server request is made to generate one. Once generated the id is stored persistently so next the next time Connector starts theresource id
will be reused. - Create XMPP session with Swarm server.
- Retrieve list of all member swarms via rest call, see Connector Joins Swarm section.
- Register with OSGi service registry to receive events.
If any of these steps fail, the Connector returns to a passive state until a new identity-change event occurs.
When the Connector shuts down the following actions are taken:
- Cancel any frequency-enabled Feed requests.
- Unregister for OSGi events.
- Send anti presence to member swarms via XMPP.
- Close XMPP session with Swarm server.
- Send XMPP presence to swarm and register to receive presence, public and private message events.
- Send
Capabilities
feed as public message to Swarm.
- Send XMPP anti presence to Swarm, notifying peers of leaving.
- Cancel any active Frequency-enabled Feed requests associated with the Swarm.
- For each attached member swarm with at least one other participant, send
Feed Response
message.
- For each attached member swarm with at least one other participant, send
Capabilities
feed as public message.
- For each attached member swarm with at least one other participant, send
Capabilities
feed as public message. - Remove any frequency-based feed requests.
- Connector created private chat session with new peer.
- Connector sends
Capabilities
feed to new peer as a private message.
- Remove any frequency-based feed requests.
- Parse feed message.
- Load feed from local registry.
- Serialize feed into JSON with
Feed Response
format. - Send feed via private message to requester.
- Connector receives OSGi event, waits 2 seconds during which all subsequent events are ignored.
- Connector creates
Capabilities
feed. - Connector sends
Capabilities
feed to all member swarms.
This message is intended for the Management UI, and is only send from Connector peers running on BUG devices. It is a top-level description of the BUG device's current state.
{
"capabilities": {
<feed message>,
<modules message>
}
}
An example of the Capabilities
feed:
{
"capabilities": {
"feeds": [
"VonHippel"
],
"modules": {
"slot2": "vonhippel"
}
}
}
This message lists the names of available feeds on a given device.
{
"feeds": [
"Feed x",
"Feed y",
...
]
}
This message summaries the currently attached BUG modules on the device.
{
"modules": {
"<slotid>": "<module name>"
}
}
A feed request is a request from another peer on a member swarm for a local device feed. The peer discovers the feed names based on the Capabilities
message. The feed request message always originates from another peer.
{
"type": "get",
"feed": "<feed name>"
}
Additionally peers can add parameters to the request. Connector-specific parameters that are handled:
-
frequency
: specify that the request should be executed at an interval (unit is seconds) until the peer leaves the swarm or explicitly stopped. -
status
: when the value is"off"
, the request means that any previous frequency-based feed requests should be cancelled for the parameters passed.
A feed with parameters:
{
"type": "get",
"feed": "<feed name>",
"parameters": {
"<name>": <value>,
...
}
}
A feed request with a frequency of 1 minute:
{
'type': 'get',
'feed': 'Location',
'params': {
'frequency': 60
}
}
A feed request to specify a previous ongoing request should be cancelled:
{
'type': 'get',
'feed': 'Location',
'params': {
'status': 'off'
}
}
This is the response sent by a connector for a request from another peer.
{ 'name': "" 'feed': { "": , ... } }
An example of a feed response from the device-stats plugin:
{
"feed": {
"users": "2 users",
"wifi.status": "down",
"battery.current": "0",
"uptime": "08:01:23 up 8:01",
"battery.temp": "-413",
"storage.rootfs.used": "474172",
"swap.available": "0",
"wifi.signal": "0",
"swap.used": "0",
"wifi.packets.rx": "0",
"ram.used": "176185344",
"ram.available": "58769408",
"wifi.noise": "0",
"battery.status": "Full",
"battery.present": "1",
"battery.capacity": "100",
"wifi.packets.tx": "0",
"ram.total": "234954752",
"swap.total": "0",
"storage.rootfs.available": "1329628",
"load": "0.05",
"battery.voltage": "65531",
"storage.rootfs.total": "1900332"
},
"name": "bugswarm-devicestats"
}
This is where the connector itself lives, and classes that it needs that don't fall within the packages below.
Classes relating to the OSGi-facet of the connector. This includes the Activator which controls the lifecycle of the application, and OSGiHelper which gathers relevant OSGi-service references and events for the connector.
Classes relating to the web UI on BUG used to configure the user identity for swarm. This includes a servlet and ServiceTracker code to bind to the HTTPService.
Model classes used internally in connector.
Classes relating to the XMPP API for swarm server. This includes a specialized Java client API that wraps a general XMPP client API.
JUnit test classes, mock objects and support classes.