Open Kilda Java Documentation
org.openkilda.messaging.BaseMessage Class Referenceabstract
Inheritance diagram for org.openkilda.messaging.BaseMessage:
org.openkilda.messaging.ctrl.AbstractDumpState org.openkilda.messaging.ctrl.RequestData org.openkilda.messaging.ctrl.ResponseData org.openkilda.messaging.Message org.openkilda.messaging.MessageData org.openkilda.messaging.model.rule.Rule org.openkilda.messaging.ctrl.state.CacheBoltState org.openkilda.messaging.ctrl.state.CrudBoltState org.openkilda.messaging.ctrl.state.OFELinkBoltState org.openkilda.messaging.ctrl.state.OFEPortBoltState org.openkilda.messaging.ctrl.state.OFESwitchBoltState org.openkilda.messaging.ctrl.state.ResorceCacheBoltState org.openkilda.messaging.ctrl.state.TransactionBoltState org.openkilda.messaging.ctrl.DumpStateBySwitchRequestData org.openkilda.messaging.ctrl.DumpStateResponseData org.openkilda.messaging.command.CommandMessage org.openkilda.messaging.ctrl.CtrlRequest org.openkilda.messaging.ctrl.CtrlResponse org.openkilda.messaging.error.ErrorMessage org.openkilda.messaging.HeartBeat org.openkilda.messaging.info.InfoMessage org.openkilda.messaging.command.CommandData org.openkilda.messaging.error.ErrorData org.openkilda.messaging.info.InfoData org.openkilda.messaging.model.rule.FlowDelete org.openkilda.messaging.model.rule.MeterDelete

Public Member Functions

 BaseMessage (@JsonProperty(TIMESTAMP) final long timestamp)
 
 BaseMessage ()
 
long getTimestamp ()
 
void setTimestamp (long timestamp)
 

Static Public Member Functions

static final< T extends BaseMessage > T getMessage (String json, Class< T > type) throws java.io.IOException
 
static final< T extends BaseMessage > T tryGetMessage (String json, Class< T > type)
 

Protected Attributes

long timestamp = 0L
 

Detailed Description

BaseMessage is the base class for all OpenKilda messages. There are several use cases we can solve with a common base class:

(1) we can use it for message deserialization everywhere, guaranteeing that that we have a known entity, and any failure to deserialize is really a failure and worthy of a Warning. (2) we can introduce common functionality that we'd like to have - Destination / Source / Return information. Possibly desired kilda topic to help with traceability.

Initial base member will have a timestamp field.

Definition at line 44 of file BaseMessage.java.

Constructor & Destructor Documentation

◆ BaseMessage() [1/2]

org.openkilda.messaging.BaseMessage.BaseMessage ( @JsonProperty(TIMESTAMP) final long  timestamp)

Instance constructor.

Parameters
timestampmessage timestamp

Definition at line 63 of file BaseMessage.java.

◆ BaseMessage() [2/2]

org.openkilda.messaging.BaseMessage.BaseMessage ( )

Create a BaseMessage with the current time as the timestamp

Definition at line 70 of file BaseMessage.java.

Member Function Documentation

◆ getMessage()

static final<T extends BaseMessage> T org.openkilda.messaging.BaseMessage.getMessage ( String  json,
Class< T >  type 
) throws java.io.IOException
static

Uses the standard MAPPER to retrieve a message, with the right type information

Parameters
jsonThe JSON string
typeThe expected type of the message
<T>The type
Returns
The deserialized message

Definition at line 101 of file BaseMessage.java.

◆ getTimestamp()

long org.openkilda.messaging.BaseMessage.getTimestamp ( )

Returns message timestamp.

Returns
message timestamp

Definition at line 80 of file BaseMessage.java.

◆ setTimestamp()

void org.openkilda.messaging.BaseMessage.setTimestamp ( long  timestamp)

Sets the timestamp.

Parameters
timestampThe timestamp, eg System.currentTimeMillis()

Definition at line 89 of file BaseMessage.java.

◆ tryGetMessage()

static final<T extends BaseMessage> T org.openkilda.messaging.BaseMessage.tryGetMessage ( String  json,
Class< T >  type 
)
static

Similar to consume message, but suppress the exception. This is useful if you want to see if the object can be mapped to the type, returning null if unsuccessful.

NB: this does have the potential of hiding problems; consider replacing if we can be more emphatic wrt when we deserialize.

Parameters
jsonThe JSON string
typeThe expected type of the message
<T>The type
Returns
The deserialized message, or null if unsuccessful

Definition at line 118 of file BaseMessage.java.

Member Data Documentation

◆ timestamp

long org.openkilda.messaging.BaseMessage.timestamp = 0L
protected

Message timestamp.

Definition at line 54 of file BaseMessage.java.


The documentation for this class was generated from the following file: