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 javax.annotation.Nonnull;
15 import org.opendaylight.openflowplugin.api.openflow.OFPContext;
16 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
17 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
18 import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
19 import org.opendaylight.openflowplugin.api.openflow.role.RoleManager;
20 import org.opendaylight.openflowplugin.impl.services.sal.SalRoleServiceImpl;
22 public class RoleManagerImpl implements RoleManager {
23 // Timeout after what we will give up on waiting for master role
24 private static final long CHECK_ROLE_MASTER_TIMEOUT = 20000;
26 private final ConcurrentMap<DeviceInfo, RoleContext> contexts = new ConcurrentHashMap<>();
27 private final HashedWheelTimer timer;
29 public RoleManagerImpl(final HashedWheelTimer timer) {
34 public RoleContext createContext(@Nonnull final DeviceContext deviceContext) {
35 final DeviceInfo deviceInfo = deviceContext.getDeviceInfo();
36 final RoleContextImpl roleContext = new RoleContextImpl(
37 deviceContext.getDeviceInfo(),
38 timer, CHECK_ROLE_MASTER_TIMEOUT);
40 roleContext.setRoleService(new SalRoleServiceImpl(roleContext, deviceContext));
41 contexts.put(deviceInfo, roleContext);
46 public void onDeviceRemoved(final DeviceInfo deviceInfo) {
47 contexts.remove(deviceInfo);
52 contexts.values().forEach(OFPContext::close);