diff options
author | Benoit Foucher <benoit@zeroc.com> | 2017-01-30 15:13:27 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2017-01-30 15:13:27 +0100 |
commit | 25fed02adb3fd0d41da3f4dff027e59c424120bc (patch) | |
tree | d701310c3e03b54b5a7d9dc90738e00e35066da7 /java/src | |
parent | slice2cs build failure (diff) | |
download | ice-25fed02adb3fd0d41da3f4dff027e59c424120bc.tar.bz2 ice-25fed02adb3fd0d41da3f4dff027e59c424120bc.tar.xz ice-25fed02adb3fd0d41da3f4dff027e59c424120bc.zip |
Fixed ICE-7493 - Support for java try-with and Python with statements for the Ice.Communicator
Diffstat (limited to 'java/src')
3 files changed, 35 insertions, 8 deletions
diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/CommunicatorI.java b/java/src/Ice/src/main/java/com/zeroc/Ice/CommunicatorI.java index 3ee8b9f7054..1f9041840b0 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/CommunicatorI.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/CommunicatorI.java @@ -13,9 +13,16 @@ public final class CommunicatorI implements Communicator { @Override public void + close() + { + _instance.destroy(false); // Don't allow destroy to be interrupted if called from try with statement. + } + + @Override + public void destroy() { - _instance.destroy(); + _instance.destroy(true); // Destroy is interruptible when call explicitly. } @Override @@ -315,7 +322,7 @@ public final class CommunicatorI implements Communicator } catch(RuntimeException ex) { - _instance.destroy(); + _instance.destroy(false); throw ex; } } diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/Util.java b/java/src/Ice/src/main/java/com/zeroc/Ice/Util.java index ff50bab15e7..b4e008352da 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/Util.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/Util.java @@ -84,8 +84,21 @@ public final class Util /** * Encapsulates the results of a call to initialize(). **/ - public static class InitializeResult + public static class InitializeResult implements java.lang.AutoCloseable { + @Override + public void close() + { + try + { + communicator.close(); + } + catch(java.lang.Exception ex) + { + assert(false); + } + } + /** The new communicator. */ public Communicator communicator; diff --git a/java/src/Ice/src/main/java/com/zeroc/IceInternal/Instance.java b/java/src/Ice/src/main/java/com/zeroc/IceInternal/Instance.java index 5bf70b1d2f6..305fee3f5d3 100644 --- a/java/src/Ice/src/main/java/com/zeroc/IceInternal/Instance.java +++ b/java/src/Ice/src/main/java/com/zeroc/IceInternal/Instance.java @@ -1171,7 +1171,7 @@ public final class Instance implements com.zeroc.Ice.ClassResolver } catch(com.zeroc.Ice.LocalException ex) { - destroy(); + destroy(false); throw ex; } } @@ -1401,9 +1401,9 @@ public final class Instance implements com.zeroc.Ice.ClassResolver // @SuppressWarnings("deprecation") public void - destroy() + destroy(boolean interruptible) { - if(Thread.interrupted()) + if(interruptible && Thread.interrupted()) { throw new com.zeroc.Ice.OperationInterruptedException(); } @@ -1423,7 +1423,10 @@ public final class Instance implements com.zeroc.Ice.ClassResolver } catch(InterruptedException ex) { - throw new com.zeroc.Ice.OperationInterruptedException(); + if(interruptible) + { + throw new com.zeroc.Ice.OperationInterruptedException(); + } } } @@ -1532,7 +1535,10 @@ public final class Instance implements com.zeroc.Ice.ClassResolver } catch(InterruptedException ex) { - throw new com.zeroc.Ice.OperationInterruptedException(); + if(interruptible) + { + throw new com.zeroc.Ice.OperationInterruptedException(); + } } // @@ -1624,6 +1630,7 @@ public final class Instance implements com.zeroc.Ice.ClassResolver { if(_state == StateDestroyInProgress) { + assert(interruptible); _state = StateActive; notifyAll(); } |