blob: 6a3c9deedd9289e84238680a5a6a67cd0483457f [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 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 */
Yuta HIGUCHI41f2ec02014-10-27 09:54:43 -070016package org.onlab.onos.store.hz;
tomdc66b382014-09-22 17:05:47 -070017
tom1a2908c2014-09-23 16:37:39 -070018import com.hazelcast.config.Config;
19import com.hazelcast.config.FileSystemXmlConfig;
tomdc66b382014-09-22 17:05:47 -070020import com.hazelcast.core.Hazelcast;
21import com.hazelcast.core.HazelcastInstance;
Yuta HIGUCHI497c8842014-09-25 14:23:34 -070022
tomdc66b382014-09-22 17:05:47 -070023import org.apache.felix.scr.annotations.Activate;
24import org.apache.felix.scr.annotations.Component;
25import org.apache.felix.scr.annotations.Deactivate;
26import org.apache.felix.scr.annotations.Service;
tomdc66b382014-09-22 17:05:47 -070027import org.slf4j.Logger;
28import org.slf4j.LoggerFactory;
29
tom1a2908c2014-09-23 16:37:39 -070030import java.io.FileNotFoundException;
tom0872a172014-09-23 11:24:26 -070031
tomdc66b382014-09-22 17:05:47 -070032/**
33 * Auxiliary bootstrap of distributed store.
34 */
35@Component(immediate = true)
36@Service
37public class StoreManager implements StoreService {
38
Yuta HIGUCHIb4139d82014-09-23 18:41:33 -070039 protected static final String HAZELCAST_XML_FILE = "etc/hazelcast.xml";
tom1a2908c2014-09-23 16:37:39 -070040
tomdc66b382014-09-22 17:05:47 -070041 private final Logger log = LoggerFactory.getLogger(getClass());
42
tom85ff08b2014-09-22 17:14:18 -070043 protected HazelcastInstance instance;
tomdc66b382014-09-22 17:05:47 -070044
45 @Activate
46 public void activate() {
tom1a2908c2014-09-23 16:37:39 -070047 try {
48 Config config = new FileSystemXmlConfig(HAZELCAST_XML_FILE);
Yuta HIGUCHI48ee9922014-11-11 09:19:13 -080049
tom1a2908c2014-09-23 16:37:39 -070050 instance = Hazelcast.newHazelcastInstance(config);
tom1a2908c2014-09-23 16:37:39 -070051 log.info("Started");
52 } catch (FileNotFoundException e) {
53 log.error("Unable to configure Hazelcast", e);
54 }
tomdc66b382014-09-22 17:05:47 -070055 }
56
57 @Deactivate
58 public void deactivate() {
tom0872a172014-09-23 11:24:26 -070059 instance.shutdown();
tomdc66b382014-09-22 17:05:47 -070060 log.info("Stopped");
61 }
62
63 @Override
64 public HazelcastInstance getHazelcastInstance() {
65 return instance;
66 }
tom0872a172014-09-23 11:24:26 -070067
tomdc66b382014-09-22 17:05:47 -070068}