You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ha...@apache.org on 2010/05/26 04:19:13 UTC
svn commit: r948293 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/component/timer/TimerEndpoint.java
test/java/org/apache/camel/component/timer/TimerRestartTest.java
Author: hadrian
Date: Wed May 26 02:19:12 2010
New Revision: 948293
URL: http://svn.apache.org/viewvc?rev=948293&view=rev
Log:
CAMEL-2751. Patch applied with thanks
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerRestartTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java?rev=948293&r1=948292&r2=948293&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java Wed May 26 02:19:12 2010
@@ -23,6 +23,7 @@ import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.Service;
import org.apache.camel.impl.DefaultEndpoint;
import org.apache.camel.spi.ManagementAware;
import org.springframework.jmx.export.annotation.ManagedAttribute;
@@ -34,7 +35,7 @@ import org.springframework.jmx.export.an
* @version $Revision$
*/
@ManagedResource(description = "Managed Timer Endpoint")
-public class TimerEndpoint extends DefaultEndpoint implements ManagementAware<TimerEndpoint> {
+public class TimerEndpoint extends DefaultEndpoint implements Service, ManagementAware<TimerEndpoint> {
private String timerName;
private Date time;
private long period = 1000;
@@ -72,6 +73,14 @@ public class TimerEndpoint extends Defau
return this;
}
+ public void start() throws Exception {
+ // do nothing, the timer will be set when the first consumer will request it
+ }
+
+ public void stop() throws Exception {
+ setTimer(null);
+ }
+
@ManagedAttribute(description = "Timer Name")
public String getTimerName() {
if (timerName == null) {
@@ -139,15 +148,19 @@ public class TimerEndpoint extends Defau
}
public Timer getTimer() {
- if (timer == null) {
- TimerComponent tc = (TimerComponent) getComponent();
- timer = tc.getTimer(this);
+ synchronized (this) {
+ if (timer == null) {
+ TimerComponent tc = (TimerComponent) getComponent();
+ timer = tc.getTimer(this);
+ }
+ return timer;
}
- return timer;
}
public void setTimer(Timer timer) {
- this.timer = timer;
+ synchronized (this) {
+ this.timer = timer;
+ }
}
@ManagedAttribute(description = "Camel id")
@@ -159,5 +172,4 @@ public class TimerEndpoint extends Defau
public String getEndpointUri() {
return super.getEndpointUri();
}
-
}
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerRestartTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerRestartTest.java?rev=948293&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerRestartTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerRestartTest.java Wed May 26 02:19:12 2010
@@ -0,0 +1,52 @@
+/**
+ * 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.component.timer;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class TimerRestartTest extends ContextTestSupport {
+ public void testTimerRestart() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(1);
+
+ assertMockEndpointsSatisfied();
+
+ context.stop();
+
+ mock.reset();
+
+ context.start();
+
+ mock.expectedMinimumMessageCount(1);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("timer://foo?fixedRate=true&delay=0&period=500").to("mock:result");
+ }
+ };
+ }
+}
\ No newline at end of file