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("Statistics initial gathering OK, submitting data for node {}", getIdentifier());
45 this.deviceContext.initialSubmitTransaction();
47 LOG.info("Starting rpc context cluster services for node {}", getIdentifier());
48 this.rpcContext.startupClusterServices();
50 LOG.info("Starting role context cluster services for node {}", getIdentifier());
51 this.roleContext.startupClusterServices();
53 } catch (ExecutionException | InterruptedException e) {
54 LOG.warn("Cluster service {} was unable to start.", this.getIdentifier());
59 public ListenableFuture<Void> closeServiceInstance() {
60 statContext.stopClusterServices();
61 rpcContext.stopClusterServices();
62 return deviceContext.stopClusterServices();
66 public ServiceGroupIdentifier getIdentifier() {
67 return deviceContext.getServiceIdentifier();
72 public void close() throws Exception {
73 if (registration != null) {
80 public void registerService(final ClusterSingletonServiceProvider singletonServiceProvider) {
81 this.registration = singletonServiceProvider.registerClusterSingletonService(this);
85 public void setDeviceContext(final DeviceContext deviceContext) {
86 this.deviceContext = deviceContext;
90 public void setRpcContext(final RpcContext rpcContext) {
91 this.rpcContext = rpcContext;
95 public void setRoleContext(final RoleContext roleContext) {
96 this.roleContext = roleContext;
100 public void setStatContext(final StatisticsContext statContext) {
101 this.statContext = statContext;