Package com.scivicslab.pojoactor.core
Class DynamicActorLoader
java.lang.Object
com.scivicslab.pojoactor.core.DynamicActorLoader
Dynamic actor loader for runtime-extensible actor system.
This class enables loading actors from external JAR files at runtime,
providing OSGi-like plugin functionality using only JDK standard APIs.
Basic Usage
// Load an actor from external JAR
Path pluginJar = Paths.get("plugins/math-plugin.jar");
ActorRef<Object> actor = DynamicActorLoader.loadActor(
pluginJar,
"com.example.plugin.MathPlugin",
"mathActor"
);
// Use the dynamically loaded actor
actor.tell(obj -> {
// Invoke methods via reflection
Method method = obj.getClass().getMethod("add", int.class, int.class);
int result = (int) method.invoke(obj, 2, 3);
System.out.println("Result: " + result);
});
Features
- Load any POJO from external JAR as an actor
- No OSGi or JPMS required - uses standard URLClassLoader
- Supports hot-reload by closing classloader and reloading
- Compatible with GraalVM Native Image (with configuration)
Requirements
- Plugin class must have a public no-argument constructor
- JAR file must be accessible via filesystem
- Since:
- 2.0.0
- Author:
- devteam@scivics-lab.com
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ActorRef<T> Loads a class from an external JAR file and wraps it as an ActorRef.static <T> ActorRef<T> loadActorIntoSystem(ActorSystem system, Path jarPath, String className, String actorName) Loads a class from an external JAR file and wraps it as an ActorRef, registering it with the given ActorSystem.
-
Constructor Details
-
DynamicActorLoader
public DynamicActorLoader()
-
-
Method Details
-
loadActor
public static <T> ActorRef<T> loadActor(Path jarPath, String className, String actorName) throws Exception Loads a class from an external JAR file and wraps it as an ActorRef. The loaded class must have a public no-argument constructor. The resulting actor can receive messages just like any other actor.- Type Parameters:
T- the type of the actor object- Parameters:
jarPath- path to the JAR file containing the classclassName- fully qualified class name to loadactorName- name for the actor- Returns:
- an ActorRef wrapping an instance of the loaded class
- Throws:
Exception- if JAR loading, class loading, or instantiation fails- See Also:
-
loadActorIntoSystem
public static <T> ActorRef<T> loadActorIntoSystem(ActorSystem system, Path jarPath, String className, String actorName) throws Exception Loads a class from an external JAR file and wraps it as an ActorRef, registering it with the given ActorSystem. This is a convenience method that combines loading and registration.- Type Parameters:
T- the type of the actor object- Parameters:
system- the ActorSystem to register the actor withjarPath- path to the JAR file containing the classclassName- fully qualified class name to loadactorName- name for the actor- Returns:
- an ActorRef wrapping an instance of the loaded class
- Throws:
Exception- if JAR loading, class loading, or instantiation fails- See Also:
-