b9e8d445a08e8bfeb6a1bc47f47d7e6523e7c557
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / lifecycle / LifecycleServiceImpl.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.openflowplugin.impl.lifecycle;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.concurrent.ExecutionException;
12 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
13 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
14 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
15 import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
16 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
17 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 class LifecycleServiceImpl implements LifecycleService {
22
23     private static final Logger LOG = LoggerFactory.getLogger(LifecycleServiceImpl.class);
24
25     private final DeviceContext deviceContext;
26     private final RpcContext rpcContext;
27     private final RoleContext roleContext;
28     private final StatisticsContext statContext;
29
30     public LifecycleServiceImpl(
31             final DeviceContext deviceContext,
32             final RpcContext rpcContext,
33             final RoleContext roleContext,
34             final StatisticsContext statContext) {
35         this.deviceContext = deviceContext;
36         this.rpcContext = rpcContext;
37         this.roleContext = roleContext;
38         this.statContext = statContext;
39     }
40
41     @Override
42     public void instantiateServiceInstance() {
43         LOG.info("Starting device context cluster services for node {}", this.deviceContext.getServiceIdentifier());
44         try {
45             this.deviceContext.startupClusterServices();
46         } catch (ExecutionException | InterruptedException e) {
47             LOG.warn("Cluster service {} was unable to start.", this.getIdentifier());
48         }
49         LOG.info("Starting statistics context cluster services for node {}", this.deviceContext.getServiceIdentifier());
50     }
51
52     @Override
53     public ListenableFuture<Void> closeServiceInstance() {
54         return deviceContext.stopClusterServices();
55     }
56
57     @Override
58     public ServiceGroupIdentifier getIdentifier() {
59         return deviceContext.getServiceIdentifier();
60     }
61 }