Package org.kaaproject.kaa.client.event

Provides implementation of event subsystem Endpoint is able to send or receive events when it is attached to user.

See: Description

Package org.kaaproject.kaa.client.event Description

Provides implementation of event subsystem Endpoint is able to send or receive events when it is attached to user. See EndpointRegistrationManager

Usage

For the example, we have one event class family named "ExampleClassFamily":

  [
      {
          "namespace": "org.kaa.example.events",
          "name": "TestEvent",
          "type": "record",
          "fields": []
      }
  ]
  
  

Getting ExampleClassFamily instance

  EventFamilyFactory factory = Kaa.getClient().getEventFamilyFactory();
      ExampleClassFamily classFamily = factory.getExampleClassFamily();
  
  

Sending an event

Sending event to all available recipients

  classFamily.sendEventToAll(new TestEvent());
  
  

Sending event to a concrete target

  String target = "lZjEzq4E/D5aWjXYuG1N2sKYt/U="; // Target's public key hash.
      classFamily.sendEvent(new TestEvent(), target);
  
  

Sending bulk of events

Event blocks in sdk are identified by TransactionId key.
Create new empty events block:
  TransactionId blockId = Kaa.getClient().getEventFamilyFactory().startEventsBlock();
  
  
Events block can contain events from different event class families.
Add events to a block:
  TestEvent event1 = new TestEvent();
       TestEvent event2 = new TestEvent();
       // Sending event1 to a concrete target and broadcasting event2 to all endpoints.
       String target = "lZjEzq4E/D5aWjXYuG1N2sKYt/U="; // Target's public key hash.
       classFamily.addEventToBlock(blockId, event1, target);
       classFamily.addEventToBlock(blockId, event2);
  
  
If events block is completed use next call to send events:
  Kaa.getClient().getEventFamilyFactory().submitEventsBlock(blockId);
  
  
In order to remove events block (events will not be sent) use:
  Kaa.getClient().getEventFamilyFactory().removeEventsBlock(blockId);
  
  

Receiving an event

Register event listener

  classFamily.addEventFamilyListener(new ExampleClassFamily.ExampleClassFamilyListener {
          \@Override
          public void onEvent(TestEvent event, String source) {
              System.out.println("Received event TestEvent!");
          }
      });
  
  

Searching for event recipients

  Kaa.getClient().getEventListenersResolver().findEventListeners(Arrays.asList("org.kaa.example.events.TestEvent"), new FetchEventListeners() {
          \@Override
          public void onEventListenersReceived(List<String> eventListeners) {
              // process response
          }
          
          \@Override
          public void onRequestFailed() {
          }
          
      });
  
  
NOTE: Passing multiple events fqns means that recipient MUST support receiving ALL mentioned events.

Copyright © 2015. All rights reserved.