Details
-
Sub-task
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
None
Description
Currently all NetworkMessage implementations are created by hand which is inconvenient (e.g. one needs to declare constructors and getters). It is proposed to automatically generate these implementations using an annotation processor.
Implementation details
- Custom messages should be declared as interfaces extending NetworkMessage. Methods in these interfaces should correspond to the message fields, for example:
@Message(type = ACTION_REQUEST) public interface ActionRequest extends NetworkMessage { String groupId(); Command command(); }
- Every message interface should be annotated with the @Message interface, with a message type parameter of type short, unique across a module. All message types should be manually listed in an interface marked with the @MessageTypes annotation with a module identifier. For example:
@MessageTypes(moduleType = 10) class RaftMessageTypes { public final short ACTION_REQUEST = 1; }
- Message implementations should have a generated Builder interface for creating new messages:
public interface Builder { Builder command(Command cmd); Builder groupId(String groupId); ActionRequest build(); }
- Builder instances should be obtained using a generated factory, based on the current module type:
public interface RaftClientMessageFactory { ActionRequestBuilder actionRequest(); ActionResponseBuilder actionResponse(); // ... }
Attachments
Issue Links
- links to