camel git commit: CAMEL-11011 Make all Services Closeable

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

camel git commit: CAMEL-11011 Make all Services Closeable

zregvart
Repository: camel
Updated Branches:
  refs/heads/master d73644159 -> 32f39ea17


CAMEL-11011 Make all Services Closeable

This prodvides Service with default implementation of `close` method
that delegates to `stop`.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/32f39ea1
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/32f39ea1
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/32f39ea1

Branch: refs/heads/master
Commit: 32f39ea17b9d0a292c8a6877089a79ecf8c0479b
Parents: d736441
Author: Zoran Regvart <[hidden email]>
Authored: Tue Mar 14 12:30:07 2017 +0100
Committer: Zoran Regvart <[hidden email]>
Committed: Tue Mar 14 20:58:43 2017 +0100

----------------------------------------------------------------------
 .../src/main/java/org/apache/camel/Service.java | 22 +++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/32f39ea1/camel-core/src/main/java/org/apache/camel/Service.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/Service.java b/camel-core/src/main/java/org/apache/camel/Service.java
index 7ad90ba..da30f43 100644
--- a/camel-core/src/main/java/org/apache/camel/Service.java
+++ b/camel-core/src/main/java/org/apache/camel/Service.java
@@ -16,12 +16,15 @@
  */
 package org.apache.camel;
 
+import java.io.Closeable;
+import java.io.IOException;
+
 /**
  * Represents the core lifecycle API for POJOs which can be started and stopped
  *
  * @version
  */
-public interface Service {
+public interface Service extends Closeable {
 
     /**
      * Starts the service
@@ -36,4 +39,21 @@ public interface Service {
      * @throws Exception is thrown if stopping failed
      */
     void stop() throws Exception;
+
+    /**
+     * Delegates to {@link Service#stop()} so it can be used in
+     * try-with-resources expression.
+     *
+     * @throws IOException per contract of {@link Closeable} if
+     *             {@link Service#stop()} fails
+     */
+    default void close() throws IOException {
+        try {
+            stop();
+        } catch (RuntimeException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new IOException(e);
+        }
+    }
 }

Loading...