From ced4405df469aa62b4495f1a258986d4842072cf Mon Sep 17 00:00:00 2001 From: Emanuel Rabina Date: Fri, 2 Feb 2024 22:50:57 +1300 Subject: [PATCH] Remove redhorizon-async subproject --- redhorizon-async/build.gradle | 17 --- .../redhorizon/async/ControlledLoop.groovy | 83 -------------- .../redhorizon/async/RateLimitedLoop.groovy | 106 ------------------ .../redhorizon/async/RunnableWorker.groovy | 40 ------- redhorizon-classic/build.gradle | 3 - redhorizon-engine/build.gradle | 9 +- redhorizon-filetypes/build.gradle | 9 +- settings.gradle | 1 - 8 files changed, 8 insertions(+), 260 deletions(-) delete mode 100644 redhorizon-async/build.gradle delete mode 100644 redhorizon-async/source/nz/net/ultraq/redhorizon/async/ControlledLoop.groovy delete mode 100644 redhorizon-async/source/nz/net/ultraq/redhorizon/async/RateLimitedLoop.groovy delete mode 100644 redhorizon-async/source/nz/net/ultraq/redhorizon/async/RunnableWorker.groovy diff --git a/redhorizon-async/build.gradle b/redhorizon-async/build.gradle deleted file mode 100644 index 652762c9..00000000 --- a/redhorizon-async/build.gradle +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2022, Emanuel Rabina (http://www.ultraq.net.nz/) - * - * 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. - */ - -description = 'Utilities to aid with multi-threaded programming' diff --git a/redhorizon-async/source/nz/net/ultraq/redhorizon/async/ControlledLoop.groovy b/redhorizon-async/source/nz/net/ultraq/redhorizon/async/ControlledLoop.groovy deleted file mode 100644 index 3df475b9..00000000 --- a/redhorizon-async/source/nz/net/ultraq/redhorizon/async/ControlledLoop.groovy +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2022, Emanuel Rabina (http://www.ultraq.net.nz/) - * - * 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 nz.net.ultraq.redhorizon.async - -import org.slf4j.Logger -import org.slf4j.LoggerFactory - -import java.util.concurrent.FutureTask -import java.util.concurrent.RunnableFuture - -/** - * A special {@link RunnableFuture} that has a loop of repeating work that can - * be queried and controlled from other objects. Useful as a {@code @Delegate} - * property in a class that needs to fulfil a {@code RunnableFuture} - * class contract. - * - * @author Emanuel Rabina - */ -class ControlledLoop implements RunnableWorker { - - private static final Logger logger = LoggerFactory.getLogger(ControlledLoop) - - @Delegate - private final FutureTask loopTask - - /** - * Constructor, build a {@link FutureTask} with a loop solely controlled by - * the task state. - * - * @param loop - */ - ControlledLoop(Closure loop) { - - this({ true }, loop) - } - - /** - * Constructor, build a {@link FutureTask} with a loop based around the given - * parameters. - * - * @param loopCondition - * @param loop - */ - ControlledLoop(Closure loopCondition, Closure loop) { - - loopTask = new FutureTask<>({ -> - try { - while (!cancelled && loopCondition()) { - loop() - } - } - catch (Throwable ex) { - logger.error("An error occurred in controlled loop \"${Thread.currentThread().name}\". Exiting...", ex) - } - }, null) - } - - @Override - boolean isStopped() { - - return isDone() - } - - @Override - void stop() { - - cancel() - } -} diff --git a/redhorizon-async/source/nz/net/ultraq/redhorizon/async/RateLimitedLoop.groovy b/redhorizon-async/source/nz/net/ultraq/redhorizon/async/RateLimitedLoop.groovy deleted file mode 100644 index 59403549..00000000 --- a/redhorizon-async/source/nz/net/ultraq/redhorizon/async/RateLimitedLoop.groovy +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2022, Emanuel Rabina (http://www.ultraq.net.nz/) - * - * 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 nz.net.ultraq.redhorizon.async - -import org.slf4j.Logger -import org.slf4j.LoggerFactory - -import groovy.transform.CompileStatic -import java.util.concurrent.FutureTask - -/** - * Similar to {@link ControlledLoop}, with the addition of the Thread being put - * into wait states at the end of each loop execution to not exceed a specified - * frequency. - * - * @author Emanuel Rabina - */ -@CompileStatic -class RateLimitedLoop implements RunnableWorker { - - private final Logger logger = LoggerFactory.getLogger(RateLimitedLoop) - - @Delegate - private final FutureTask loopTask - - /** - * Constructor, build a {@link FutureTask} with a rate-limited loop solely - * controlled by the task state. - - * @param frequency - * @param loop - */ - RateLimitedLoop(float frequency, Closure loop) { - - this(frequency, { true }, loop) - } - - /** - * Constructor, build a {@link FutureTask} with a rate-limited loop based - * around the given parameters. - * - * @param frequency - * @param loopCondition - * @param loop - */ - RateLimitedLoop(float frequency, Closure loopCondition, Closure loop) { - - double maxRunTimeNanos = 1000000000 / frequency - - loopTask = new FutureTask<>({ -> - try { - def lastTimeNanos = System.nanoTime() - while (!cancelled && loopCondition()) { - loop() - - // Add a wait if loop() was too quick - long executionTimeNanos = System.nanoTime() - lastTimeNanos - if (executionTimeNanos < maxRunTimeNanos) { - double diffTimeNanos = maxRunTimeNanos - executionTimeNanos - // If the amount to wait is rather large, sleep for most of that time - // (all but the remaining 5ms of the time because sleep is a minimum, - // it can take a bit to calculate all of this, and to 'wake up') - if (diffTimeNanos > 5000000) { - Thread.sleep((long) (diffTimeNanos / 1000000 - 5)) - } - // Go into a spin-lock for the remaining time - while (System.nanoTime() - lastTimeNanos < maxRunTimeNanos) { - Thread.onSpinWait() - } - } - - lastTimeNanos = System.nanoTime() - } - } - catch (Throwable ex) { - logger.error("An error occurred in rate-limited loop \"${Thread.currentThread().name}\". Exiting...", ex) - } - }, null) - } - - @Override - boolean isStopped() { - - return isDone() - } - - @Override - void stop() { - - cancel() - } -} diff --git a/redhorizon-async/source/nz/net/ultraq/redhorizon/async/RunnableWorker.groovy b/redhorizon-async/source/nz/net/ultraq/redhorizon/async/RunnableWorker.groovy deleted file mode 100644 index f7607786..00000000 --- a/redhorizon-async/source/nz/net/ultraq/redhorizon/async/RunnableWorker.groovy +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2022, Emanuel Rabina (http://www.ultraq.net.nz/) - * - * 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 nz.net.ultraq.redhorizon.async - -import java.util.concurrent.RunnableFuture - -/** - * A {@link Runnable} with methods more geared towards threads that perform - * repeated/looped tasks. - * - * @author Emanuel Rabina - */ -interface RunnableWorker extends RunnableFuture { - - /** - * Return whether or not this worker has been stopped. - * - * @return - */ - boolean isStopped() - - /** - * Signal to the worker to stop. - */ - void stop() -} diff --git a/redhorizon-classic/build.gradle b/redhorizon-classic/build.gradle index b7947837..418661f8 100644 --- a/redhorizon-classic/build.gradle +++ b/redhorizon-classic/build.gradle @@ -24,7 +24,6 @@ description = 'Code that bridges the classic C&C file formats for use with the R year = '2007' dependencies { - implementation project(':redhorizon-async') implementation project(':redhorizon-engine') implementation project(':redhorizon-events') implementation project(':redhorizon-filetypes') @@ -35,7 +34,6 @@ dependencies { shadowJar { archiveClassifier.set('') dependencies { - include(project(':redhorizon-async')) include(project(':redhorizon-engine')) include(project(':redhorizon-events')) include(project(':redhorizon-filetypes')) @@ -49,7 +47,6 @@ groovydoc { here, and serve as working examples for other programmers. ''') // Can't link to these until they get published on maven central themselves -// link("https://javadoc.io/doc/nz.net.ultraq.redhorizon/redhorizon-async/${version}/", 'nz.net.ultraq.redhorizon.async.') // link("https://javadoc.io/doc/nz.net.ultraq.redhorizon/redhorizon-events/${version}/", 'nz.net.ultraq.redhorizon.events.') // link("https://javadoc.io/doc/nz.net.ultraq.redhorizon/redhorizon-filetypes/${version}/", 'nz.net.ultraq.redhorizon.filetypes.') } diff --git a/redhorizon-engine/build.gradle b/redhorizon-engine/build.gradle index cf7ed5ca..e8a7820e 100644 --- a/redhorizon-engine/build.gradle +++ b/redhorizon-engine/build.gradle @@ -1,12 +1,12 @@ -/* +/* * Copyright 2016, Emanuel Rabina (http://www.ultraq.net.nz/) - * + * * 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. @@ -17,7 +17,6 @@ description = 'Core rendering engine for Red Horizon' dependencies { - api project(':redhorizon-async') implementation project(':redhorizon-events') implementation project(':redhorizon-filetypes') implementation platform("org.lwjgl:lwjgl-bom:${lwjglVersion}") diff --git a/redhorizon-filetypes/build.gradle b/redhorizon-filetypes/build.gradle index 51e96031..618b13ac 100644 --- a/redhorizon-filetypes/build.gradle +++ b/redhorizon-filetypes/build.gradle @@ -1,12 +1,12 @@ -/* +/* * Copyright 2015, Emanuel Rabina (http://www.ultraq.net.nz/) - * + * * 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. @@ -18,6 +18,5 @@ description = 'Filetypes module for the Red Horizon project' dependencies { api 'org.reflections:reflections:0.10.2' - implementation project(':redhorizon-async') implementation project(':redhorizon-events') } diff --git a/settings.gradle b/settings.gradle index 2f7564ad..03811350 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,7 +17,6 @@ rootProject.name = 'redhorizon' include( - 'redhorizon-async', 'redhorizon-classic', 'redhorizon-cli', 'redhorizon-engine',