blob: 6a667e329c7e22f6cce2dc7e444c44bce95881c8 [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
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 */
Madan Jampani3e033bd2015-04-08 13:03:49 -070016package org.onosproject.store.core.impl;
17
18import static org.slf4j.LoggerFactory.getLogger;
19
20import org.apache.felix.scr.annotations.Activate;
21import org.apache.felix.scr.annotations.Component;
22import org.apache.felix.scr.annotations.Deactivate;
23import org.apache.felix.scr.annotations.Reference;
24import org.apache.felix.scr.annotations.ReferenceCardinality;
25import org.apache.felix.scr.annotations.Service;
26import org.onosproject.store.Timestamp;
27import org.onosproject.store.impl.LogicalTimestamp;
28import org.onosproject.store.service.AtomicCounter;
29import org.onosproject.store.service.LogicalClockService;
30import org.onosproject.store.service.StorageService;
31import org.slf4j.Logger;
32
33/**
34 * LogicalClockService implementation based on a AtomicCounter.
35 */
36@Component(immediate = true, enabled = true)
37@Service
38public class LogicalClockManager implements LogicalClockService {
39
40 private final Logger log = getLogger(getClass());
41
42 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
43 protected StorageService storageService;
44
45 private static final String SYSTEM_LOGICAL_CLOCK_COUNTER_NAME = "sys-clock-counter";
46 private AtomicCounter atomicCounter;
47
48 @Activate
49 public void activate() {
50 atomicCounter = storageService.atomicCounterBuilder()
51 .withName(SYSTEM_LOGICAL_CLOCK_COUNTER_NAME)
52 .withPartitionsDisabled()
53 .build();
Madan Jampani5756c352015-04-29 00:23:58 -070054 log.info("Started");
Madan Jampani3e033bd2015-04-08 13:03:49 -070055 }
56
57 @Deactivate
58 public void deactivate() {
Madan Jampani5756c352015-04-29 00:23:58 -070059 log.info("Stopped");
Madan Jampani3e033bd2015-04-08 13:03:49 -070060 }
61
62 @Override
63 public Timestamp getTimestamp() {
64 return new LogicalTimestamp(atomicCounter.incrementAndGet());
65 }
66}