public Type GetMailboxType(Props props, Config dispatcherConfig)
{
if (!string.IsNullOrEmpty(props.Mailbox))
{
return FromConfig(props.Mailbox);
}
if (dispatcherConfig == null)
dispatcherConfig = ConfigurationFactory.Empty;
var id = dispatcherConfig.GetString("id");
var deploy = props.Deploy;
var actorType = props.Type;
var actorRequirement = new Lazy<Type>(() => GetRequiredType(actorType));
var mailboxRequirement = GetMailboxRequirement(dispatcherConfig);
var hasMailboxRequirement = mailboxRequirement != typeof (IMessageQueue);
var hasMailboxType = dispatcherConfig.HasPath("mailbox-type") &&
dispatcherConfig.GetString("mailbox-type") != Deploy.NoMailboxGiven;
Func<Type, Type> verifyRequirements = mailboxType =>
{
// TODO Akka code after introducing IProducesMessageQueue
// if (hasMailboxRequirement && !mailboxRequirement.isAssignableFrom(mqType))
// throw new IllegalArgumentException(
// s"produced message queue type [$mqType] does not fulfill requirement for dispatcher [$id]. " +
// s"Must be a subclass of [$mailboxRequirement].")
// if (hasRequiredType(actorClass) && !actorRequirement.isAssignableFrom(mqType))
// throw new IllegalArgumentException(
// s"produced message queue type [$mqType] does not fulfill requirement for actor class [$actorClass]. " +
// s"Must be a subclass of [$actorRequirement].")
return mailboxType;
};
if (!deploy.Mailbox.Equals(Deploy.NoMailboxGiven))
return verifyRequirements(FromConfig(deploy.Mailbox));
if (!deploy.Dispatcher.Equals(Deploy.NoDispatcherGiven) && hasMailboxType)
return verifyRequirements(FromConfig(id));
if (actorRequirement.Value != null)
{
try
{
return verifyRequirements(LookupByQueueType(actorRequirement.Value));
}
catch (Exception e)
{
if (hasMailboxRequirement)
return verifyRequirements(LookupByQueueType(mailboxRequirement));
throw;
}
}
if (hasMailboxRequirement)
return verifyRequirements(LookupByQueueType(mailboxRequirement));
return verifyRequirements(_defaultMailboxType);
}