-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Feature-Request-Checklist
Description
The CommunicationRegistration has an issue, related to the registration of message objects. Think about a Message, that has sub-types, that should be handled the same. Currently you have to provide 2 implementations of OnReceive[Single/Tripple/], because of java's generic system. You cannot have one class that handles both in the same way.
The reason
To reduce required boilerplate code, this behavior should be changed. The CommunicationRegistration should check for any super-classes. This way, you might have a super class, with 2 implementations and only register the super class.
Example
The following example should word and not throw an CommunicationNotSpecifiedException!
class SuperMessage {
// ....
}
class MessageB extends SuperMessage {
// ....
}
class MessageC extends SuperMessage {
// ....
}
// .....
CommunicationRegistration communicationRegistration = ...
communicationRegistration.register(SuperMessage.class)
.addFirst(System.out::println);
// ....
ConnectionContext context = ...
Session session = ...
MessageA a = new MessageA();
MessageB b = new MessageB();
communicationRegistration.trigger(context, session, a);
communicationRegistration.trigger(context, session, b);The output should be something like this:
class com.example.MessageA
class com.example.MessageB
Alternatives
Alternative 1
To check this, reflection is required. This may be an issue, since reflection are not improved in speed at runtime. Another alternative (at least at the start) might be this:
class SuperMessage {
// ....
}
class MessageB extends SuperMessage {
// ....
}
class MessageC extends SuperMessage {
// ....
}
// .....
CommunicationRegistration communicationRegistration = ...
communicationRegistration.register(SuperMessage.class)
.addFirst(System.out::println);
// ######## Alternative approach instead of dynamic detection:
communicationRegistration.map(MessageA.class).to(SuperMessage.class);
communicationRegistration.map(MessageB.class).to(SuperMessage.class);
// ....
ConnectionContext context = ...
Session session = ...
MessageA a = new MessageA();
MessageB b = new MessageB();
communicationRegistration.trigger(context, session, a);
communicationRegistration.trigger(context, session, b);This map method might look something like this:
<T> Mapper<T> map(Class<T> type);
// ....
class Mapper<T> {
public void to(Class<? super T> ) {
// ...
}
}Alternative 2
Instead of checking manually which class is connected to which other class, a method like this could be done:
public <T, S super T> Pipeline<S> register(Class<T> type, Class<S> superType) {
// ...
}which could map the pipeline to the super type and the type instead of only the type. This would ensure, that when either MessageA or the SuperMessage are passed, this Pipeline is called.