2 * Copyright (c) 2016 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.openflowplugin.impl.lifecycle;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.concurrent.ExecutionException;
12 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
13 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
14 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
15 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
16 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
17 import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
18 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
19 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public class LifecycleServiceImpl implements LifecycleService {
25 private static final Logger LOG = LoggerFactory.getLogger(LifecycleServiceImpl.class);
27 private DeviceContext deviceContext;
28 private RpcContext rpcContext;
29 private RoleContext roleContext;
30 private StatisticsContext statContext;
31 private ClusterSingletonServiceRegistration registration;
35 public void instantiateServiceInstance() {
38 LOG.info("Starting device context cluster services for node {}", getIdentifier());
39 this.deviceContext.startupClusterServices();
41 LOG.info("Starting statistics context cluster services for node {}", getIdentifier());
42 this.statContext.startupClusterServices();
44 LOG.info("Starting rpc context cluster services for node {}", getIdentifier());
45 this.rpcContext.startupClusterServices();
47 LOG.info("Starting role context cluster services for node {}", getIdentifier());
48 this.roleContext.startupClusterServices();
50 } catch (ExecutionException | InterruptedException e) {
51 LOG.warn("Cluster service {} was unable to start.", this.getIdentifier());
56 public ListenableFuture<Void> closeServiceInstance() {
57 statContext.stopClusterServices();
58 rpcContext.stopClusterServices();
59 return deviceContext.stopClusterServices();
63 public ServiceGroupIdentifier getIdentifier() {
64 return deviceContext.getServiceIdentifier();
69 public void close() throws Exception {
70 if (registration != null) {
77 public void registerService(final ClusterSingletonServiceProvider singletonServiceProvider) {
78 this.registration = singletonServiceProvider.registerClusterSingletonService(this);
82 public void setDeviceContext(final DeviceContext deviceContext) {
83 this.deviceContext = deviceContext;
87 public void setRpcContext(final RpcContext rpcContext) {
88 this.rpcContext = rpcContext;
92 public void setRoleContext(final RoleContext roleContext) {
93 this.roleContext = roleContext;
97 public void setStatContext(final StatisticsContext statContext) {
98 this.statContext = statContext;