PCEP sucessfull connection now implemented. Fixed minor bug in parsing.
[bgpcep.git] / framework / src / test / java / org / opendaylight / protocol / framework / Session.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.framework;
9
10 import java.io.IOException;
11 import java.util.List;
12
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 import com.google.common.collect.Lists;
17
18 public class Session implements ProtocolSession {
19
20         private static final Logger logger = LoggerFactory.getLogger(Session.class);
21
22         public final List<ProtocolMessage> msgs = Lists.newArrayList();
23
24         public boolean up = false;
25
26         private final int maxMsgSize;
27
28         public Session(final int maxMsgSize) {
29                 this.maxMsgSize = maxMsgSize;
30         }
31
32         @Override
33         public void close() throws IOException {
34
35         }
36
37         @Override
38         public void startSession() {
39                 // this.pos.putMessage(new Message("hello"), this.pmf);
40         }
41
42         @Override
43         public void handleMessage(final ProtocolMessage msg) {
44                 logger.debug("Message received: {}", ((Message) msg).getMessage());
45                 this.up = true;
46                 this.msgs.add(msg);
47                 logger.debug(this.msgs.size() + "");
48         }
49
50         @Override
51         public void handleMalformedMessage(final DeserializerException e) {
52                 logger.debug("Malformed message: {}", e.getMessage(), e);
53         }
54
55         @Override
56         public void handleMalformedMessage(final DocumentedException e) {
57                 logger.debug("Malformed message: {}", e.getMessage(), e);
58         }
59
60         @Override
61         public void endOfInput() {
62                 logger.debug("End of input reported.");
63         }
64
65         @Override
66         public ProtocolMessageFactory getMessageFactory() {
67                 return null;
68         }
69
70         @Override
71         public void onConnectionFailed(final IOException e) {
72                 logger.debug("Connection failed: {}", e.getMessage(), e);
73         }
74
75         @Override
76         public int maximumMessageSize() {
77                 return this.maxMsgSize;
78         }
79 }