2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.openflowplugin.impl.role;
11 import io.netty.util.HashedWheelTimer;
12 import java.util.concurrent.ConcurrentHashMap;
13 import java.util.concurrent.ConcurrentMap;
14 import java.util.concurrent.ExecutorService;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.openflowplugin.api.openflow.OFPContext;
17 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
18 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
19 import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
20 import org.opendaylight.openflowplugin.api.openflow.role.RoleManager;
21 import org.opendaylight.openflowplugin.impl.services.sal.SalRoleServiceImpl;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfig;
24 public class RoleManagerImpl implements RoleManager {
25 // Timeout after what we will give up on waiting for master role
26 private static final long CHECK_ROLE_MASTER_TIMEOUT = 20000;
28 private final ConcurrentMap<DeviceInfo, RoleContext> contexts = new ConcurrentHashMap<>();
29 private final HashedWheelTimer timer;
30 private final OpenflowProviderConfig config;
31 private final ExecutorService executorService;
33 public RoleManagerImpl(final HashedWheelTimer timer,
34 final OpenflowProviderConfig config,
35 final ExecutorService executorService) {
38 this.executorService = executorService;
42 public RoleContext createContext(@NonNull final DeviceContext deviceContext) {
43 final DeviceInfo deviceInfo = deviceContext.getDeviceInfo();
44 final RoleContextImpl roleContext = new RoleContextImpl(
45 deviceContext.getDeviceInfo(),
46 timer, CHECK_ROLE_MASTER_TIMEOUT, config, executorService);
48 roleContext.setRoleService(new SalRoleServiceImpl(roleContext, deviceContext));
49 contexts.put(deviceInfo, roleContext);
54 public void onDeviceRemoved(final DeviceInfo deviceInfo) {
55 contexts.remove(deviceInfo);
60 contexts.values().forEach(OFPContext::close);