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

io.vlingo.lattice.router.LoadBalancingCommandRouter Maven / Gradle / Ivy

Go to download

Tooling for reactive Domain-Driven Design projects that are highly concurrent. Includes compute grid, actor caching, spaces, cross-node cluster messaging, CQRS, and Event Sourcing support.

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.lattice.router;

import io.vlingo.actors.Definition;
import io.vlingo.actors.RouterSpecification;
import io.vlingo.actors.SmallestMailboxRouter;
import io.vlingo.lattice.model.Command;

/**
 * The {@code CommandRouter} implementation for load-balancing on the {@code RoutableCommand}.
 */
public class LoadBalancingCommandRouter extends SmallestMailboxRouter implements CommandRouter {
  /**
   * Constructs my default state.
   * @param totalRoutees the int number or routees to create
   */
  public LoadBalancingCommandRouter(final int totalRoutees) {
    super(new RouterSpecification(
            totalRoutees,
            Definition.has(CommandRouterWorkerActor.class, Definition.NoParameters),
            CommandRouter.class));
  }

  /**
   * Route to least busy routee.
   * @see io.vlingo.lattice.router.CommandRouter#route(io.vlingo.lattice.router.RoutableCommand)
   */
  @Override
  public  void route(final RoutableCommand command) {
    dispatchCommand(CommandRouter::route, command);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy