28
28
import org .slf4j .Logger ;
29
29
import org .slf4j .LoggerFactory ;
30
30
31
- public final class CompositeInvocationEventHandler extends AbstractInvocationEventHandler <InvocationContext > {
31
+ public final class CompositeInvocationEventHandler extends AbstractInvocationEventHandler <Object [] > {
32
32
33
33
private static final Logger logger = LoggerFactory .getLogger (CompositeInvocationEventHandler .class );
34
34
35
- private final InvocationEventHandler <InvocationContext >[] handlers ;
35
+ private final InvocationEventHandler <? >[] handlers ;
36
36
37
- @ SuppressWarnings ("unchecked" )
38
- private CompositeInvocationEventHandler (List <InvocationEventHandler <InvocationContext >> handlers ) {
37
+ private CompositeInvocationEventHandler (List <InvocationEventHandler <?>> handlers ) {
39
38
this .handlers = checkNotNull (handlers , "handlers" ).toArray (new InvocationEventHandler [0 ]);
40
- for (InvocationEventHandler <InvocationContext > handler : handlers ) {
39
+ for (InvocationEventHandler <? > handler : handlers ) {
41
40
checkNotNull (handler , "Null handlers are not allowed" );
42
41
}
43
42
}
44
43
45
- public static InvocationEventHandler <InvocationContext > of (
46
- List <InvocationEventHandler <InvocationContext >> handlers ) {
44
+ public static InvocationEventHandler <?> of (List <InvocationEventHandler <?>> handlers ) {
47
45
if (handlers .isEmpty ()) {
48
46
return NoOpInvocationEventHandler .INSTANCE ;
49
47
} else if (handlers .size () == 1 ) {
@@ -54,56 +52,58 @@ public static InvocationEventHandler<InvocationContext> of(
54
52
}
55
53
56
54
@ Nullable
57
- private InvocationEventHandler <InvocationContext > tryGetEnabledHandler (int index ) {
58
- InvocationEventHandler <InvocationContext > handler = handlers [index ];
55
+ private InvocationEventHandler <? > tryGetEnabledHandler (int index ) {
56
+ InvocationEventHandler <? > handler = handlers [index ];
59
57
if (handler .isEnabled ()) {
60
58
return handler ;
61
59
}
62
60
return null ;
63
61
}
64
62
65
63
@ Override
66
- public InvocationContext preInvocation (@ Nonnull Object instance , @ Nonnull Method method , @ Nonnull Object [] args ) {
67
- InvocationContext [] contexts = new InvocationContext [handlers .length ];
64
+ public Object [] preInvocation (@ Nonnull Object instance , @ Nonnull Method method , @ Nonnull Object [] args ) {
65
+ Object [] contexts = new Object [handlers .length ];
68
66
69
67
for (int i = 0 ; i < handlers .length ; i ++) {
70
68
contexts [i ] = handlePreInvocation (tryGetEnabledHandler (i ), instance , method , args );
71
69
}
72
70
73
- return new CompositeInvocationContext ( instance , method , args , contexts ) ;
71
+ return contexts ;
74
72
}
75
73
76
74
@ Override
77
- public void onSuccess (@ Nullable InvocationContext context , @ Nullable Object result ) {
75
+ public void onSuccess (@ Nullable Object [] context , @ Nullable Object result ) {
78
76
debugIfNullContext (context );
79
77
if (context != null ) {
80
- success ((( CompositeInvocationContext ) context ). getContexts () , result );
78
+ success (context , result );
81
79
}
82
80
}
83
81
84
- private void success (@ Nonnull InvocationContext [] contexts , @ Nullable Object result ) {
82
+ @ SuppressWarnings ("unchecked" )
83
+ private void success (@ Nonnull Object [] contexts , @ Nullable Object result ) {
85
84
for (int i = contexts .length - 1 ; i > -1 ; i --) {
86
- handleSuccess (handlers [i ], contexts [i ], result );
85
+ handleSuccess (( InvocationEventHandler < Object >) handlers [i ], contexts [i ], result );
87
86
}
88
87
}
89
88
90
89
@ Override
91
- public void onFailure (@ Nullable InvocationContext context , @ Nonnull Throwable cause ) {
90
+ public void onFailure (@ Nullable Object [] context , @ Nonnull Throwable cause ) {
92
91
debugIfNullContext (context );
93
92
if (context != null ) {
94
- failure ((( CompositeInvocationContext ) context ). getContexts () , cause );
93
+ failure (context , cause );
95
94
}
96
95
}
97
96
98
- private void failure (InvocationContext [] contexts , @ Nonnull Throwable cause ) {
97
+ @ SuppressWarnings ("unchecked" )
98
+ private void failure (Object [] contexts , @ Nonnull Throwable cause ) {
99
99
for (int i = contexts .length - 1 ; i > -1 ; i --) {
100
- handleFailure (handlers [i ], contexts [i ], cause );
100
+ handleFailure (( InvocationEventHandler < Object >) handlers [i ], contexts [i ], cause );
101
101
}
102
102
}
103
103
104
104
@ Nullable
105
- private static InvocationContext handlePreInvocation (
106
- @ Nullable InvocationEventHandler <? extends InvocationContext > handler ,
105
+ private static Object handlePreInvocation (
106
+ @ Nullable InvocationEventHandler <?> handler ,
107
107
Object instance ,
108
108
Method method ,
109
109
Object [] args ) {
@@ -123,7 +123,7 @@ public String toString() {
123
123
}
124
124
125
125
private static void preInvocationFailed (
126
- @ Nullable InvocationEventHandler <? extends InvocationContext > handler ,
126
+ @ Nullable InvocationEventHandler <?> handler ,
127
127
@ Nullable Object instance ,
128
128
Method method ,
129
129
@ Nullable Exception exception ) {
@@ -136,9 +136,9 @@ private static void preInvocationFailed(
136
136
exception );
137
137
}
138
138
139
- private static void handleSuccess (
140
- InvocationEventHandler <? > handler ,
141
- @ Nullable InvocationContext context ,
139
+ private static < T > void handleSuccess (
140
+ InvocationEventHandler <T > handler ,
141
+ @ Nullable T context ,
142
142
@ Nullable Object result ) {
143
143
if (context != null ) {
144
144
try {
@@ -149,9 +149,9 @@ private static void handleSuccess(
149
149
}
150
150
}
151
151
152
- private static void handleFailure (
153
- InvocationEventHandler <? > handler ,
154
- @ Nullable InvocationContext context ,
152
+ private static < T > void handleFailure (
153
+ InvocationEventHandler <T > handler ,
154
+ @ Nullable T context ,
155
155
Throwable cause ) {
156
156
if (context != null ) {
157
157
try {
@@ -164,7 +164,7 @@ private static void handleFailure(
164
164
165
165
private static void eventFailed (
166
166
String event ,
167
- @ Nullable InvocationContext context ,
167
+ @ Nullable Object context ,
168
168
@ Nullable Object result ,
169
169
RuntimeException exception ) {
170
170
logger .warn (
@@ -174,22 +174,4 @@ private static void eventFailed(
174
174
UnsafeArg .of ("result" , result ),
175
175
exception );
176
176
}
177
-
178
- static class CompositeInvocationContext extends DefaultInvocationContext {
179
-
180
- private final InvocationContext [] contexts ;
181
-
182
- CompositeInvocationContext (
183
- Object instance ,
184
- Method method ,
185
- @ Nullable Object [] args ,
186
- InvocationContext [] contexts ) {
187
- super (System .nanoTime (), instance , method , args );
188
- this .contexts = checkNotNull (contexts );
189
- }
190
-
191
- InvocationContext [] getContexts () {
192
- return contexts ;
193
- }
194
- }
195
177
}
0 commit comments