Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
io.vlingo.actors.Definition Maven / Gradle / Ivy
Go to download
Type safe Actor Model toolkit for reactive concurrency and resiliency using Java and other JVM languages.
// Copyright © 2012-2018 Vaughn Vernon. All rights reserved.
//
// This Source Code Form is subject to the terms of the
// Mozilla Public License, v. 2.0. If a copy of the MPL
// was not distributed with this file, You can obtain
// one at https://mozilla.org/MPL/2.0/.
package io.vlingo.actors;
import java.util.ArrayList;
import java.util.List;
public final class Definition {
public static final List NoParameters = new ArrayList();
public static Definition has(
final Class extends Actor> type,
final List parameters) {
return new Definition(type, parameters);
}
public static Definition has(
final Class extends Actor> type,
final List parameters,
final Logger logger) {
return new Definition(type, parameters, logger);
}
public static Definition has(
final Class extends Actor> type,
final List parameters,
final String actorName) {
return new Definition(type, parameters, actorName);
}
public static Definition has(
final Class extends Actor> type,
final List parameters,
final String actorName,
final Logger logger) {
return new Definition(type, parameters, actorName, logger);
}
public static Definition has(
final Class extends Actor> type,
final List parameters,
final Actor parent,
final String actorName) {
return new Definition(type, parameters, parent, actorName);
}
public static Definition has(
final Class extends Actor> type,
final List parameters,
final String mailboxName,
final String actorName) {
return new Definition(type, parameters, null, mailboxName, actorName);
}
public static Definition has(
final Class extends Actor> type,
final List parameters,
final Actor parent,
final String mailboxName,
final String actorName) {
return new Definition(type, parameters, parent, mailboxName, actorName);
}
public static Definition has(
final Class extends Actor> type,
final List parameters,
final Actor parent,
final String mailboxName,
final String actorName,
final Logger logger) {
return new Definition(type, parameters, parent, mailboxName, actorName, logger);
}
public static List parameters(Object... parameters) {
final List allParameters = new ArrayList();
for (final Object param : parameters) {
allParameters.add(param);
}
return allParameters;
}
private final String actorName;
private final Logger logger;
private final String mailboxName;
private final List parameters;
private final Actor parent;
private final Supervisor supervisor;
private final Class extends Actor> type;
public Definition(final Class extends Actor> type, final List parameters) {
this(type, parameters, null, null, null, null);
}
public Definition(final Class extends Actor> actor, final List parameters, final Logger logger) {
this(actor, parameters, null, null, null, logger);
}
public Definition(final Class extends Actor> actor, final List parameters, final String actorName, final Logger logger) {
this(actor, parameters, null, null, actorName, logger);
}
public Definition(
final Class extends Actor> type,
final List parameters,
final String actorName) {
this(type, parameters, null, null, actorName, null);
}
public Definition(
final Class extends Actor> type,
final List parameters,
final Actor parent,
final String actorName) {
this(type, parameters, parent, null, actorName, null);
}
public Definition(
Class extends Actor> type,
List parameters,
Actor parent,
String mailboxName,
String actorName) {
this(type, parameters, parent, mailboxName, actorName, null);
}
public Definition(
final Class extends Actor> type,
final List parameters,
final Actor parent,
final String mailboxName,
final String actorName,
final Logger logger) {
this.type = type;
this.parameters = parameters;
this.parent = parent;
this.mailboxName = mailboxName;
this.actorName = actorName;
this.supervisor = assignSupervisor(parent);
this.logger = logger;
}
public String actorName() {
return actorName;
}
public Logger loggerOr(final Logger defaultLogger) {
return logger != null ? logger : defaultLogger;
}
public String mailboxName() {
return mailboxName;
}
public List parameters() {
return new ArrayList(internalParameters());
}
public Actor parent() {
return parent;
}
public Actor parentOr(final Actor defaultParent) {
return parent != null ? parent : defaultParent;
}
public Supervisor supervisor() {
return supervisor;
}
public Class extends Actor> type() {
return type;
}
List internalParameters() {
return parameters;
}
private Supervisor assignSupervisor(final Actor parent) {
if (parent != null && parent instanceof Supervisor) {
return parent.lifeCycle.environment.stage.actorAs(parent, Supervisor.class);
}
return null;
}
}