Use ByteBuf.readRetainedSlice()
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / extension / RegistrationCloser.java
1 /*
2  * Copyright (c) 2014 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.openflowplugin.openflow.md.core.extension;
9
10 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
11 import org.opendaylight.openflowplugin.extension.api.ConverterExtensionKey;
12 import org.opendaylight.openflowplugin.extension.api.ConverterMessageToOFJava;
13 import org.opendaylight.openflowplugin.extension.api.ConvertorActionFromOFJava;
14 import org.opendaylight.openflowplugin.extension.api.ConvertorActionToOFJava;
15 import org.opendaylight.openflowplugin.extension.api.ConvertorData;
16 import org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava;
17 import org.opendaylight.openflowplugin.extension.api.ConvertorMessageFromOFJava;
18 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
19 import org.opendaylight.openflowplugin.extension.api.TypeVersionKey;
20 import org.opendaylight.openflowplugin.extension.api.path.AugmentationPath;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
24 import org.opendaylight.yangtools.concepts.ObjectRegistration;
25 import org.opendaylight.yangtools.yang.binding.DataContainer;
26
27 /**
28  * Closes converter registrations.
29  *
30  * @param <K> converter key
31  * @param <C> converter instance
32  */
33 public abstract class RegistrationCloser<K, C> implements ObjectRegistration<C> {
34
35     private ExtensionConverterManagerImpl registrator;
36     private K key;
37     private C converter;
38
39     /**
40      * Sets the registrator.
41      *
42      * @param registrator the registrator to set
43      */
44     public void setRegistrator(ExtensionConverterManagerImpl registrator) {
45         this.registrator = registrator;
46     }
47
48     /**
49      * Sets the key.
50      *
51      * @param key the key to set
52      */
53     public void setKey(K key) {
54         this.key = key;
55     }
56
57     /**
58      * Sets the converter.
59      *
60      * @param converter the converter to set
61      */
62     public void setConverter(C converter) {
63         this.converter = converter;
64     }
65
66     /**
67      * Returns the registrator.
68      */
69     public ExtensionConverterManagerImpl getRegistrator() {
70         return registrator;
71     }
72
73     /**
74      * Returns the key.
75      */
76     public K getKey() {
77         return key;
78     }
79
80     /**
81      * Returns the converter.
82      */
83     public C getConverter() {
84         return converter;
85     }
86
87     @Override
88     public C getInstance() {
89         return getConverter();
90     }
91
92     /**
93      * Standalone deregistrator.
94      *
95      * @param <T> target type of wrapped convertor
96      */
97     public static class RegistrationCloserToOFJava<T extends DataContainer> extends
98             RegistrationCloser<ConverterExtensionKey<? extends ExtensionKey>, ConvertorToOFJava<T>> {
99
100         @Override
101         public void close() {
102             getRegistrator().unregister(getKey(), getConverter());
103         }
104     }
105
106     /**
107      * Standalone deregistrator.
108      *
109      * @param <F> source type of wrapped convertor
110      * @param <P> associated augmentation path
111      */
112     public static class RegistrationCloserFromOFJava<F extends DataContainer, P extends AugmentationPath>
113             extends RegistrationCloser<MessageTypeKey<?>, ConvertorFromOFJava<F, P>> {
114         @Override
115         public void close() {
116             getRegistrator().unregister(getKey(), getConverter());
117         }
118     }
119
120     /**
121      * Standalone deregistrator.
122      *
123      * @param <T> target type of wrapped convertor
124      */
125     public static class RegistrationCloserActionToOFJava<T extends DataContainer> extends
126             RegistrationCloser<TypeVersionKey<? extends Action>, ConvertorActionToOFJava<Action, T>> {
127
128         @Override
129         public void close() {
130             getRegistrator().unregister(getKey(), getConverter());
131         }
132     }
133
134     /**
135      * Standalone deregistrator.
136      *
137      * @param <F> source type of wrapped convertor
138      * @param <P> associated augmentation path
139      */
140     public static class RegistrationCloserActionFromOFJava<F extends DataContainer, P extends AugmentationPath> extends
141             RegistrationCloser<MessageTypeKey<?>, ConvertorActionFromOFJava<F, P>> {
142
143         @Override
144         public void close() {
145             getRegistrator().unregister(getKey(), getConverter());
146         }
147     }
148
149     /**
150      * Standalone deregistrator.
151      *
152      * @param <T> target type of wrapped convertor
153      */
154     public static class RegistrationCloserMessageToOFJava<T extends DataContainer,
155             K extends ExperimenterMessageOfChoice, D extends ConvertorData>
156                 extends RegistrationCloser<TypeVersionKey<K>, ConverterMessageToOFJava<K, T, D>> {
157
158         @Override
159         public void close() {
160             getRegistrator().unregister(getKey(), getConverter());
161         }
162     }
163
164     /**
165      * Standalone deregistrator.
166      *
167      * @param <F> source type of wrapped convertor
168      * @param <P> associated augmentation path
169      */
170     public static class RegistrationCloserMessageFromOFJava<F extends DataContainer, P extends AugmentationPath> extends
171             RegistrationCloser<MessageTypeKey<?>, ConvertorMessageFromOFJava<F, P>> {
172
173         @Override
174         public void close() {
175             getRegistrator().unregister(getKey(), getConverter());
176         }
177     }
178 }