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
9 package org.opendaylight.controller.cluster.datastore.utils;
11 import com.google.common.base.Preconditions;
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";
21 private final akka.dispatch.Dispatchers dispatchers;
23 public enum DispatcherType {
24 Client(CLIENT_DISPATCHER_PATH),
25 Transaction(TXN_DISPATCHER_PATH),
26 Shard(SHARD_DISPATCHER_PATH),
27 Notification(NOTIFICATION_DISPATCHER_PATH);
29 private final String path;
30 DispatcherType(String path) {
34 private String path(akka.dispatch.Dispatchers dispatchers) {
35 if (dispatchers.hasDispatcher(path)) {
38 return DEFAULT_DISPATCHER_PATH;
41 private ExecutionContext dispatcher(akka.dispatch.Dispatchers dispatchers) {
42 if (dispatchers.hasDispatcher(path)) {
43 return dispatchers.lookup(path);
45 return dispatchers.defaultGlobalDispatcher();
49 public Dispatchers(akka.dispatch.Dispatchers dispatchers) {
50 Preconditions.checkNotNull(dispatchers, "dispatchers should not be null");
51 this.dispatchers = dispatchers;
54 public ExecutionContext getDispatcher(DispatcherType dispatcherType) {
55 return dispatcherType.dispatcher(this.dispatchers);
58 public String getDispatcherPath(DispatcherType dispatcherType) {
59 return dispatcherType.path(this.dispatchers);