flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tillrohrmann <...@git.apache.org>
Subject [GitHub] flink pull request #3198: [FLINK-5626] Improved resource deallocation in Roc...
Date Tue, 24 Jan 2017 11:10:49 GMT
Github user tillrohrmann commented on a diff in the pull request:

    https://github.com/apache/flink/pull/3198#discussion_r97522787
  
    --- Diff: flink-core/src/main/java/org/apache/flink/util/IOUtils.java ---
    @@ -216,9 +215,52 @@ public static void closeSocket(final Socket sock) {
     	}
     
     	/**
    +	 * Closes all {@link AutoCloseable} objects in the parameter, suppressing exceptions.
Exception will be emitted
    +	 * after calling close() on every object.
    +	 *
    +	 * @param closeables iterable with closeables to close.
    +	 * @throws Exception collected exceptions that occurred during closing
    +	 */
    +	public static void closeAll(Iterable<? extends AutoCloseable> closeables) throws
Exception {
    +		if (null != closeables) {
    +
    +			Exception collectedExceptions = null;
    +
    +			for (AutoCloseable closeable : closeables) {
    +				try {
    +					if (null != closeable) {
    +						closeable.close();
    +					}
    +				} catch (Exception e) {
    +					if (null == collectedExceptions) {
    +						collectedExceptions = e;
    +					} else {
    +						collectedExceptions.addSuppressed(e);
    +					}
    --- End diff --
    
    Here you could use `collectedExceptions = ExceptionUtils.firstOrSuppressed(e, collectedExceptions);`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message