Rename netconf-impl to netconf-server
[netconf.git] / protocol / netconf-server / src / main / java / org / opendaylight / netconf / server / DefaultSessionIdProvider.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech, s.r.o. 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.netconf.server;
9
10 import java.util.concurrent.atomic.AtomicLong;
11 import javax.inject.Inject;
12 import javax.inject.Singleton;
13 import org.osgi.service.component.annotations.Component;
14
15 /**
16  * Default {@link SessionIdProvider}. Counts sessions from the start of the component.
17  */
18 @Singleton
19 @Component(immediate = true, property = "type=default")
20 public final class DefaultSessionIdProvider implements SessionIdProvider {
21     private final AtomicLong sessionCounter = new AtomicLong();
22
23     @Inject
24     public DefaultSessionIdProvider() {
25         // Nothing here
26     }
27
28     @Override
29     public long getNextSessionId() {
30         return sessionCounter.incrementAndGet();
31     }
32
33     @Override
34     public long getCurrentSessionId() {
35         return sessionCounter.get();
36     }
37 }