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

org.opentcs.customizations.kernel.KernelInjectionModule Maven / Gradle / Ivy

// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.customizations.kernel;

import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import com.google.inject.multibindings.MapBinder;
import com.google.inject.multibindings.Multibinder;
import org.opentcs.components.kernel.Dispatcher;
import org.opentcs.components.kernel.KernelExtension;
import org.opentcs.components.kernel.OrderSequenceCleanupApproval;
import org.opentcs.components.kernel.PeripheralJobCleanupApproval;
import org.opentcs.components.kernel.PeripheralJobDispatcher;
import org.opentcs.components.kernel.Router;
import org.opentcs.components.kernel.Scheduler;
import org.opentcs.components.kernel.TransportOrderCleanupApproval;
import org.opentcs.components.kernel.routing.EdgeEvaluator;
import org.opentcs.customizations.ConfigurableInjectionModule;
import org.opentcs.drivers.peripherals.PeripheralCommAdapterFactory;
import org.opentcs.drivers.vehicle.VehicleCommAdapterFactory;
import org.opentcs.drivers.vehicle.VehicleDataTransformerFactory;

/**
 * A base class for Guice modules adding or customizing bindings for the kernel application.
 */
public abstract class KernelInjectionModule
    extends
      ConfigurableInjectionModule {

  /**
   * Sets the scheduler implementation to be used.
   *
   * @param clazz The implementation.
   */
  protected void bindScheduler(Class clazz) {
    bind(Scheduler.class).to(clazz).in(Singleton.class);
  }

  /**
   * Sets the router implementation to be used.
   *
   * @param clazz The implementation.
   */
  protected void bindRouter(Class clazz) {
    bind(Router.class).to(clazz).in(Singleton.class);
  }

  /**
   * Sets the dispatcher implementation to be used.
   *
   * @param clazz The implementation.
   */
  protected void bindDispatcher(Class clazz) {
    bind(Dispatcher.class).to(clazz).in(Singleton.class);
  }

  /**
   * Sets the peripheral job dispatcher implementation to be used.
   *
   * @param clazz The implementation.
   */
  protected void bindPeripheralJobDispatcher(Class clazz) {
    bind(PeripheralJobDispatcher.class).to(clazz).in(Singleton.class);
  }

  /**
   * Returns a multibinder that can be used to register kernel extensions for all kernel states.
   *
   * @return The multibinder.
   */
  protected Multibinder extensionsBinderAllModes() {
    return Multibinder.newSetBinder(binder(), KernelExtension.class, ActiveInAllModes.class);
  }

  /**
   * Returns a multibinder that can be used to register kernel extensions for the kernel's modelling
   * state.
   *
   * @return The multibinder.
   */
  protected Multibinder extensionsBinderModelling() {
    return Multibinder.newSetBinder(binder(), KernelExtension.class, ActiveInModellingMode.class);
  }

  /**
   * Returns a multibinder that can be used to register kernel extensions for the kernel's operating
   * state.
   *
   * @return The multibinder.
   */
  protected Multibinder extensionsBinderOperating() {
    return Multibinder.newSetBinder(binder(), KernelExtension.class, ActiveInOperatingMode.class);
  }

  /**
   * Returns a multibinder that can be used to register vehicle communication adapter factories.
   *
   * @return The multibinder.
   */
  protected Multibinder vehicleCommAdaptersBinder() {
    return Multibinder.newSetBinder(binder(), VehicleCommAdapterFactory.class);
  }

  /**
   * Returns a multibinder that can be used to register vehicle data transformer factories.
   *
   * @return The multibinder.
   */
  protected Multibinder vehicleDataTransformersBinder() {
    return Multibinder.newSetBinder(binder(), VehicleDataTransformerFactory.class);
  }

  /**
   * Returns a multibinder that can be used to register peripheral communication adapter factories.
   *
   * @return The multibinder.
   */
  protected Multibinder peripheralCommAdaptersBinder() {
    return Multibinder.newSetBinder(binder(), PeripheralCommAdapterFactory.class);
  }

  /**
   * Returns a multibinder that can be used to register transport order cleanup approvals.
   *
   * @return The multibinder.
   */
  protected Multibinder transportOrderCleanupApprovalBinder() {
    return Multibinder.newSetBinder(binder(), TransportOrderCleanupApproval.class);
  }

  /**
   * Returns a multibinder that can be used to register order sequence cleanup approvals.
   *
   * @return The multibinder.
   */
  protected Multibinder orderSequenceCleanupApprovalBinder() {
    return Multibinder.newSetBinder(binder(), OrderSequenceCleanupApproval.class);
  }

  /**
   * Returns a multibinder that can be used to register peripheral job cleanup approvals.
   *
   * @return The multibinder.
   */
  protected Multibinder peripheralJobCleanupApprovalBinder() {
    return Multibinder.newSetBinder(binder(), PeripheralJobCleanupApproval.class);
  }

  /**
   * Returns a multibinder that can be used to register scheduler modules.
   *
   * @return The multibinder.
   */
  protected Multibinder schedulerModuleBinder() {
    return Multibinder.newSetBinder(binder(), Scheduler.Module.class);
  }

  /**
   * Returns a mapbinder that can be used to register edge evaluators.
   *
   * @return The mapbinder.
   */
  protected MapBinder edgeEvaluatorBinder() {
    return MapBinder.newMapBinder(
        binder(),
        TypeLiteral.get(String.class),
        TypeLiteral.get(EdgeEvaluator.class)
    );
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy