EzyAbstractResponse is an abstract base class used to construct and dispatch messages (responses) to specific recipients within the EzyFox server. To use it, you must extend this class and implement the sendData(EzyData data, EzyTransportType transportType) method to define how the constructed data is actually transmitted.
Key Capabilities
- Command & Parameters: Set the message command name and attach
EzyData parameters. - Recipient Management: Target specific
EzySession objects, EzyUser objects, or usernames. You can use the exclude flag to treat recipients as exclusiveRecipients (to be removed from the final recipient list). - Encryption: Toggle whether the response should be encrypted using
.encrypted(boolean). - Transport Control: Specify the
EzyTransportType (e.g., TCP) for the delivery. - Execution Lifecycle: Calling
.execute() calculates the final recipient list (subtracting exclusive recipients from the general recipients), builds the EzyData payload using the command and params, and triggers the sendData implementation.
Recipient Logic
When adding recipients, the exclude boolean determines the behavior:
exclude = false: Adds the session/user to the recipients set.exclude = true: Adds the session/user to the exclusiveRecipients set.
During .execute(), the final set of recipients is calculated as recipients.removeAll(exclusiveRecipients).
// Example of a concrete implementation
public class MyResponse extends EzyAbstractResponse<EzyZoneChildContext> {
public MyResponse(EzyZoneChildContext context) {
super(context);
}
@Override
protected EzyUserManager getUserManager(EzyZoneChildContext context) {
return context.getUserManager();
}
@Override
protected void sendData(EzyData data, EzyTransportType transportType) {
// Implementation to send data to the calculated recipients
for (EzySession session : getRecipients()) {
session.send(data, transportType);
}
}
}
// Usage pattern
myResponse
.command("login_success")
.params(myData)
.user(targetUser, false)
.encrypted(true)
.execute();