|
17 | 17 |
|
18 | 18 | package com.intergral.deep.agent.settings;
|
19 | 19 |
|
| 20 | +import com.intergral.deep.agent.api.IRegistration; |
20 | 21 | import com.intergral.deep.agent.api.logger.ITracepointLogger;
|
21 | 22 | import com.intergral.deep.agent.api.logger.TracepointLogger;
|
22 | 23 | import com.intergral.deep.agent.api.resource.Resource;
|
@@ -51,7 +52,7 @@ public class Settings implements ISettings {
|
51 | 52 | private static final AtomicBoolean IS_ACTIVE = new AtomicBoolean(true);
|
52 | 53 | private final Properties properties;
|
53 | 54 | private Resource resource;
|
54 |
| - private Collection<IDeepPlugin> plugins = Collections.emptyList(); |
| 55 | + private final Collection<IDeepPlugin> plugins = new ArrayList<>(); |
55 | 56 | private ITracepointLogger tracepointLogger = new TracepointLogger();
|
56 | 57 |
|
57 | 58 | private Settings(Properties properties) {
|
@@ -321,7 +322,7 @@ public List<String> getAsList(final String key) {
|
321 | 322 | * @return the discovered plugin with the given name, or {@code null} if a plugin with the provided name and type cannot be found.
|
322 | 323 | */
|
323 | 324 | public <T> T getPluginByName(final Class<T> clazz, final String name) {
|
324 |
| - final Collection<T> plugins = getPlugins(clazz, t -> t.getClass().getName().endsWith(name)); |
| 325 | + final Collection<T> plugins = getPlugins(clazz, t -> t.getClass().getName().equals(name)); |
325 | 326 | if (plugins.isEmpty()) {
|
326 | 327 | return null;
|
327 | 328 | }
|
@@ -364,7 +365,8 @@ private <T> Collection<T> getPlugins(final Class<T> target, final Predicate<T> p
|
364 | 365 | * @param plugins the plugins to use
|
365 | 366 | */
|
366 | 367 | public void setPlugins(Collection<IDeepPlugin> plugins) {
|
367 |
| - this.plugins = plugins; |
| 368 | + this.plugins.clear(); |
| 369 | + this.plugins.addAll(plugins); |
368 | 370 | }
|
369 | 371 |
|
370 | 372 | /**
|
@@ -419,6 +421,30 @@ public void setTracepointLogger(final ITracepointLogger tracepointLogger) {
|
419 | 421 | this.tracepointLogger = tracepointLogger;
|
420 | 422 | }
|
421 | 423 |
|
| 424 | + /** |
| 425 | + * Add a plugin to the current config. |
| 426 | + * |
| 427 | + * @param plugin the new plugin |
| 428 | + * @return the plugin registration |
| 429 | + */ |
| 430 | + public IRegistration<IDeepPlugin> addPlugin(final IDeepPlugin plugin) { |
| 431 | + this.plugins.add(plugin); |
| 432 | + return new IRegistration<IDeepPlugin>() { |
| 433 | + @Override |
| 434 | + public void unregister() { |
| 435 | + final boolean removeIf = Settings.this.plugins.removeIf(existing -> existing == plugin); |
| 436 | + if (!removeIf) { |
| 437 | + throw new IllegalStateException(String.format("cannot remove plugin: %s", plugin)); |
| 438 | + } |
| 439 | + } |
| 440 | + |
| 441 | + @Override |
| 442 | + public IDeepPlugin get() { |
| 443 | + return plugin; |
| 444 | + } |
| 445 | + }; |
| 446 | + } |
| 447 | + |
422 | 448 | /**
|
423 | 449 | * Used to indicate an invalid config value.
|
424 | 450 | */
|
|
0 commit comments