2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.common.actor;
10 import static java.util.Objects.requireNonNull;
12 import scala.concurrent.ExecutionContext;
14 public class Dispatchers {
15 public static final String DEFAULT_DISPATCHER_PATH = "akka.actor.default-dispatcher";
16 public static final String CLIENT_DISPATCHER_PATH = "client-dispatcher";
17 public static final String TXN_DISPATCHER_PATH = "txn-dispatcher";
18 public static final String SHARD_DISPATCHER_PATH = "shard-dispatcher";
19 public static final String NOTIFICATION_DISPATCHER_PATH = "notification-dispatcher";
20 public static final String SERIALIZATION_DISPATCHER_PATH = "serialization-dispatcher";
22 private final akka.dispatch.Dispatchers dispatchers;
24 public enum DispatcherType {
25 Client(CLIENT_DISPATCHER_PATH),
26 Transaction(TXN_DISPATCHER_PATH),
27 Shard(SHARD_DISPATCHER_PATH),
28 Notification(NOTIFICATION_DISPATCHER_PATH),
29 Serialization(SERIALIZATION_DISPATCHER_PATH);
31 private final String path;
33 DispatcherType(final String path) {
37 String path(final akka.dispatch.Dispatchers knownDispatchers) {
38 if (knownDispatchers.hasDispatcher(path)) {
41 return DEFAULT_DISPATCHER_PATH;
44 ExecutionContext dispatcher(final akka.dispatch.Dispatchers knownDispatchers) {
45 if (knownDispatchers.hasDispatcher(path)) {
46 return knownDispatchers.lookup(path);
48 return knownDispatchers.defaultGlobalDispatcher();
52 public Dispatchers(final akka.dispatch.Dispatchers dispatchers) {
53 this.dispatchers = requireNonNull(dispatchers, "dispatchers should not be null");
56 public ExecutionContext getDispatcher(final DispatcherType dispatcherType) {
57 return dispatcherType.dispatcher(this.dispatchers);
60 public String getDispatcherPath(final DispatcherType dispatcherType) {
61 return dispatcherType.path(this.dispatchers);