From a9b3982b536432c3b268e03cf731f7e8dabecb19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20B=C3=BClte?= Date: Tue, 24 Sep 2024 13:20:45 +0200 Subject: [PATCH 1/2] Add draft for object sleeper #495 --- .../flowcontrol/ObjectSleeper.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectSleeper.java diff --git a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectSleeper.java b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectSleeper.java new file mode 100644 index 00000000..02824b66 --- /dev/null +++ b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectSleeper.java @@ -0,0 +1,72 @@ +/* +* Copyright 2024 hbz +* +* Licensed 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.metafacture.strings; + +import org.metafacture.framework.FluxCommand; +import org.metafacture.framework.ObjectReceiver; +import org.metafacture.framework.annotations.Description; +import org.metafacture.framework.annotations.In; +import org.metafacture.framework.annotations.Out; +import org.metafacture.framework.helpers.DefaultObjectPipe; + +/** + * Lets the process between objects sleep for a specific ms. +* +* @author Tobias Bülte +*/ +@Description("Lets the process between objects sleep for a specific ms.") +@In(Object.class) +@Out(Object.class) +@FluxCommand("object-sleep") +public final class ObjectSleeper extends DefaultObjectPipe> { + + public static final long DEFAULT_SLEEP_TIME = 1000; + + private long sleepTime = DEFAULT_SLEEP_TIME; + + /** + * Creates an instance of {@link ObjectSleeper}. + */ + public ObjectSleeper() { + } + + + /** + * Sets the time in ms for the sleep phase. + * + * @param sleepTime the time to sleep + */ + public void setSleepTime(final int sleepTime) { + this.sleepTime = sleepTime; + } + + /** + * Gets the time in ms for the sleep phase. + * + * @return the time to sleep + */ + public long getSleepTime() { + return sleepTime; + } + + @Override + public void process(final T obj) { + Thread.sleep(sleepTime); + getReceiver().process(obj); + } + +} From 489a74d1c450c53d1232331541d8e5d6478c3fcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20B=C3=BClte?= Date: Thu, 17 Oct 2024 12:15:25 +0200 Subject: [PATCH 2/2] Adjust ObjectSleeper.java #495 --- .../flowcontrol/ObjectSleeper.java | 28 ++++++++++++------- .../main/resources/flux-commands.properties | 1 + 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectSleeper.java b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectSleeper.java index 02824b66..4526684c 100644 --- a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectSleeper.java +++ b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectSleeper.java @@ -14,25 +14,28 @@ * limitations under the License. */ -package org.metafacture.strings; +package org.metafacture.flowcontrol; import org.metafacture.framework.FluxCommand; +import org.metafacture.framework.MetafactureException; import org.metafacture.framework.ObjectReceiver; import org.metafacture.framework.annotations.Description; import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; + /** * Lets the process between objects sleep for a specific ms. -* -* @author Tobias Bülte -*/ + * + * @param object type + * @author Tobias Bülte + */ @Description("Lets the process between objects sleep for a specific ms.") @In(Object.class) @Out(Object.class) -@FluxCommand("object-sleep") -public final class ObjectSleeper extends DefaultObjectPipe> { +@FluxCommand("sleep") +public final class ObjectSleeper extends DefaultObjectPipe> { public static final long DEFAULT_SLEEP_TIME = 1000; @@ -44,8 +47,7 @@ public final class ObjectSleeper extends DefaultObjectPipe> public ObjectSleeper() { } - - /** + /** * Sets the time in ms for the sleep phase. * * @param sleepTime the time to sleep @@ -54,7 +56,7 @@ public void setSleepTime(final int sleepTime) { this.sleepTime = sleepTime; } - /** + /** * Gets the time in ms for the sleep phase. * * @return the time to sleep @@ -65,7 +67,13 @@ public long getSleepTime() { @Override public void process(final T obj) { - Thread.sleep(sleepTime); + try { + Thread.sleep(sleepTime); + } + catch (final InterruptedException e) { + Thread.currentThread().interrupt(); + throw new MetafactureException(e.getMessage(), e); + } getReceiver().process(obj); } diff --git a/metafacture-flowcontrol/src/main/resources/flux-commands.properties b/metafacture-flowcontrol/src/main/resources/flux-commands.properties index beefcf19..ec36f079 100644 --- a/metafacture-flowcontrol/src/main/resources/flux-commands.properties +++ b/metafacture-flowcontrol/src/main/resources/flux-commands.properties @@ -21,3 +21,4 @@ reset-object-batch org.metafacture.flowcontrol.ObjectBatchResetter defer-stream org.metafacture.flowcontrol.StreamDeferrer catch-stream-exception org.metafacture.flowcontrol.StreamExceptionCatcher thread-object-tee org.metafacture.flowcontrol.ObjectThreader +sleep org.metafacture.flowcontrol.ObjectSleeper