|
1 | 1 | package core.framework.internal.web.sse;
|
2 | 2 |
|
3 | 3 | import core.framework.web.Request;
|
| 4 | +import core.framework.web.rate.LimitRate; |
4 | 5 | import core.framework.web.sse.Channel;
|
5 | 6 | import core.framework.web.sse.ChannelListener;
|
6 | 7 |
|
7 |
| -import java.lang.annotation.Annotation; |
8 | 8 | import java.lang.reflect.Method;
|
9 | 9 |
|
10 | 10 | class ChannelSupport<T> {
|
11 | 11 | final ChannelListener<T> listener;
|
12 | 12 | final ServerSentEventContextImpl<T> context;
|
13 | 13 | final ServerSentEventBuilder<T> builder;
|
14 |
| - final Method targetMethod; |
| 14 | + final LimitRate limitRate; |
15 | 15 |
|
16 | 16 | ChannelSupport(ChannelListener<T> listener, Class<T> eventClass, ServerSentEventContextImpl<T> context) {
|
17 | 17 | this.listener = listener;
|
18 | 18 | this.context = context;
|
19 | 19 | builder = new ServerSentEventBuilder<>(eventClass);
|
| 20 | + limitRate = limitRate(listener); |
| 21 | + } |
| 22 | + |
| 23 | + private LimitRate limitRate(ChannelListener<T> listener) { |
20 | 24 | try {
|
21 |
| - this.targetMethod = listener.getClass().getMethod("onConnect", Request.class, Channel.class, String.class); |
| 25 | + Method targetMethod = listener.getClass().getMethod("onConnect", Request.class, Channel.class, String.class); |
| 26 | + LimitRate limitRate = targetMethod.getDeclaredAnnotation(LimitRate.class); |
| 27 | + if (limitRate == null) |
| 28 | + limitRate = listener.getClass().getDeclaredAnnotation(LimitRate.class); |
| 29 | + return limitRate; |
22 | 30 | } catch (NoSuchMethodException e) {
|
23 | 31 | throw new Error("failed to get listener.onConnect method", e);
|
24 | 32 | }
|
25 | 33 | }
|
26 |
| - |
27 |
| - <V extends Annotation> V annotation(Class<V> annotationClass) { |
28 |
| - V annotation = targetMethod.getDeclaredAnnotation(annotationClass); |
29 |
| - if (annotation == null) |
30 |
| - annotation = listener.getClass().getDeclaredAnnotation(annotationClass); |
31 |
| - return annotation; |
32 |
| - } |
33 | 34 | }
|
0 commit comments