Skip to content

eclipse-iofog/iofog-java-sdk

Repository files navigation

WARNING: STALE REPO

Please note this SDK has not been updated for a long period of time.

We recommend using the Golang SDK or Python SDK instead.
https://github.com/eclipse-iofog/iofog-go-sdk
https://github.com/eclipse-iofog/iofog-python-sdk

Community contributions to bring this SDK up to date are very welcome!

iofog-java-sdk

This module lets you easily build an ioElement. It gives you all the functionality to interact with ioFog via Local API. Additionally some useful methods to work with ioMessage.

  • send new message to ioFog (pushNewMessage)
  • fetch next unread messages from ioFog (fetchNextMessage)
  • fetch messages for time period and list of accessible publishers (fetchMessagesByQuery)
  • get config options (fetchContainerConfig)
  • connect to ioFog Control Channel via WebSocket (openControlWebSocket)
  • connect to ioFog Message Channel via WebSocket (openMessageWebSocket) and publish new message via this channel (sendMessageToWebSocket)

Code snippets:

ioFogClient implements all methods to communicate with ioFog (via local API). IOMessage represent all message communication between ioFog and Containers. IOMessageUtils class is convenient to encode and decode byte arrays. ioFogAPIListener - listener's interface for requests to ioFog.

set up custom host, port and container's ID (in case of no params default values for host and port will be used: 'ioFog', 54321):

   ioFogClient ioFogClient = new ioFogClient("iofog", 54321, "TEST_CONTAINER_ID");

REST calls

post new ioMessage to ioFog via REST call (could trigger onError, onBadRequest and onMessageReceipt listener's methods):

  IOMessage message = new IOMessage();
  MyIOFAPIListener ioFogListener = new MyIOFAPIListener(); // implementation of listener's interface
  ioFogClient ioFogClient = new ioFogClient("iofog", 54321, "TEST_CONTAINER_ID");
  ioFogClient.pushNewMessage(message, ioFogListener);

get list of ioMessages by time frame for accessible publishers from ioFog via REST call (could trigger onError, onBadRequest and onMessagesQuery listener's methods):

  IOMessage message = new IOMessage();
  MyIOFAPIListener ioFogListener = new MyIOFAPIListener(); // implementation of listener's interface
  ioFogClient ioFogClient = new ioFogClient("iofog", 54321, "TEST_CONTAINER_ID");
  ioFogClient.fetchMessagesByQuery(new Date(), new Date(), Collections.singleton("publisher_ID"), ioFogListener);

get list of next unread ioMessages via REST call (could trigger onError, onBadRequest and onMessages listener's methods):

  IOMessage message = new IOMessage();
  MyIOFAPIListener ioFogListener = new MyIOFAPIListener(); // implementation of listener's interface
  ioFogClient ioFogClient = new ioFogClient("iofog", 54321, "TEST_CONTAINER_ID");
  ioFogClient.fetchNextMessage(ioFogListener);

get container's config via REST call (could trigger onError, onBadRequest and onNewConfig listener's methods):

  IOMessage message = new IOMessage();
  MyIOFAPIListener ioFogListener = new MyIOFAPIListener(); // implementation of listener's interface
  ioFogClient ioFogClient = new ioFogClient("iofog", 54321, "TEST_CONTAINER_ID");
  ioFogClient.fetchContainerConfig(ioFogListener);

WebSocket(WS) calls

Open WS Control Channel to ioFog (could trigger onError and onNewConfigSignal listener's methods):

  IOMessage message = new IOMessage();
  MyIOFAPIListener ioFogListener = new MyIOFAPIListener(); // implementation of listener's interface
  ioFogClient ioFogClient = new ioFogClient("iofog", 54321, "TEST_CONTAINER_ID");
  ioFogClient.openControlWebSocket(ioFogListener);

Open WS Message Channel to ioFog (could trigger onError, onMessages and onMessageReceipt listener's methods):

  IOMessage message = new IOMessage();
  MyIOFAPIListener ioFogListener = new MyIOFAPIListener(); // implementation of listener's interface
  ioFogClient ioFogClient = new ioFogClient("iofog", 54321, "TEST_CONTAINER_ID");
  ioFogClient.openMessageWebSocket(ioFogListener);

Send ioMessage via WS Message Channel (pre-condition: WS Message Channel is open):

  IOMessage message = new IOMessage();
  ioFogClient.sendMessageToWebSocket(message);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages