public abstract class Communicator extends Object
Requires a Transmitter to send and receive messages. Must be overloaded to implement a
specific format.
| Constructor and Description |
|---|
Communicator(Radio transmitter)
Handle required injections.
|
| Modifier and Type | Method and Description |
|---|---|
void |
accept(CommunicatorEvents events)
Use the injected
Transmitter to accept a client. |
void |
connect(String uri,
CommunicatorEvents events)
Use the injected
Transmitter to connect to server. |
void |
disconnect()
Close down the connection.
|
protected abstract Object |
makeCall(String uniqueId,
String action,
Object payload)
Create a call envelope to transmit to the server.
|
protected abstract Object |
makeCallError(String uniqueId,
String action,
String errorCode,
String errorDescription)
Create a call error envelope to transmit.
|
protected abstract Object |
makeCallResult(String uniqueId,
String action,
Object payload)
Create a call result envelope to transmit.
|
abstract Object |
packPayload(Object payload)
Convert a
Request/Confirmation into a formatted string. |
protected abstract Message |
parse(Object message)
Identify an incoming call and parse it into one of the following:
CallMessage a
request. |
void |
sendCall(String uniqueId,
String action,
Request request)
Send a new
Request. |
void |
sendCallError(String uniqueId,
String action,
String errorCode,
String errorDescription)
Send an error.
|
void |
sendCallResult(String uniqueId,
String action,
Confirmation confirmation)
Send a
Confirmation reply to a Request. |
abstract <T> T |
unpackPayload(Object payload,
Class<T> type)
Convert a formatted string into a
Request/Confirmation. |
protected Radio radio
public Communicator(Radio transmitter)
transmitter - Injected Transmitterpublic abstract <T> T unpackPayload(Object payload, Class<T> type) throws Exception
Request/Confirmation. This is useful for call
results, where the confirmation type isn't given.payload - the raw formatted payload.type - the expected return type.Exception - error occurred while converting.public abstract Object packPayload(Object payload)
Request/Confirmation into a formatted string.payload - the payload model.protected abstract Object makeCallResult(String uniqueId, String action, Object payload)
uniqueId - the id the receiver expects.action - action name of the feature.payload - packed payload.protected abstract Object makeCall(String uniqueId, String action, Object payload)
uniqueId - the id the receiver must reply with.action - action name of the feature.payload - packed payload.protected abstract Object makeCallError(String uniqueId, String action, String errorCode, String errorDescription)
uniqueId - the id the receiver expects.errorCode - an OCPP error code.errorDescription - an associated error description.protected abstract Message parse(Object message)
CallMessage a
request. CallResultMessage a response.message - the raw messageCallResultMessagepublic void connect(String uri, CommunicatorEvents events)
Transmitter to connect to server.uri - the url and port of the server.events - handler for call back events.public void accept(CommunicatorEvents events)
Transmitter to accept a client.events - handler for call back events.public void sendCallResult(String uniqueId, String action, Confirmation confirmation)
Confirmation reply to a Request.uniqueId - the id the receiver expects.confirmation - the outgoing Confirmationpublic void sendCallError(String uniqueId, String action, String errorCode, String errorDescription)
uniqueId - the id the receiver expects a response to.errorCode - an OCPP error CodeerrorDescription - a associated error description.public void disconnect()
Transmitter.Copyright © 2022. All rights reserved.