diff --git a/pom.xml b/pom.xml index 4c60ef7..fe1638d 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.5.1 + 3.8.0 1.8 1.8 @@ -86,7 +86,7 @@ com.github.siom79.japicmp japicmp-maven-plugin - 0.10.0 + 0.14.0 diff --git a/src/main/java/org/ice4j/socket/jdk8/DelegatingServerSocketChannel.java b/src/main/java/org/ice4j/socket/jdk8/DelegatingServerSocketChannel.java index 52e5003..c860b26 100644 --- a/src/main/java/org/ice4j/socket/jdk8/DelegatingServerSocketChannel.java +++ b/src/main/java/org/ice4j/socket/jdk8/DelegatingServerSocketChannel.java @@ -1,7 +1,7 @@ /* * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal. * - * Copyright @ 2015 Atlassian Pty Ltd + * Copyright @ 2018 - present 8x8, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,9 @@ package org.ice4j.socket.jdk8; import java.io.*; +import java.lang.reflect.*; import java.nio.channels.*; +import java.util.logging.*; import org.ice4j.socket.*; @@ -35,12 +37,30 @@ class DelegatingServerSocketChannel extends BaseDelegatingServerSocketChannel implements SelChImpl { + /** + * The {@link Logger} used by the {@link DelegatingServerSocketChannel} + * class and its instances for logging output. + */ + private static final java.util.logging.Logger classLogger + = java.util.logging.Logger.getLogger( + DelegatingServerSocketChannel.class.getName()); + /** * The view of {@link #delegate} as a SelChImpl interface instance * required by {@link Selector} and related functionality. */ protected final SelChImpl delegateAsSelChImpl; + /** + * The translateAndSetInterestOps method available in java 8. + */ + private final Method translateAndSetInterestOpsMethod; + + /** + * The translateInterestOps method available in java 11. + */ + private final Method translateInterestOpsMethod; + /** * Initializes a new {@code DelegatingServerSocketChannel} instance which is * to delegate (its method calls) to a specific {@code ServerSocketChannel}. @@ -54,6 +74,37 @@ class DelegatingServerSocketChannel delegateAsSelChImpl = (delegate instanceof SelChImpl) ? (SelChImpl) delegate : null; + + Method method; + try + { + method = SelChImpl.class.getMethod( + "translateAndSetInterestOps", + Integer.TYPE, SelectionKeyImpl.class); + } + catch(NoSuchMethodException e) + { + method = null; + + classLogger.log( + Level.SEVERE, + "Cannot find method translateAndSetInterestOps", e); + } + translateAndSetInterestOpsMethod = method; + + try + { + method = SelChImpl.class.getMethod( + "translateInterestOps", Integer.TYPE); + } + catch(NoSuchMethodException e) + { + method = null; + + classLogger.log( + Level.SEVERE, "Cannot find method translateInterestOps", e); + } + translateInterestOpsMethod = method; } /** @@ -95,10 +146,49 @@ class DelegatingServerSocketChannel * * Forwards to {@link #delegate}. */ - @Override + @SuppressWarnings("unused") public void translateAndSetInterestOps(int ops, SelectionKeyImpl sk) { - delegateAsSelChImpl.translateAndSetInterestOps(ops, sk); + try + { + if (translateAndSetInterestOpsMethod != null) + { + translateAndSetInterestOpsMethod.invoke( + delegateAsSelChImpl, ops, sk); + } + } + catch(IllegalAccessException | InvocationTargetException e) + { + classLogger.log( + Level.SEVERE, + "Cannot execute method translateAndSetInterestOpsMethod", e); + } + } + + /** + * {@inheritDoc} + * + * Forwards to {@link #delegate}. + */ + @SuppressWarnings("unused") + public int translateInterestOps(int ops) + { + try + { + if (translateInterestOpsMethod != null) + { + return (Integer) translateInterestOpsMethod.invoke( + delegateAsSelChImpl, ops); + } + } + catch(IllegalAccessException | InvocationTargetException e) + { + classLogger.log( + Level.SEVERE, + "Cannot execute method translateInterestOpsMethod", e); + } + + return 0; } /** diff --git a/src/main/java/org/ice4j/socket/jdk8/DelegatingSocketChannel.java b/src/main/java/org/ice4j/socket/jdk8/DelegatingSocketChannel.java index a4bbfee..637f5b1 100644 --- a/src/main/java/org/ice4j/socket/jdk8/DelegatingSocketChannel.java +++ b/src/main/java/org/ice4j/socket/jdk8/DelegatingSocketChannel.java @@ -1,7 +1,7 @@ /* * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal. * - * Copyright @ 2015 Atlassian Pty Ltd + * Copyright @ 2018 - present 8x8, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,9 @@ package org.ice4j.socket.jdk8; import java.io.*; +import java.lang.reflect.*; import java.nio.channels.*; +import java.util.logging.*; import org.ice4j.socket.*; @@ -34,12 +36,30 @@ class DelegatingSocketChannel extends BaseDelegatingSocketChannel implements SelChImpl { + /** + * The {@link Logger} used by the {@link DelegatingSocketChannel} + * class and its instances for logging output. + */ + private static final java.util.logging.Logger classLogger + = java.util.logging.Logger.getLogger( + DelegatingSocketChannel.class.getName()); + /** * The view of {@link #delegate} as a SelChImpl interface instance * required by {@link Selector} and related functionality. */ protected final SelChImpl delegateAsSelChImpl; + /** + * The translateAndSetInterestOps method available in java 8. + */ + private final Method translateAndSetInterestOpsMethod; + + /** + * The translateInterestOps method available in java 11. + */ + private final Method translateInterestOpsMethod; + /** * Initializes a new {@code DelegatingSocketChannel} instance which is to * delegate (its method calls) to a specific {@code SocketChannel}. @@ -53,6 +73,37 @@ class DelegatingSocketChannel delegateAsSelChImpl = (delegate instanceof SelChImpl) ? (SelChImpl) delegate : null; + + Method method; + try + { + method = SelChImpl.class.getMethod( + "translateAndSetInterestOps", + Integer.TYPE, SelectionKeyImpl.class); + } + catch(NoSuchMethodException e) + { + method = null; + + classLogger.log( + Level.SEVERE, + "Cannot find method translateAndSetInterestOps", e); + } + translateAndSetInterestOpsMethod = method; + + try + { + method = SelChImpl.class.getMethod( + "translateInterestOps", Integer.TYPE); + } + catch(NoSuchMethodException e) + { + method = null; + + classLogger.log( + Level.SEVERE, "Cannot find method translateInterestOps", e); + } + translateInterestOpsMethod = method; } /** @@ -94,10 +145,49 @@ class DelegatingSocketChannel * * Forwards to {@link #delegate}. */ - @Override + @SuppressWarnings("unused") public void translateAndSetInterestOps(int ops, SelectionKeyImpl sk) { - delegateAsSelChImpl.translateAndSetInterestOps(ops, sk); + try + { + if (translateAndSetInterestOpsMethod != null) + { + translateAndSetInterestOpsMethod.invoke( + delegateAsSelChImpl, ops, sk); + } + } + catch(IllegalAccessException | InvocationTargetException e) + { + classLogger.log( + Level.SEVERE, + "Cannot execute method translateAndSetInterestOpsMethod", e); + } + } + + /** + * {@inheritDoc} + * + * Forwards to {@link #delegate}. + */ + @SuppressWarnings("unused") + public int translateInterestOps(int ops) + { + try + { + if (translateInterestOpsMethod != null) + { + return (Integer) translateInterestOpsMethod.invoke( + delegateAsSelChImpl, ops); + } + } + catch(IllegalAccessException | InvocationTargetException e) + { + classLogger.log( + Level.SEVERE, + "Cannot execute method translateInterestOpsMethod", e); + } + + return 0; } /**