Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions core/src/main/java/org/zstack/core/plugin/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,15 @@ public interface PluginManager {

// get plugin class with type
<T extends PluginDriver> T getPlugin(Class<? extends PluginDriver> pluginClass, String type);

/**
* Create a new independent instance of a plugin driver.
* Unlike getPlugin() which returns a shared singleton, this method creates
* a fresh instance each time to avoid concurrent state corruption when
* multiple callers need isolated driver configurations.
*
* @param pluginUuid the plugin product key / UUID
* @return a new instance of the plugin driver
*/
<T extends PluginDriver> T newDriverInstance(String pluginUuid);
}
15 changes: 15 additions & 0 deletions core/src/main/java/org/zstack/core/plugin/PluginManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,21 @@ public <T extends PluginDriver> T getPlugin(Class<? extends PluginDriver> plugin
.orElse(null);
}

@Override
public <T extends PluginDriver> T newDriverInstance(String pluginProductKey) {
PluginDriver singleton = pluginInstances.get(pluginProductKey);
if (singleton == null) {
throw new CloudRuntimeException(String.format("Unsupported plugin %s", pluginProductKey));
}

try {
return (T) singleton.getClass().getConstructor().newInstance();
} catch (Exception e) {
throw new CloudRuntimeException(
String.format("Failed to create new instance of plugin %s", pluginProductKey), e);
}
}

@Override
public void handleMessage(Message msg) {
if (msg instanceof APIRefreshPluginDriversMsg) {
Expand Down