@@ -201,7 +201,7 @@ public class Channel implements VirtualChannel, IChannel, Closeable {
201
201
* termination and simplify the circles into chains which can then be collected easily by the garbage collector.
202
202
* @since FIXME after merge
203
203
*/
204
- private final Ref reference = new Ref ( this ) ;
204
+ private final Ref reference ;
205
205
206
206
/**
207
207
* Registered listeners.
@@ -491,6 +491,7 @@ public Channel(String name, ExecutorService exec, CommandTransport transport, bo
491
491
*/
492
492
protected Channel (ChannelBuilder settings , CommandTransport transport ) throws IOException {
493
493
this .name = settings .getName ();
494
+ this .reference = new Ref (this );
494
495
this .executor = new InterceptingExecutorService (settings .getExecutors (),decorators );
495
496
this .arbitraryCallableAllowed = settings .isArbitraryCallableAllowed ();
496
497
this .remoteClassLoadingAllowed = settings .isRemoteClassLoadingAllowed ();
@@ -537,7 +538,7 @@ public void terminate(IOException e) {
537
538
}
538
539
539
540
/**
540
- * Gets the {@link Ref} for this {@link Channel}. The {@link Ref} will be {@linkplain Ref#clear()}ed when
541
+ * Gets the {@link Ref} for this {@link Channel}. The {@link Ref} will be {@linkplain Ref#clear(Exception )}ed when
541
542
* the channel is terminated in order to break any complex object cycles.
542
543
* @return the {@link Ref} for this {@link Channel}
543
544
* @since FIXME after merge
@@ -896,7 +897,7 @@ public void terminate(IOException e) {
896
897
}
897
898
exportedObjects .abort (e );
898
899
// break any object cycles into simple chains to simplify work for the garbage collector
899
- reference .clear ();
900
+ reference .clear (e );
900
901
} finally {
901
902
notifyAll ();
902
903
}
@@ -1703,17 +1704,29 @@ protected int[] initialValue() {
1703
1704
* @see #reference
1704
1705
*/
1705
1706
/*package*/ static final class Ref {
1707
+ /**
1708
+ * @see {@link Channel#getName()}
1709
+ */
1710
+ @ Nonnull
1711
+ private final String name ;
1712
+
1706
1713
/**
1707
1714
* The channel.
1708
1715
*/
1709
1716
@ CheckForNull
1710
1717
private Channel channel ;
1711
1718
1719
+ /**
1720
+ * If the channel is cleared, retain the reason channel was closed to assist diagnostics.
1721
+ */
1722
+ private Exception cause ;
1723
+
1712
1724
/**
1713
1725
* Constructor.
1714
1726
* @param channel the {@link Channel}.
1715
1727
*/
1716
1728
private Ref (@ CheckForNull Channel channel ) {
1729
+ this .name = channel .getName ();
1717
1730
this .channel = channel ;
1718
1731
}
1719
1732
@@ -1726,12 +1739,28 @@ public Channel channel() {
1726
1739
return channel ;
1727
1740
}
1728
1741
1742
+ /**
1743
+ * If the channel is null, return the cause of the channel termination.
1744
+ */
1745
+ public Exception cause () {
1746
+ return cause ;
1747
+ }
1748
+
1749
+ /**
1750
+ * @see Channel#getName()
1751
+ */
1752
+ @ Nonnull
1753
+ public String name () {
1754
+ return name ;
1755
+ }
1756
+
1729
1757
/**
1730
1758
* Clears the {@link #channel} to signify that the {@link Channel} has been closed and break any complex
1731
1759
* object cycles that might prevent the full garbage collection of the channel's associated object tree.
1732
1760
*/
1733
- public void clear () {
1734
- channel = null ;
1761
+ public void clear (Exception cause ) {
1762
+ this .channel = null ;
1763
+ this .cause = cause ;
1735
1764
}
1736
1765
1737
1766
/**
0 commit comments