ffdd25f24ea6ab06325091d21e3a40f681c5b5f9
[onosfw.git] /
1 /*
2  * Copyright 2015 Open Networking Laboratory
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onosproject.store.cluster.messaging.impl;
17
18 import org.apache.felix.scr.annotations.Activate;
19 import org.apache.felix.scr.annotations.Component;
20 import org.apache.felix.scr.annotations.Deactivate;
21 import org.apache.felix.scr.annotations.Reference;
22 import org.apache.felix.scr.annotations.ReferenceCardinality;
23 import org.apache.felix.scr.annotations.Service;
24 import org.onlab.nio.service.IOLoopMessaging;
25 import org.onosproject.cluster.ClusterDefinitionService;
26 import org.onosproject.cluster.ControllerNode;
27 import org.onosproject.store.cluster.messaging.Endpoint;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 /**
32  * IOLoop based MessagingService.
33  */
34 @Component(immediate = true, enabled = false)
35 @Service
36 public class IOLoopMessagingManager extends IOLoopMessaging {
37
38     private final Logger log = LoggerFactory.getLogger(getClass());
39
40     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
41     protected ClusterDefinitionService clusterDefinitionService;
42
43     @Activate
44     public void activate() throws Exception {
45         ControllerNode localNode = clusterDefinitionService.localNode();
46         super.start(new Endpoint(localNode.ip(), localNode.tcpPort()));
47         log.info("Started");
48     }
49
50     @Deactivate
51     public void deactivate() throws Exception {
52         super.stop();
53         log.info("Stopped");
54     }
55 }