You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/03/14 07:53:12 UTC

[camel] branch master updated (ed26e22 -> 094b8eb)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from ed26e22  Fixed tests
     new 4e67b1e  Move lifecycle api into its own api for camel context.
     new 094b8eb  Fixed tests

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../main/java/org/apache/camel/CamelContext.java   |  44 +-------
 .../org/apache/camel/CamelContextLifecycle.java    | 124 +++++++++++++++++++++
 .../camel/impl/lw/ImmutableCamelContext.java       |   2 +-
 .../directvm/AbstractDirectVmTestSupport.java      |   8 +-
 .../directvm/DirectVmConsumerExpressionTest.java   |  23 ++--
 5 files changed, 140 insertions(+), 61 deletions(-)
 create mode 100644 core/camel-api/src/main/java/org/apache/camel/CamelContextLifecycle.java


[camel] 01/02: Move lifecycle api into its own api for camel context.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 4e67b1e73ae3a234ada56200d07ac9013a003757
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Mar 14 07:33:03 2020 +0100

    Move lifecycle api into its own api for camel context.
---
 .../main/java/org/apache/camel/CamelContext.java   |  44 +-------
 .../org/apache/camel/CamelContextLifecycle.java    | 124 +++++++++++++++++++++
 .../camel/impl/lw/ImmutableCamelContext.java       |   2 +-
 3 files changed, 127 insertions(+), 43 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/CamelContext.java b/core/camel-api/src/main/java/org/apache/camel/CamelContext.java
index 96471ca..a51c1d7 100644
--- a/core/camel-api/src/main/java/org/apache/camel/CamelContext.java
+++ b/core/camel-api/src/main/java/org/apache/camel/CamelContext.java
@@ -16,7 +16,6 @@
  */
 package org.apache.camel;
 
-import java.io.IOException;
 import java.util.Collection;
 import java.util.Date;
 import java.util.List;
@@ -59,7 +58,7 @@ import org.apache.camel.support.jsse.SSLContextParameters;
  * Interface used to represent the CamelContext used to configure routes and the
  * policies to use during message exchanges between endpoints.
  * <p/>
- * The CamelContext offers the following methods to control the lifecycle:
+ * The CamelContext offers the following methods {@link CamelContextLifecycle} to control the lifecycle:
  * <ul>
  *   <li>{@link #start()}  - to start (<b>important:</b> the start method is not blocked, see more details
  *     <a href="http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html">here</a>)</li>
@@ -80,20 +79,7 @@ import org.apache.camel.support.jsse.SSLContextParameters;
  * <p/>
  * For more advanced APIs with {@link CamelContext} see {@link ExtendedCamelContext}, which you can obtain via the adapt method.
  */
