857169305a0269478ef3809c1ac31c7519b0f11a
[bgpcep.git] / framework / src / main / java / org / opendaylight / protocol / framework / ProtocolSession.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.Closeable;
11 import java.io.IOException;
12
13 /**
14  * Protocol Session represents the finite state machine in underlying protocol, including timers and its purpose is to
15  * create a connection between server and client. Session is automatically started, when TCP connection is created, but
16  * can be stopped manually. If the session is up, it has to redirect messages to/from user. Handles also malformed
17  * messages and unknown requests.
18  * 
19  * This interface should be implemented by a final class representing a protocol specific session.
20  */
21 public interface ProtocolSession extends Closeable {
22
23         /**
24          * Starts the session. This method should be used only internally by the Dispatcher.
25          */
26         public void startSession();
27
28         /**
29          * Handles incoming message (parsing, reacting if necessary).
30          * 
31          * @param msg incoming message
32          */
33         public void handleMessage(final ProtocolMessage msg);
34
35         /**
36          * Handles malformed message when a deserializer exception occurred. The handling might be different from when a
37          * documented exception is thrown.
38          * 
39          * @param e deserializer exception that occurred
40          */
41         public void handleMalformedMessage(final DeserializerException e);
42
43         /**
44          * Handles malformed message when a documented exception occurred. The handling might be different from when a
45          * deserializer exception is thrown.
46          * 
47          * @param e documented exception that occurred
48          */
49         public void handleMalformedMessage(final DocumentedException e);
50
51         /**
52          * Called when reached the end of input stream while reading.
53          */
54         public void endOfInput();
55
56         /**
57          * Getter for message factory
58          * 
59          * @return protocol specific message factory
60          */
61         public ProtocolMessageFactory getMessageFactory();
62
63         /**
64          * Session is notified about the connection not being established successfully.
65          * 
66          * @param e IOException that was the cause of failed connection.
67          */
68         public void onConnectionFailed(final IOException e);
69
70         /**
71          * Returns the maximum message size (in bytes) for purposes of dispatcher buffering -- the dispatcher allocates a
72          * buffer this big, and if it gets full without making decoding progress, the dispatcher terminates the session.
73          * 
74          * @return maximum message size
75          */
76         public int maximumMessageSize();
77 }