Events

Events may be defined in two ways: as a XML element or as a class.

XML Element event. 

<EventName xmlns="tigase:demo">
  <sample_value>1</sample_value>
</EventName>

Serialized event class. 

public class SampleSerializedEvent implements Serializable {
    private JID data;
    public JID getData() {
        return this.data;
    }
    public void setData(JID data) {
        this.data = data;
    }
}

Event class. 

public class SampleEvent {
    private JID data;
    public JID getData() {
        return this.data;
    }
    public void setData(JID data) {
        this.data = data;
    }
}

Note

Events defined as XML element and class implementing Serializable interface will be distributed to all servers in cluster. Event SampleEvent will be broadcast only in the same instance what fired the event.

Requirements for class-based events
  • Default, explicit, public, paremeter-less constructor is mandatory.
  • If the event should be delivered to all cluster nodes then it MUST implement Serializable interface.
  • Variables serialisation follows Serializable semantics, which means that final, static nor transient fields will be skipped. What’s more, fields with null value will not be serialised neither.
Serialisation of class-based events

Class based events are serialized (if it is required and possible) to XML element. Name of XML element is taken from full name of class:

Class based event serialized to XML. 

<net.tigase.sample.SampleSerializedEvent>
    <data>sample@data.tigase.net</data>
</net.tigase.sample.SampleSerializedEvent>