Bug 3864: Notify netconf monitoring about changes in session
[netconf.git] / netconf / netconf-api / src / main / java / org / opendaylight / netconf / api / monitoring / SessionEvent.java
1 /*
2  * Copyright (c) 2016 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.netconf.api.monitoring;
9
10 /**
11  * Class represents change in netconf session.
12  */
13 public class SessionEvent {
14     private final NetconfManagementSession session;
15     private final Type type;
16
17     private SessionEvent(NetconfManagementSession session, Type type) {
18         this.session = session;
19         this.type = type;
20     }
21
22     /**
23      * Returns session, where event occurred
24      * @return session
25      */
26     public NetconfManagementSession getSession() {
27         return session;
28     }
29
30     /**
31      * Returns event type
32      * @return type
33      */
34     public Type getType() {
35         return type;
36     }
37
38     public static SessionEvent inRpcSuccess(NetconfManagementSession session) {
39         return new SessionEvent(session, Type.IN_RPC_SUCCESS);
40     }
41
42     public static SessionEvent inRpcFail(NetconfManagementSession session) {
43         return new SessionEvent(session, Type.IN_RPC_FAIL);
44     }
45
46     public static SessionEvent outRpcError(NetconfManagementSession session) {
47         return new SessionEvent(session, Type.OUT_RPC_ERROR);
48     }
49
50     public static SessionEvent notification(NetconfManagementSession session) {
51         return new SessionEvent(session, Type.NOTIFICATION);
52     }
53
54     /**
55      * Session event type
56      */
57     public enum Type {
58
59         /**
60          * Correct rpc message received
61          */
62         IN_RPC_SUCCESS,
63
64         /**
65          * Incorrect rpc message received
66          */
67         IN_RPC_FAIL,
68
69         /**
70          * rpc-reply messages sent that contained an rpc-error element.
71          */
72         OUT_RPC_ERROR,
73
74         /**
75          *  Notification message sent
76          */
77         NOTIFICATION
78     }
79 }