-public interface CamelContext extends RuntimeConfiguration, AutoCloseable {
-
-    boolean isStarted();
-    boolean isStarting();
-    boolean isStopped();
-    boolean isStopping();
-    boolean isSuspended();
-    boolean isSuspending();
-    boolean isRunAllowed();
-    void init();
-    void suspend();
-    void resume();
-    void shutdown();
-    void close() throws IOException;
+public interface CamelContext extends CamelContextLifecycle, RuntimeConfiguration {
 
     /**
      * Adapts this {@link org.apache.camel.CamelContext} to the specialized type.
@@ -128,25 +114,6 @@ public interface CamelContext extends RuntimeConfiguration, AutoCloseable {
     boolean isVetoStarted();
 
     /**
-     * Starts the {@link CamelContext} (<b>important:</b> the start method is not blocked, see more details
-     *     <a href="http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html">here</a>)</li>.
-     * <p/>
-     * See more details at the class-level javadoc of this class.
-     *
-     * @throws RuntimeCamelException is thrown if starting failed
-     */
-    void start();
-
-    /**
-     * Stop and shutdown the {@link CamelContext} (will stop all routes/components/endpoints etc and clear internal state/cache).
-     * <p/>
-     * See more details at the class-level javadoc of this class.
-     *
-     * @throws RuntimeCamelException is thrown if stopping failed
-     */
-    void stop();
-
-    /**
      * Gets the name (id) of the this CamelContext.
      *
      * @return the name
@@ -205,13 +172,6 @@ public interface CamelContext extends RuntimeConfiguration, AutoCloseable {
     String getVersion();
 
     /**
-     * Get the status of this CamelContext
-     *
-     * @return the status
-     */
-    ServiceStatus getStatus();
-
-    /**
      * Gets the uptime in a human readable format
      *
      * @return the uptime in days/hours/minutes
diff --git a/core/camel-api/src/main/java/org/apache/camel/CamelContextLifecycle.java b/core/camel-api/src/main/java/org/apache/camel/CamelContextLifecycle.java
new file mode 100644
index 0000000..7c4b327
--- /dev/null
+++ b/core/camel-api/src/main/java/org/apache/camel/CamelContextLifecycle.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel;
+
+/**
+ * Lifecycle API for {@link CamelContext}.
+ */
+public interface CamelContextLifecycle extends AutoCloseable {
+
+    /**
+     * Starts the {@link CamelContext} (<b>important:</b> the start method is not blocked, see more details
+     *     <a href="http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html">here</a>)</li>.
+     * <p/>
+     * See more details at the class-level javadoc of this class.
+     *
+     * @throws RuntimeCamelException is thrown if starting failed
+     */
+    void start();
+
+    /**
+     * Stop and shutdown the {@link CamelContext} (will stop all routes/components/endpoints etc and clear internal state/cache).
+     * <p/>
+     * See more details at the class-level javadoc of this class.
+     *
+     * @throws RuntimeCamelException is thrown if stopping failed
+     */
+    void stop();
+
+    /**
+     * Whether the CamelContext is started
+     *
+     * @return true if this CamelContext has been started
+     */
+    boolean isStarted();
+
+    /**
+     * Whether the CamelContext is starting
+     *
+     * @return true if this CamelContext is being started
+     */
+    boolean isStarting();
+
+    /**
+     * Whether the CamelContext is stopping
+     *
+     * @return true if this CamelContext is in the process of stopping
+     */
+    boolean isStopping();
+
+    /**
+     * Whether the CamelContext is stopped
+     *
+     * @return true if this CamelContext is stopped
+     */
+    boolean isStopped();
+
+    /**
+     * Whether the CamelContext is suspending
+     *
+     * @return true if this CamelContext is in the process of suspending
+     */
+    boolean isSuspending();
+
+    /**
+     * Whether the CamelContext is suspended
+     *
+     * @return true if this CamelContext is suspended
+     */
+    boolean isSuspended();
+
+    /**
+     * Helper methods so the CamelContext knows if it should keep running.
+     * Returns <tt>false</tt> if the CamelContext is being stopped or is stopped.
+     *
+     * @return <tt>true</tt> if the CamelContext should continue to run.
+     */
+    boolean isRunAllowed();
+
+    void init();
+
+    /**
+     * Suspends the CamelContext.
+     */
+    void suspend();
+
+    /**
+     * Resumes the CamelContext.
+     */
+    void resume();
+
+    /**
+     * Shutdown the CamelContext, which means it cannot be started again.
+     */
+    void shutdown();
+
+    /**
+     * Closes (Shutdown) the CamelContext, which means it cannot be started again.
+     *
+     * @throws Exception is thrown if shutdown failed
+     */
+    void close() throws Exception;
+
+    /**
+     * Get the status of this CamelContext
+     *
+     * @return the status
+     */
+    ServiceStatus getStatus();
+
+}
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/ImmutableCamelContext.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/ImmutableCamelContext.java
index 14313aa..71ffe85 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/ImmutableCamelContext.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/ImmutableCamelContext.java
@@ -229,7 +229,7 @@ public class ImmutableCamelContext implements ExtendedCamelContext, CatalogCamel
     }
 
     @Override
-    public void close() throws IOException {
+    public void close() throws Exception {
         delegate.close();
     }
 


[camel] 02/02: Fixed tests

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 094b8eb68850c1881ea3b6435c99b40a996bf319
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Mar 14 08:36:05 2020 +0100

    Fixed tests
---
 .../directvm/AbstractDirectVmTestSupport.java      |  8 ++++----
 .../directvm/DirectVmConsumerExpressionTest.java   | 23 +++++++++-------------
 2 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/component/directvm/AbstractDirectVmTestSupport.java b/core/camel-core/src/test/java/org/apache/camel/component/directvm/AbstractDirectVmTestSupport.java
index 35a7c6e..ac87c7b 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/directvm/AbstractDirectVmTestSupport.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/directvm/AbstractDirectVmTestSupport.java
@@ -21,7 +21,6 @@ import org.apache.camel.ContextTestSupport;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.support.service.ServiceHelper;
 import org.junit.After;
 import org.junit.Before;
 
@@ -40,9 +39,9 @@ public abstract class AbstractDirectVmTestSupport extends ContextTestSupport {
         doPostSetup();
 
         context2 = new DefaultCamelContext();
+        context2.start();
         template2 = context2.createProducerTemplate();
-
-        ServiceHelper.startService(template2, context2);
+        template2.start();
 
         // add routes after CamelContext has been started
         RouteBuilder routeBuilder = createRouteBuilderForSecondContext();
@@ -58,7 +57,8 @@ public abstract class AbstractDirectVmTestSupport extends ContextTestSupport {
     @Override
     @After
     public void tearDown() throws Exception {
-        ServiceHelper.stopService(context2, template2);
+        template2.stop();
+        context2.stop();
 
         super.tearDown();
     }
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/directvm/DirectVmConsumerExpressionTest.java b/core/camel-core/src/test/java/org/apache/camel/component/directvm/DirectVmConsumerExpressionTest.java
index 95e1cbf..a50d696 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/directvm/DirectVmConsumerExpressionTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/directvm/DirectVmConsumerExpressionTest.java
@@ -21,7 +21,6 @@ import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.support.service.ServiceHelper;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -44,31 +43,27 @@ public class DirectVmConsumerExpressionTest extends ContextTestSupport {
         context3 = new DefaultCamelContext();
         context4 = new DefaultCamelContext();
 
-        ServiceHelper.startService(context2);
-        ServiceHelper.startService(context3);
-        ServiceHelper.startService(context4);
+        context2.start();
+        context3.start();
+        context4.start();
 
         // add routes after CamelContext has been started
         RouteBuilder routeBuilder = createRouteBuilderCamelContext2();
-        if (routeBuilder != null) {
-            context2.addRoutes(routeBuilder);
-        }
+        context2.addRoutes(routeBuilder);
 
         routeBuilder = createRouteBuilderCamelContext3();
-        if (routeBuilder != null) {
-            context3.addRoutes(routeBuilder);
-        }
+        context3.addRoutes(routeBuilder);
 
         routeBuilder = createRouteBuilderCamelContext4();
-        if (routeBuilder != null) {
-            context4.addRoutes(routeBuilder);
-        }
+        context4.addRoutes(routeBuilder);
     }
 
     @Override
     @After
     public void tearDown() throws Exception {
-        ServiceHelper.stopService(context2, context3, context4);
+        context2.stop();
+        context3.stop();
+        context4.stop();
         super.tearDown();
     }