You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2014/11/03 16:52:11 UTC
[27/29] git commit: more code review for brooklyn upgrade
more code review for brooklyn upgrade
call the class RuntimeTimeoutException, rename methods to Duration.{upper,lower}Bound, and fix reference to onUnmanaged
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/724ee578
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/724ee578
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/724ee578
Branch: refs/heads/master
Commit: 724ee5787850f00dd4e5adbaf4c9dbf645de13ac
Parents: d3f6e34
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu Oct 30 09:06:18 2014 -0500
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Oct 31 09:39:51 2014 -0500
----------------------------------------------------------------------
.../rebind/PeriodicDeltaChangeListener.java | 6 ++--
.../event/basic/DependentConfiguration.java | 35 ++++++++++---------
.../test/java/brooklyn/util/task/TasksTest.java | 8 ++---
.../exceptions/RuntimeTimeoutException.java | 36 ++++++++++++++++++++
.../util/exceptions/TimeoutException.java | 36 --------------------
.../main/java/brooklyn/util/time/Duration.java | 15 ++++++--
6 files changed, 75 insertions(+), 61 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/724ee578/core/src/main/java/brooklyn/entity/rebind/PeriodicDeltaChangeListener.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/PeriodicDeltaChangeListener.java b/core/src/main/java/brooklyn/entity/rebind/PeriodicDeltaChangeListener.java
index 9b71633..3ae6916 100644
--- a/core/src/main/java/brooklyn/entity/rebind/PeriodicDeltaChangeListener.java
+++ b/core/src/main/java/brooklyn/entity/rebind/PeriodicDeltaChangeListener.java
@@ -194,13 +194,13 @@ public class PeriodicDeltaChangeListener implements ChangeListener {
CountdownTimer expiry = timeout.countdownTimer();
scheduledTask.cancel(false);
try {
- waitForPendingComplete(expiry.getDurationRemaining().minimum(Duration.ZERO).add(graceTimeoutForSubsequentOperations));
+ waitForPendingComplete(expiry.getDurationRemaining().lowerBound(Duration.ZERO).add(graceTimeoutForSubsequentOperations));
} catch (Exception e) {
throw Exceptions.propagate(e);
}
- scheduledTask.blockUntilEnded(expiry.getDurationRemaining().minimum(Duration.ZERO).add(graceTimeoutForSubsequentOperations));
+ scheduledTask.blockUntilEnded(expiry.getDurationRemaining().lowerBound(Duration.ZERO).add(graceTimeoutForSubsequentOperations));
scheduledTask.cancel(true);
- boolean reallyEnded = Tasks.blockUntilInternalTasksEnded(scheduledTask, expiry.getDurationRemaining().minimum(Duration.ZERO).add(graceTimeoutForSubsequentOperations));
+ boolean reallyEnded = Tasks.blockUntilInternalTasksEnded(scheduledTask, expiry.getDurationRemaining().lowerBound(Duration.ZERO).add(graceTimeoutForSubsequentOperations));
if (!reallyEnded) {
LOG.warn("Persistence tasks took too long to complete when stopping persistence (ignoring): "+scheduledTask);
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/724ee578/core/src/main/java/brooklyn/event/basic/DependentConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/event/basic/DependentConfiguration.java b/core/src/main/java/brooklyn/event/basic/DependentConfiguration.java
index 51af110..b1d1526 100644
--- a/core/src/main/java/brooklyn/event/basic/DependentConfiguration.java
+++ b/core/src/main/java/brooklyn/event/basic/DependentConfiguration.java
@@ -60,7 +60,7 @@ import brooklyn.util.collections.MutableMap;
import brooklyn.util.exceptions.CompoundRuntimeException;
import brooklyn.util.exceptions.Exceptions;
import brooklyn.util.exceptions.NotManagedException;
-import brooklyn.util.exceptions.TimeoutException;
+import brooklyn.util.exceptions.RuntimeTimeoutException;
import brooklyn.util.guava.Functionals;
import brooklyn.util.guava.Maybe;
import brooklyn.util.task.BasicExecutionContext;
@@ -189,16 +189,16 @@ public class DependentConfiguration {
* now find a different problem. */
private final static boolean DEFAULT_IGNORE_UNMANAGED = false;
- final Entity source;
- final AttributeSensor<T> sensor;
- final Predicate<? super T> ready;
- final List<AttributeAndSensorCondition<?>> abortSensorConditions;
- final String blockingDetails;
- final Function<? super T,? extends V> postProcess;
- final Duration timeout;
- final Maybe<V> onTimeout;
- final boolean ignoreUnmanaged;
- final Maybe<V> onUnmanaged;
+ protected final Entity source;
+ protected final AttributeSensor<T> sensor;
+ protected final Predicate<? super T> ready;
+ protected final List<AttributeAndSensorCondition<?>> abortSensorConditions;
+ protected final String blockingDetails;
+ protected final Function<? super T,? extends V> postProcess;
+ protected final Duration timeout;
+ protected final Maybe<V> onTimeout;
+ protected final boolean ignoreUnmanaged;
+ protected final Maybe<V> onUnmanaged;
// TODO onError Continue / Throw / Return(V)
protected WaitInTaskForAttributeReady(Builder<T, V> builder) {
@@ -311,7 +311,7 @@ public class DependentConfiguration {
}
if (timer.isExpired()) {
if (onTimeout.isPresent()) return onTimeout.get();
- throw new TimeoutException("Unsatisfied after "+Duration.sinceUtc(start));
+ throw new RuntimeTimeoutException("Unsatisfied after "+Duration.sinceUtc(start));
}
}
@@ -328,14 +328,17 @@ public class DependentConfiguration {
}
// check any subscribed values which have come in first
- while (!publishedValues.isEmpty()) {
- synchronized (publishedValues) { value = publishedValues.pop(); }
+ while (true) {
+ synchronized (publishedValues) {
+ if (publishedValues.isEmpty()) break;
+ value = publishedValues.pop();
+ }
if (ready(value)) break;
}
// if unmanaged then ignore the other abort conditions
if (!ignoreUnmanaged && Entities.isNoLongerManaged(entity)) {
- if (onTimeout.isPresent()) return onTimeout.get();
+ if (onUnmanaged.isPresent()) return onUnmanaged.get();
throw new NotManagedException(entity);
}
@@ -343,7 +346,7 @@ public class DependentConfiguration {
throw new CompoundRuntimeException("Aborted waiting for ready from "+source+" "+sensor, abortionExceptions);
}
- nextPeriod = nextPeriod.times(2).maximum(maxPeriod);
+ nextPeriod = nextPeriod.times(2).upperBound(maxPeriod);
}
if (LOG.isDebugEnabled()) LOG.debug("Attribute-ready for {} in entity {}", sensor, source);
return postProcess(value);
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/724ee578/core/src/test/java/brooklyn/util/task/TasksTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/util/task/TasksTest.java b/core/src/test/java/brooklyn/util/task/TasksTest.java
index 68aa2ea..d5e2bb4 100644
--- a/core/src/test/java/brooklyn/util/task/TasksTest.java
+++ b/core/src/test/java/brooklyn/util/task/TasksTest.java
@@ -136,16 +136,16 @@ public class TasksTest extends BrooklynAppUnitTestSupport {
t = Tasks.requiring(Repeater.create().until(Callables.returning(true)).every(Duration.millis(1))).build();
app.getExecutionContext().submit(t);
- t.get(Duration.ONE_SECOND);
+ t.get(Duration.TEN_SECONDS);
t = Tasks.testing(Repeater.create().until(Callables.returning(true)).every(Duration.millis(1))).build();
app.getExecutionContext().submit(t);
- Assert.assertEquals(t.get(Duration.ONE_SECOND), true);
+ Assert.assertEquals(t.get(Duration.TEN_SECONDS), true);
t = Tasks.requiring(Repeater.create().until(Callables.returning(false)).limitIterationsTo(2).every(Duration.millis(1))).build();
app.getExecutionContext().submit(t);
try {
- t.get(Duration.ONE_SECOND);
+ t.get(Duration.TEN_SECONDS);
Assert.fail("Should have failed");
} catch (Exception e) {
// expected
@@ -153,7 +153,7 @@ public class TasksTest extends BrooklynAppUnitTestSupport {
t = Tasks.testing(Repeater.create().until(Callables.returning(false)).limitIterationsTo(2).every(Duration.millis(1))).build();
app.getExecutionContext().submit(t);
- Assert.assertEquals(t.get(Duration.ONE_SECOND), false);
+ Assert.assertEquals(t.get(Duration.TEN_SECONDS), false);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/724ee578/utils/common/src/main/java/brooklyn/util/exceptions/RuntimeTimeoutException.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/brooklyn/util/exceptions/RuntimeTimeoutException.java b/utils/common/src/main/java/brooklyn/util/exceptions/RuntimeTimeoutException.java
new file mode 100644
index 0000000..865ae73
--- /dev/null
+++ b/utils/common/src/main/java/brooklyn/util/exceptions/RuntimeTimeoutException.java
@@ -0,0 +1,36 @@
+/*
+ * 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 brooklyn.util.exceptions;
+
+public class RuntimeTimeoutException extends IllegalStateException {
+
+ private static final long serialVersionUID = -3359163414517503809L;
+
+ public RuntimeTimeoutException() {
+ super("timeout");
+ }
+
+ public RuntimeTimeoutException(String message) {
+ super(message);
+ }
+
+ public RuntimeTimeoutException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/724ee578/utils/common/src/main/java/brooklyn/util/exceptions/TimeoutException.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/brooklyn/util/exceptions/TimeoutException.java b/utils/common/src/main/java/brooklyn/util/exceptions/TimeoutException.java
deleted file mode 100644
index c31512f..0000000
--- a/utils/common/src/main/java/brooklyn/util/exceptions/TimeoutException.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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 brooklyn.util.exceptions;
-
-public class TimeoutException extends IllegalStateException {
-
- private static final long serialVersionUID = -3359163414517503809L;
-
- public TimeoutException() {
- super("timeout");
- }
-
- public TimeoutException(String message) {
- super(message);
- }
-
- public TimeoutException(String message, Throwable cause) {
- super(message, cause);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/724ee578/utils/common/src/main/java/brooklyn/util/time/Duration.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/brooklyn/util/time/Duration.java b/utils/common/src/main/java/brooklyn/util/time/Duration.java
index c6622ba..3950bc7 100644
--- a/utils/common/src/main/java/brooklyn/util/time/Duration.java
+++ b/utils/common/src/main/java/brooklyn/util/time/Duration.java
@@ -282,15 +282,26 @@ public class Duration implements Comparable<Duration>, Serializable {
}
/** returns the larger of this value or the argument */
- public Duration minimum(Duration alternateMinimumValue) {
+ public Duration lowerBound(Duration alternateMinimumValue) {
if (isShorterThan(alternateMinimumValue)) return alternateMinimumValue;
return this;
}
/** returns the smaller of this value or the argument */
- public Duration maximum(Duration alternateMaximumValue) {
+ public Duration upperBound(Duration alternateMaximumValue) {
if (isLongerThan(alternateMaximumValue)) return alternateMaximumValue;
return this;
}
+ /** @deprecated since 0.7.0 use {@link #lowerBound(Duration)} */ @Deprecated
+ public Duration minimum(Duration alternateMinimumValue) {
+ return lowerBound(alternateMinimumValue);
+ }
+
+ /** @deprecated since 0.7.0 use {@link #upperBound(Duration)} */ @Deprecated
+ /** returns the smaller of this value or the argument */
+ public Duration maximum(Duration alternateMaximumValue) {
+ return upperBound(alternateMaximumValue);
+ }
+
}