Skip to content

Commit 3f65f14

Browse files
Merge pull request #205 from proferabg/master
Better support with other plugins
2 parents 5ce914f + c810905 commit 3f65f14

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

protocolize-velocity/src/main/java/dev/simplix/protocolize/velocity/netty/ProtocolizeBackendChannelInitializer.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,29 @@
1818
public class ProtocolizeBackendChannelInitializer extends BackendChannelInitializer {
1919

2020
private final ChannelInitializer<Channel> wrapped;
21-
private static final Method INIT_METHOD;
22-
23-
static {
24-
try {
25-
INIT_METHOD = ChannelInitializer.class.getDeclaredMethod("initChannel", Channel.class);
26-
INIT_METHOD.setAccessible(true);
27-
} catch (NoSuchMethodException e) {
28-
throw new RuntimeException("Unsupported velocity version. Please use a different version.", e);
29-
}
30-
}
21+
private Method initMethod;
3122

3223
public ProtocolizeBackendChannelInitializer(VelocityServer server, ChannelInitializer<Channel> wrapped) {
3324
super(server);
3425
this.wrapped = wrapped;
26+
27+
if (wrapped != null) {
28+
log.info("Respecting the previous registered BackendChannelInitializer: " + wrapped.getClass().getName());
29+
try {
30+
initMethod = wrapped.getClass().getDeclaredMethod("initChannel", Channel.class);
31+
initMethod.setAccessible(true);
32+
} catch (NoSuchMethodException e) {
33+
log.error("Unsupported backend channel initializer: " + wrapped.getClass().getName(), e);
34+
}
35+
}
3536
}
3637

3738
@Override
3839
protected void initChannel(Channel ch) throws Exception {
3940
try {
40-
if (wrapped != null) {
41+
if (wrapped != null && initMethod != null) {
4142
log.debug("Calling the underlying backend channel initializer: " + wrapped.getClass().getName());
42-
INIT_METHOD.invoke(wrapped, ch);
43+
initMethod.invoke(wrapped, ch);
4344
}
4445
} catch (Exception e) {
4546
log.error("There was a problem while calling the underlying backend channel initializer", e);

0 commit comments

Comments
 (0)