Skip to content

Commit

Permalink
Revert: refresh the plugin wrapper when starting the plugin (#5238)
Browse files Browse the repository at this point in the history
#### What type of PR is this?

/kind improvement
/area core
/milestone 2.12.x

#### What this PR does / why we need it:

This PR reverts changes in PR <#4023>, mainly thanks to PR <#5148>.

We don't need to refresh the plugin wrapper on every startup, because we entirely disable the plugin in plugin manager when disabling plugin at console.

#### Which issue(s) this PR fixes:

Fixes #4016

#### Does this PR introduce a user-facing change?

```release-note
None
```
  • Loading branch information
JohnNiang authored Jan 24, 2024
1 parent 28ee0bf commit 7e8df33
Showing 1 changed file with 1 addition and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,7 @@ public void stopPlugins() {
private PluginState doStartPlugin(String pluginId) {
checkPluginId(pluginId);

// refresh plugin to ensure cache object of PluginWrapper.plugin is up-to-date
// see gh-4016 to know why we need this
// TODO if has a better way to do this?
PluginWrapper pluginWrapper = refreshPluginWrapper(pluginId);
PluginWrapper pluginWrapper = getPlugin(pluginId);

checkExtensionFinderReady(pluginWrapper);

Expand Down Expand Up @@ -352,37 +349,6 @@ private void removePluginComponentsCache(String pluginId) {
}
}

/**
* <p>Refresh plugin wrapper by plugin name.</p>
*
* <p>It will be create a new plugin wrapper and replace old plugin wrapper to clean
* {@link PluginWrapper#getPlugin()} cache object.</p>
*
* @param pluginName plugin name
* @return refreshed plugin wrapper instance, plugin cache object will be null
* @throws IllegalArgumentException if plugin not found
*/
protected synchronized PluginWrapper refreshPluginWrapper(String pluginName) {
checkPluginId(pluginName);
// get old plugin wrapper
PluginWrapper pluginWrapper = getPlugin(pluginName);
// create new plugin wrapper to replace old plugin wrapper
PluginWrapper refreshed = copyPluginWrapper(pluginWrapper);
this.plugins.put(pluginName, refreshed);
return refreshed;
}

@NonNull
PluginWrapper copyPluginWrapper(@NonNull PluginWrapper pluginWrapper) {
PluginWrapper refreshed =
createPluginWrapper(pluginWrapper.getDescriptor(), pluginWrapper.getPluginPath(),
pluginWrapper.getPluginClassLoader());
refreshed.setPluginFactory(getPluginFactory());
refreshed.setPluginState(pluginWrapper.getPluginState());
refreshed.setFailedException(pluginWrapper.getFailedException());
return refreshed;
}

@Override
public void destroy() throws Exception {
stopPlugins();
Expand Down

0 comments on commit 7e8df33

Please sign in to comment.