Initial framework migration to netty.
[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         private final ProtocolMessageFactory pmf = new MessageFactory();
25
26         private final SessionParent parent;
27
28         public boolean up = false;
29
30         private final int maxMsgSize;
31
32         public Session(final SessionParent parent, final int maxMsgSize) {
33                 this.parent = parent;
34                 this.maxMsgSize = maxMsgSize;
35         }
36
37         @Override
38         public void close() throws IOException {
39
40         }
41
42         @Override
43         public void startSession() {
44                 // this.pos.putMessage(new Message("hello"), this.pmf);
45         }
46
47         @Override
48         public void handleMessage(final ProtocolMessage msg) {
49                 logger.debug("Message received: {}", ((Message) msg).getMessage());
50                 this.up = true;
51                 this.msgs.add(msg);
52                 logger.debug(this.msgs.size() + "");
53         }
54
55         @Override
56         public void handleMalformedMessage(final DeserializerException e) {
57                 logger.debug("Malformed message: {}", e.getMessage(), e);
58         }
59
60         @Override
61         public void handleMalformedMessage(final DocumentedException e) {
62                 logger.debug("Malformed message: {}", e.getMessage(), e);
63         }
64
65         @Override
66         public void endOfInput() {
67                 logger.debug("End of input reported.");
68         }
69
70         @Override
71         public ProtocolMessageFactory getMessageFactory() {
72                 return null;
73         }
74
75         @Override
76         public void onConnectionFailed(final IOException e) {
77                 logger.debug("Connection failed: {}", e.getMessage(), e);
78         }
79
80         @Override
81         public int maximumMessageSize() {
82                 return this.maxMsgSize;
83         }
84 }