Skip to content

Commit

Permalink
Seperate loading plugin providers when base service can't find them i…
Browse files Browse the repository at this point in the history
…nto subclass
  • Loading branch information
gschueler committed Apr 15, 2011
1 parent e5b2d50 commit 7cad2fd
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,19 @@ public void registerInstance(String name, T object) {

protected T providerOfType(final String providerName) throws ExecutionServiceException {
if (null == providerName) {
throw new MissingProviderException("provider name was null", getName(), providerName);
throw new IllegalArgumentException("provider name was null for Service: " + getName());
}
if (null == instanceregistry.get(providerName)) {
if (null != registry.get(providerName)) {
T instance = createProviderInstanceOfType(providerName);
instanceregistry.put(providerName, instance);
return instance;
}else {
throw new MissingProviderException("provider not found: " + providerName, getName(), providerName);
}
T instance = createProviderInstanceOfType(providerName);
instanceregistry.put(providerName, instance);
return instance;
}
return instanceregistry.get(providerName);
}

private T createProviderInstanceOfType(final String providerName) throws ExecutionServiceException {
if (null == registry.get(providerName)) {
throw new MissingProviderException("No provider with the specified name is registered.", getName(),
throw new MissingProviderException("Not found", getName(),
providerName);
}
final Class<? extends T> execClass = registry.get(providerName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @author Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
*/
public abstract class NodeSpecifiedService<T> extends BaseProviderRegistryService<T> implements PluggableService<T> {
public abstract class NodeSpecifiedService<T> extends PluggableProviderRegistryService<T> implements PluggableService<T> {
protected NodeSpecifiedService(final Framework framework) {
super(framework);
}
Expand All @@ -52,17 +52,6 @@ public T getProviderForNodeAndProject(final INodeEntry node, final String projec
return providerOfType(copiername);
}

@Override
protected T providerOfType(final String providerName) throws ExecutionServiceException {
T t = super.providerOfType(providerName);
if (null != t) {
return t;
} else {
t = framework.getPluginManager().loadProvider(this, providerName);
}
return t;
}

/**
* Return name of Node attribute that specifies the service provider name for this service.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 2011 DTO Solutions, Inc. (http://dtosolutions.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* PluggableProviderRegistryService.java
*
* User: Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
* Created: 4/14/11 3:53 PM
*
*/
package com.dtolabs.rundeck.core.execution.service;

import com.dtolabs.rundeck.core.common.Framework;
import com.dtolabs.rundeck.core.plugins.PluggableService;
import com.dtolabs.rundeck.core.plugins.ServiceProviderLoader;

/**
* Overrides the {@link #providerOfType(String)} method to attempt to load a provider from the PluginManagerService.
*
* @author Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
*/
public abstract class PluggableProviderRegistryService<T> extends BaseProviderRegistryService<T> implements
PluggableService<T> {
protected PluggableProviderRegistryService(final Framework framework) {
super(framework);
}


@Override
protected T providerOfType(final String providerName) throws ExecutionServiceException {
T t = null;
MissingProviderException caught = null;
try {
t = super.providerOfType(providerName);
} catch (MissingProviderException e) {
//ignore and attempt to load from the plugin manager
caught = e;
}
if (null != t) {
return t;
}
final ServiceProviderLoader pluginManager = framework.getPluginManager();
if (null != pluginManager) {
return pluginManager.loadProvider(this, providerName);
} else if (null != caught) {
throw caught;
}else {
throw new MissingProviderException("Provider not found", getName(), providerName);
}
}
}

0 comments on commit 7cad2fd

Please sign in to comment.