Good day. i`m new to akka so can you explain me some aspects of akka-typed usage?
as far as i concerned base feature of akka typed is creating actor with Type parameter wich represent types of messages wich this actor can process. i’m looking for a way to force to implement some method , say processIncomingMesage(<? extends SupportedProtocol> msg ), in class that exstends AbstractBehavior as many times as SupportedProtocol have concrete implementations of mesasges, so Behavior class may look like
public class SimpleDevice extend AbstractBehavior<SimpleDeviceProtocol>
@Override
private Behavior<SimpleDeviceProtocol> processIncomingMesage (final MonitoringProtocol.GetStateRequest getStateRequestMsg){
// processing message here
return Behaviors.same()
}
@Override
private Behavior<SimpleDeviceProtocol> processIncomingMesage (final SimpleManagementProtocol.TurnOnRequest turnOnRequestMsg){
// processing message here
return Behaviors.same()
}
@Override
public Receive<SimpleDeviceProtocol> createReceive() {
final Receive<SimpleDeviceProtocol> receive
= newReceiveBuilder().onMessageUnchecked(SimpleDeviceProtocol.class, this::handlerSelector).build();
return receive;
}
private <M> Behavior<SimpleDeviceProtocol> handlerSelector(final M m)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
final Class<? extends Object> messageClass = m.getClass();
final Object processIncomingMesageResult = this.getClass().getDeclaredMethod("processIncomingMesage"
, messageClass).invoke(this,m);
return (Behavior<SimpleDeviceProtocol>) processIncomingMesage;
}
main idea is that somehow create SimpleDeviceProtocol that include all messages types from SimpleManagementProtocol and MonitoringProtocol , than somehow force to implement
method
private Behavior processIncomingMesage (final T message){}
for each processable message Type in SimpleDeviceProtocol
so we can create diferent types of actors wich can implements same protocols in diferent ways
and if later on we will extend protocol with say SimpleManagementProtocol.TurnOffRequest
than all behaviors classes that extends SimpleDeviceProtocol or another protocol that contains SimpleManagementProtocol must implement
private Behavior processIncomingMesage (final SimpleManagementProtocol.TurnOffRequest turnOffRequestMsg);
or may be threre is more simple aproach ?