Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.store.hz; |
tom | dc66b38 | 2014-09-22 17:05:47 -0700 | [diff] [blame] | 17 | |
tom | 1a2908c | 2014-09-23 16:37:39 -0700 | [diff] [blame] | 18 | import com.hazelcast.config.Config; |
| 19 | import com.hazelcast.config.FileSystemXmlConfig; |
tom | dc66b38 | 2014-09-22 17:05:47 -0700 | [diff] [blame] | 20 | import com.hazelcast.core.Hazelcast; |
| 21 | import com.hazelcast.core.HazelcastInstance; |
Yuta HIGUCHI | 497c884 | 2014-09-25 14:23:34 -0700 | [diff] [blame] | 22 | |
tom | dc66b38 | 2014-09-22 17:05:47 -0700 | [diff] [blame] | 23 | import org.apache.felix.scr.annotations.Activate; |
| 24 | import org.apache.felix.scr.annotations.Component; |
| 25 | import org.apache.felix.scr.annotations.Deactivate; |
| 26 | import org.apache.felix.scr.annotations.Service; |
tom | dc66b38 | 2014-09-22 17:05:47 -0700 | [diff] [blame] | 27 | import org.slf4j.Logger; |
| 28 | import org.slf4j.LoggerFactory; |
| 29 | |
tom | 1a2908c | 2014-09-23 16:37:39 -0700 | [diff] [blame] | 30 | import java.io.FileNotFoundException; |
tom | 0872a17 | 2014-09-23 11:24:26 -0700 | [diff] [blame] | 31 | |
tom | dc66b38 | 2014-09-22 17:05:47 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Auxiliary bootstrap of distributed store. |
| 34 | */ |
| 35 | @Component(immediate = true) |
| 36 | @Service |
| 37 | public class StoreManager implements StoreService { |
| 38 | |
Yuta HIGUCHI | b4139d8 | 2014-09-23 18:41:33 -0700 | [diff] [blame] | 39 | protected static final String HAZELCAST_XML_FILE = "etc/hazelcast.xml"; |
tom | 1a2908c | 2014-09-23 16:37:39 -0700 | [diff] [blame] | 40 | |
tom | dc66b38 | 2014-09-22 17:05:47 -0700 | [diff] [blame] | 41 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 42 | |
tom | 85ff08b | 2014-09-22 17:14:18 -0700 | [diff] [blame] | 43 | protected HazelcastInstance instance; |
tom | dc66b38 | 2014-09-22 17:05:47 -0700 | [diff] [blame] | 44 | |
| 45 | @Activate |
| 46 | public void activate() { |
tom | 1a2908c | 2014-09-23 16:37:39 -0700 | [diff] [blame] | 47 | try { |
| 48 | Config config = new FileSystemXmlConfig(HAZELCAST_XML_FILE); |
Yuta HIGUCHI | 48ee992 | 2014-11-11 09:19:13 -0800 | [diff] [blame] | 49 | |
tom | 1a2908c | 2014-09-23 16:37:39 -0700 | [diff] [blame] | 50 | instance = Hazelcast.newHazelcastInstance(config); |
tom | 1a2908c | 2014-09-23 16:37:39 -0700 | [diff] [blame] | 51 | log.info("Started"); |
| 52 | } catch (FileNotFoundException e) { |
| 53 | log.error("Unable to configure Hazelcast", e); |
| 54 | } |
tom | dc66b38 | 2014-09-22 17:05:47 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | @Deactivate |
| 58 | public void deactivate() { |
tom | 0872a17 | 2014-09-23 11:24:26 -0700 | [diff] [blame] | 59 | instance.shutdown(); |
tom | dc66b38 | 2014-09-22 17:05:47 -0700 | [diff] [blame] | 60 | log.info("Stopped"); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public HazelcastInstance getHazelcastInstance() { |
| 65 | return instance; |
| 66 | } |
tom | 0872a17 | 2014-09-23 11:24:26 -0700 | [diff] [blame] | 67 | |
tom | dc66b38 | 2014-09-22 17:05:47 -0700 | [diff] [blame] | 68 | } |