All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vlingo.actors.plugin.supervision.ConfiguredSupervisor Maven / Gradle / Ivy

Go to download

Type safe Actor Model toolkit for reactive concurrency and resiliency using Java and other JVM languages.

There is a newer version: 1.7.5
Show newest version
// Copyright © 2012-2020 VLINGO LABS. 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.plugin.supervision;

import io.vlingo.actors.Actor;

class ConfiguredSupervisor {
  public final String stageName;
  public final Class supervisorClass;
  public final String supervisorName;
  public final Class supervisedProtocol;

  static Class protocolFrom(final String supervisedProtocol) {
    try {
      return Class.forName(supervisedProtocol);
    } catch (Exception e) {
      throw new IllegalStateException("Cannot load class for: " + supervisedProtocol);
    }
  }

  @SuppressWarnings("unchecked")
  static Class supervisorFrom(final String supervisorClassname) {
    try {
      return (Class) Class.forName(supervisorClassname);
    } catch (Exception e) {
      throw new IllegalStateException("Cannot load class for: " + supervisorClassname);
    }
  }

  @Override
  public int hashCode() {
    return 31 * this.stageName.hashCode() + this.supervisorName.hashCode();
  }

  @Override
  public boolean equals(final Object other) {
    if (other == null || other.getClass() != this.getClass()) {
      return false;
    }
    final ConfiguredSupervisor otherSupervisor = (ConfiguredSupervisor) other;
    return this.stageName.equals(otherSupervisor.stageName) &&
           this.supervisorName.equals(otherSupervisor.supervisorName) && 
           (this.supervisedProtocol == null && otherSupervisor.supervisedProtocol == null) ||
           (this.supervisedProtocol != null && otherSupervisor.supervisedProtocol != null &&
            this.supervisedProtocol.equals(otherSupervisor.supervisedProtocol)) &&
           this.supervisorClass.equals(otherSupervisor.supervisorClass);
  }

  ConfiguredSupervisor(final String stageName, final String supervisorName, final Class supervisedProtocol, final Class supervisorClass) {
    this.stageName = stageName;
    this.supervisorName = supervisorName;
    this.supervisedProtocol = supervisedProtocol;
    this.supervisorClass = supervisorClass;
  }

  ConfiguredSupervisor(final String stageName, final String supervisorName, final String supervisedProtocol, final String supervisorClassname) {
    this.stageName = stageName;
    this.supervisorName = supervisorName;
    this.supervisedProtocol = protocolFrom(supervisedProtocol);
    this.supervisorClass = supervisorFrom(supervisorClassname);
  }

  ConfiguredSupervisor(final String stageName, final String supervisorName, final Class supervisorClass) {
    this.stageName = stageName;
    this.supervisorName = supervisorName;
    this.supervisedProtocol = null;
    this.supervisorClass = supervisorClass;
  }

  ConfiguredSupervisor(final String stageName, final String supervisorName, final String supervisorClassname) {
    this.stageName = stageName;
    this.supervisorName = supervisorName;
    this.supervisedProtocol = null;
    this.supervisorClass = supervisorFrom(supervisorClassname);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy