blob: e3a0522c22184493a7199a5b688d9bd74388589f [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska83e090e2014-10-22 14:25:35 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska83e090e2014-10-22 14:25:35 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska83e090e2014-10-22 14:25:35 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent;
Brian O'Connorb876bf12014-10-02 14:59:37 -070017
Brian O'Connorabafb502014-12-02 22:26:20 -080018import org.onosproject.event.AbstractEvent;
Brian O'Connorb876bf12014-10-02 14:59:37 -070019
Brian O'Connorb876bf12014-10-02 14:59:37 -070020/**
21 * A class to represent an intent related event.
22 */
tom85258ee2014-10-07 00:10:02 -070023public class IntentEvent extends AbstractEvent<IntentEvent.Type, Intent> {
Brian O'Connorb876bf12014-10-02 14:59:37 -070024
tom85258ee2014-10-07 00:10:02 -070025 public enum Type {
26 /**
Brian O'Connor7a71d5d2014-12-02 00:12:27 -080027 * Signifies that an intent is to be installed or reinstalled.
tom85258ee2014-10-07 00:10:02 -070028 */
Brian O'Connor7a71d5d2014-12-02 00:12:27 -080029 INSTALL_REQ,
Brian O'Connorb876bf12014-10-02 14:59:37 -070030
tom85258ee2014-10-07 00:10:02 -070031 /**
32 * Signifies that an intent has been successfully installed.
33 */
34 INSTALLED,
Brian O'Connorb876bf12014-10-02 14:59:37 -070035
tom85258ee2014-10-07 00:10:02 -070036 /**
37 * Signifies that an intent has failed compilation or installation.
38 */
39 FAILED,
40
41 /**
Brian O'Connor7a71d5d2014-12-02 00:12:27 -080042 * Signifies that an intent will be withdrawn.
43 */
44 WITHDRAW_REQ,
45
46 /**
tom85258ee2014-10-07 00:10:02 -070047 * Signifies that an intent has been withdrawn from the system.
48 */
49 WITHDRAWN
Brian O'Connorb876bf12014-10-02 14:59:37 -070050 }
51
52 /**
tom85258ee2014-10-07 00:10:02 -070053 * Creates an event of a given type and for the specified intent and the
54 * current time.
Brian O'Connorb876bf12014-10-02 14:59:37 -070055 *
tom85258ee2014-10-07 00:10:02 -070056 * @param type event type
57 * @param intent subject intent
58 * @param time time the event created in milliseconds since start of epoch
Brian O'Connorb876bf12014-10-02 14:59:37 -070059 */
tom85258ee2014-10-07 00:10:02 -070060 public IntentEvent(Type type, Intent intent, long time) {
61 super(type, intent, time);
Brian O'Connorb876bf12014-10-02 14:59:37 -070062 }
63
64 /**
tom85258ee2014-10-07 00:10:02 -070065 * Creates an event of a given type and for the specified intent and the
66 * current time.
Brian O'Connorb876bf12014-10-02 14:59:37 -070067 *
tom85258ee2014-10-07 00:10:02 -070068 * @param type event type
69 * @param intent subject intent
Brian O'Connorb876bf12014-10-02 14:59:37 -070070 */
tom85258ee2014-10-07 00:10:02 -070071 public IntentEvent(Type type, Intent intent) {
72 super(type, intent);
Brian O'Connorb876bf12014-10-02 14:59:37 -070073 }
74
alshabiba9819bf2014-11-30 18:15:52 -080075 public static IntentEvent getEvent(IntentState state, Intent intent) {
76 Type type;
77 switch (state) {
Brian O'Connor7a71d5d2014-12-02 00:12:27 -080078 case INSTALL_REQ:
79 type = Type.INSTALL_REQ;
alshabiba9819bf2014-11-30 18:15:52 -080080 break;
81 case INSTALLED:
82 type = Type.INSTALLED;
83 break;
Brian O'Connor7a71d5d2014-12-02 00:12:27 -080084 case WITHDRAW_REQ:
85 type = Type.WITHDRAW_REQ;
86 break;
alshabiba9819bf2014-11-30 18:15:52 -080087 case WITHDRAWN:
88 type = Type.WITHDRAWN;
89 break;
90 case FAILED:
91 type = Type.FAILED;
92 break;
93
94 //fallthrough to default from here
95 case COMPILING:
96 case INSTALLING:
97 case RECOMPILING:
98 case WITHDRAWING:
99 default:
100 throw new IllegalArgumentException(
101 "Intent event cannot have transient state: " + state);
102 }
103 return new IntentEvent(type, intent);
104 }
105
Brian O'Connorb876bf12014-10-02 14:59:37 -0700106}