Code clean up
[bgpcep.git] / bmp / bmp-mock / src / main / java / org / opendaylight / protocol / bmp / mock / BmpMockSessionListener.java
1 /*
2  * Copyright (c) 2017 AT&T Intellectual Property. 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
9 package org.opendaylight.protocol.bmp.mock;
10
11 import java.util.concurrent.atomic.AtomicBoolean;
12 import java.util.concurrent.atomic.LongAdder;
13 import javax.annotation.concurrent.GuardedBy;
14 import org.opendaylight.protocol.bmp.api.BmpSession;
15 import org.opendaylight.protocol.bmp.api.BmpSessionListener;
16 import org.opendaylight.yangtools.yang.binding.Notification;
17
18 public final class BmpMockSessionListener implements BmpSessionListener {
19     private final LongAdder counter = new LongAdder();
20     @GuardedBy("this")
21     private final AtomicBoolean up = new AtomicBoolean(false);
22
23     @Override
24     public void onSessionUp(final BmpSession session) {
25         this.up.set(true);
26     }
27
28     @Override
29     public void onSessionDown(final Exception exception) {
30         this.up.set(false);
31     }
32
33     @Override
34     public void onMessage(final Notification message) {
35         this.counter.increment();
36     }
37
38     public boolean getStatus() {
39         return this.up.get();
40     }
41
42     public long getNumberOfMessagesReceived() {
43         return this.counter.longValue();
44     }
45 }