Debian Codegraph @

api/src/main/java/jakarta/enterprise/inject/spi/configurator/ObserverMethodConfigurator.java

raw
1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2016, Red Hat, Inc., and individual contributors
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package jakarta.enterprise.inject.spi.configurator;
19
20 import java.lang.annotation.Annotation;
21 import java.lang.reflect.Method;
22 import java.lang.reflect.Type;
23 import java.util.Set;
24
25 import jakarta.enterprise.event.ObserverException;
26 import jakarta.enterprise.event.Reception;
27 import jakarta.enterprise.event.TransactionPhase;
28 import jakarta.enterprise.inject.spi.AfterBeanDiscovery;
29 import jakarta.enterprise.inject.spi.AnnotatedMethod;
30 import jakarta.enterprise.inject.spi.EventContext;
31 import jakarta.enterprise.inject.spi.ObserverMethod;
32 import jakarta.enterprise.inject.spi.ProcessObserverMethod;
33
34 /**
35 * <p>
36 * An {@link ObserverMethodConfigurator} can configure an {@link ObserverMethod}. The container must provide an implementation
37 * of this interface.
38 * </p>
39 *
40 * <p>
41 * This configurator is not thread safe and shall not be used concurrently.
42 * </p>
43 *
44 * <p>CDI Lite implementations are not required to provide support for Portable Extensions.</p>
45 *
46 * @param <T> type of the event the configured ObserverMethod will observe
47 * @author Antoine Sabot-Durand
48 * @see ProcessObserverMethod#configureObserverMethod()
49 * @see AfterBeanDiscovery#addObserverMethod()
50 * @since 2.0
51 */
52 public interface ObserverMethodConfigurator<T> {
53
54 /**
55 * Read observer meta data from a existing {@link java.lang.reflect.Method}
56 *
57 * @param method to read meta data from
58 * @return self
59 */
60 ObserverMethodConfigurator<T> read(Method method);
61
62 /**
63 * Read observer meta data from a existing {@link AnnotatedMethod}
64 *
65 * @param method to read meta data from
66 * @return self
67 */
68 ObserverMethodConfigurator<T> read(AnnotatedMethod<?> method);
69
70 /**
71 * Read observer meta data from a existing ObserverMethod
72 *
73 * @param method to read meta data from
74 * @return self
75 */
76 ObserverMethodConfigurator<T> read(ObserverMethod<T> method);
77
78 /**
79 * Set the class of the Bean containing this observer. If not set, the extension class is used.
80 *
81 * @param type the bean class containing this configurator.
82 * @return self
83 */
84 ObserverMethodConfigurator<T> beanClass(Class<?> type);
85
86 /**
87 * Set the type of the observed event
88 *
89 * @param type of the observed event
90 * @return self
91 */
92 ObserverMethodConfigurator<T> observedType(Type type);
93
94 /**
95 * Add the qualifier to the observed event
96 *
97 * @param qualifier to add to event
98 * @return self
99 */
100 ObserverMethodConfigurator<T> addQualifier(Annotation qualifier);
101
102 /**
103 * Add all the qualifiers to the Observed event
104 *
105 * @param qualifiers to add to event
106 * @return self
107 */
108 ObserverMethodConfigurator<T> addQualifiers(Annotation... qualifiers);
109
110 /**
111 * Add all the qualifiers to the Observed event
112 *
113 * @param qualifiers to add to event
114 * @return self
115 */
116 ObserverMethodConfigurator<T> addQualifiers(Set<Annotation> qualifiers);
117
118 /**
119 * Replace all qualifiers on the Observed event.
120 *
121 * @param qualifiers to put on event
122 * @return self
123 */
124 ObserverMethodConfigurator<T> qualifiers(Annotation... qualifiers);
125
126 /**
127 * Replace all qualifiers on the Observed event.
128 *
129 * @param qualifiers to put on event
130 * @return self
131 */
132 ObserverMethodConfigurator<T> qualifiers(Set<Annotation> qualifiers);
133
134 /**
135 * Set the {@link Reception} mode for the observer to build
136 *
137 * @param reception reception type
138 * @return self
139 */
140 ObserverMethodConfigurator<T> reception(Reception reception);
141
142 /**
143 * Set the {@link TransactionPhase} for the observer to build
144 *
145 * @param transactionPhase phase for the observer
146 * @return self
147 */
148 ObserverMethodConfigurator<T> transactionPhase(TransactionPhase transactionPhase);
149
150 /**
151 * Set the priority for the observer to build
152 *
153 * @param priority priority of the observer
154 * @return self
155 */
156 ObserverMethodConfigurator<T> priority(int priority);
157
158 /**
159 * Define an operation that accepts a context of a fired event.
160 *
161 * @param callback to call for the event notification
162 * @return self
163 */
164 ObserverMethodConfigurator<T> notifyWith(EventConsumer<T> callback);
165
166 /**
167 * Allows modification of the asynchronous status of the observer to build.
168 *
169 * @param async async status
170 * @return self
171 */
172 ObserverMethodConfigurator<T> async(boolean async);
173
174 /**
175 * Represents an operation that accepts a context of a fired event.
176 *
177 * @author Martin Kouba
178 *
179 * @param <T> event type
180 * @see EventContext
181 */
182 @FunctionalInterface
183 interface EventConsumer<T> {
184
185 /**
186 *
187 * @param eventContext the {@link EventContext} used to fire the event
188 * @throws Exception The thrown checked exception is wrapped and rethrown as an (unchecked) {@link ObserverException}
189 */
190 void accept(EventContext<T> eventContext) throws Exception;
191
192 }
193 }