Skip to content

Commit

Permalink
added reload api
Browse files Browse the repository at this point in the history
  • Loading branch information
eric2788 committed Jan 5, 2025
1 parent dca141e commit fbe40d2
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 10 deletions.
2 changes: 1 addition & 1 deletion groovier-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>groovier</artifactId>
<groupId>org.groovier</groupId>
<version>0.0.54-SNAPSHOT</version>
<version>0.0.55-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.ericlam.mc.groovier;

import java.util.concurrent.CompletableFuture;

/**
* script manager
*/
public interface ScriptManager {

/**
* reload all scripts
* @return future
*/
CompletableFuture<Void> reloadAllScripts();

/**
* reload a specific script loader
* @param loader script loader class
* @return future
*/
CompletableFuture<Void> reloadScript(Class<? extends ScriptLoader> loader);


}
2 changes: 1 addition & 1 deletion groovier-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>groovier</artifactId>
<groupId>org.groovier</groupId>
<version>0.0.54-SNAPSHOT</version>
<version>0.0.55-SNAPSHOT</version>
</parent>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public GroovierCore() {
this.addScriptLoader(EventScriptsManager.class);
this.addScriptLoader(ArgumentScriptManager.class);
this.addScriptLoader(LifeCycleScriptsManager.class);
this.bindType(ScriptManager.class, GroovierScriptLoader.class);
this.bindProvider(ArgumentParser.class, ArgumentParserProvider.class);
this.bindProvider(ServiceInjector.class, ServiceInjectorProvider.class);
this.bindProvider(GroovierLifeCycle.class, GroovierLifeCycleProvider.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package com.ericlam.mc.groovier
import com.ericlam.mc.groovier.scriptloaders.GroovierLifeCycle

import javax.inject.Inject
import javax.inject.Singleton
import java.util.concurrent.CompletableFuture
import java.util.concurrent.atomic.AtomicBoolean

class GroovierScriptLoader {
@Singleton
class GroovierScriptLoader implements ScriptManager {

private final AtomicBoolean reloading = new AtomicBoolean(false)
private final List<ScriptLoader> loaders
Expand All @@ -29,7 +31,7 @@ class GroovierScriptLoader {
classLoader.addClasspath(plugin.pluginFolder.path)
}

CompletableFuture<Void> loadAllScripts() {
CompletableFuture<Void> loadAllScripts(List<ScriptLoader> loaders = this.loaders) {
CompletableFuture<Void> future = new CompletableFuture<>()
plugin.runAsyncTask {
try {
Expand Down Expand Up @@ -62,7 +64,7 @@ class GroovierScriptLoader {
return future
}

void unloadAllScripts() {
void unloadAllScripts(List<ScriptLoader> loaders = this.loaders) {
lifeCycle.onScriptUnload()
loaders.each { loader ->
plugin.logger.info("Unloading ${loader.class.simpleName}")
Expand All @@ -72,12 +74,17 @@ class GroovierScriptLoader {
classLoader.clearCache()
}

CompletableFuture<Void> reloadAllScripts() {
CompletableFuture<Void> reloadAllScripts(List<ScriptLoader> loaders = this.loaders) {
if (!reloading.compareAndSet(false, true)) {
return CompletableFuture.failedFuture(new ScriptLoadingException())
}
this.unloadAllScripts()
return this.loadAllScripts().thenRun { reloading.set(false) }
this.unloadAllScripts(loaders)
return this.loadAllScripts(loaders).thenRun { reloading.set(false) }
}

@Override
CompletableFuture<Void> reloadScript(Class<? extends ScriptLoader> loader) {
return this.reloadAllScripts(this.loaders.findAll { loader.isAssignableFrom(it.class) })
}

}
2 changes: 1 addition & 1 deletion groovier-scripts/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>groovier</artifactId>
<groupId>org.groovier</groupId>
<version>0.0.54-SNAPSHOT</version>
<version>0.0.55-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.groovier</groupId>
<artifactId>groovier</artifactId>
<version>0.0.54-SNAPSHOT</version>
<version>0.0.55-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Groovier</name>
Expand Down

0 comments on commit fbe40d2

Please sign in to comment.