Skip to content

Commit a9b3982

Browse files
committed
Add draft for object sleeper #495
1 parent edb3a8d commit a9b3982

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2024 hbz
3+
*
4+
* Licensed under the Apache License, Version 2.0 the "License";
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.metafacture.strings;
18+
19+
import org.metafacture.framework.FluxCommand;
20+
import org.metafacture.framework.ObjectReceiver;
21+
import org.metafacture.framework.annotations.Description;
22+
import org.metafacture.framework.annotations.In;
23+
import org.metafacture.framework.annotations.Out;
24+
import org.metafacture.framework.helpers.DefaultObjectPipe;
25+
26+
/**
27+
* Lets the process between objects sleep for a specific ms.
28+
*
29+
* @author Tobias Bülte
30+
*/
31+
@Description("Lets the process between objects sleep for a specific ms.")
32+
@In(Object.class)
33+
@Out(Object.class)
34+
@FluxCommand("object-sleep")
35+
public final class ObjectSleeper extends DefaultObjectPipe<T, ObjectReceiver<T>> {
36+
37+
public static final long DEFAULT_SLEEP_TIME = 1000;
38+
39+
private long sleepTime = DEFAULT_SLEEP_TIME;
40+
41+
/**
42+
* Creates an instance of {@link ObjectSleeper}.
43+
*/
44+
public ObjectSleeper() {
45+
}
46+
47+
48+
/**
49+
* Sets the time in ms for the sleep phase.
50+
*
51+
* @param sleepTime the time to sleep
52+
*/
53+
public void setSleepTime(final int sleepTime) {
54+
this.sleepTime = sleepTime;
55+
}
56+
57+
/**
58+
* Gets the time in ms for the sleep phase.
59+
*
60+
* @return the time to sleep
61+
*/
62+
public long getSleepTime() {
63+
return sleepTime;
64+
}
65+
66+
@Override
67+
public void process(final T obj) {
68+
Thread.sleep(sleepTime);
69+
getReceiver().process(obj);
70+
}
71+
72+
}

0 commit comments

Comments
 (0)