BUG-58: refactor to take advantage of netty
[bgpcep.git] / bgp / rib-mock / src / test / java / org / opendaylight / protocol / bgp / rib / mock / BGPListenerMock.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. 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.protocol.bgp.rib.mock;
9
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
13
14 import org.opendaylight.protocol.bgp.parser.BGPMessage;
15 import org.opendaylight.protocol.bgp.parser.BGPSession;
16 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
17 import org.opendaylight.protocol.bgp.parser.BGPTerminationReason;
18
19
20 /**
21  * Mock implementation of {@link BGPListener} for testing purposes.
22  */
23 final class BGPListenerMock implements BGPSessionListener {
24         private final List<BGPMessage> buffer = Collections.synchronizedList(new ArrayList<BGPMessage>());
25         private boolean connected = false;
26
27         protected List<BGPMessage> getBuffer() {
28                 return this.buffer;
29         }
30
31         protected boolean isConnected() {
32                 return this.connected;
33         }
34
35         @Override
36         public void onMessage(final BGPSession session, final BGPMessage message) {
37                 this.buffer.add(message);
38         }
39
40         @Override
41         public void onSessionUp(final BGPSession session) {
42                 this.connected = true;
43         }
44
45         @Override
46         public void onSessionDown(final BGPSession session, final Exception e) {
47                 this.connected = false;
48
49         }
50
51         @Override
52         public void onSessionTerminated(final BGPSession session, final BGPTerminationReason reason) {
53                 this.connected = false;
54         }
55 }