File tree Expand file tree Collapse file tree 1 file changed +13
-12
lines changed
protocolize-velocity/src/main/java/dev/simplix/protocolize/velocity/netty Expand file tree Collapse file tree 1 file changed +13
-12
lines changed Original file line number Diff line number Diff line change 1818public 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 );
You can’t perform that action at this time.
0 commit comments