Fabio Sinibaldi 2017-12-13 14:04:13 +00:00
parent 04e826621e
commit 3194959b9e
11 changed files with 34 additions and 40 deletions

View File

@ -19,8 +19,8 @@ public class DTServiceAppManager implements ApplicationManager {
RequestManager requests;
@Inject
TicketManager tickets;
@Inject
PluginManager plugins;
PluginManager plugins=PluginManager.get();
ApplicationContext ctx = ContextProvider.get();

View File

@ -12,21 +12,24 @@ import javax.ws.rs.core.Response.Status;
import org.gcube.data.transfer.model.ServiceConstants;
import org.gcube.data.transfer.model.TransferCapabilities;
import org.gcube.data.transfer.service.DTServiceAppManager;
import org.gcube.data.transfer.service.transfers.engine.CapabilitiesProvider;
import org.gcube.data.transfer.service.transfers.engine.PluginManager;
import org.gcube.data.transfer.service.transfers.engine.faults.PluginNotFoundException;
import org.gcube.smartgears.annotations.ManagedBy;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Path(ServiceConstants.CAPABILTIES_SERVLET_NAME)
@ManagedBy(DTServiceAppManager.class)
public class Capabilities {
@Inject
CapabilitiesProvider provider;
@Inject
PluginManager plugins;
PluginManager plugins=PluginManager.get();
@GET

View File

@ -8,6 +8,7 @@ import org.gcube.data.transfer.model.PluginInvocation;
import org.gcube.data.transfer.plugin.fails.PluginException;
import org.gcube.data.transfer.plugin.fails.PluginExecutionException;
import org.gcube.data.transfer.service.transfers.engine.faults.PluginNotFoundException;
import org.gcube.data.transfer.service.transfers.engine.impl.PluginManagerImpl;
public interface PluginManager {
@ -18,4 +19,7 @@ public interface PluginManager {
public void initPlugins();
public static PluginManager get() {
return PluginManagerImpl.get();
}
}

View File

@ -32,9 +32,9 @@ public class CapabilitiesProviderImpl implements CapabilitiesProvider {
@Inject
public CapabilitiesProviderImpl(PersistenceProvider persistenceProvider,PluginManager pluginManager) {
public CapabilitiesProviderImpl(PersistenceProvider persistenceProvider) {
this.persistenceProvider = persistenceProvider;
this.pluginManager=pluginManager;
this.pluginManager=PluginManager.get();
}
@Override @Synchronized

View File

@ -22,17 +22,28 @@ import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Singleton
public class PluginManagerImpl implements PluginManager {
private static ServiceLoader<AbstractPluginFactory> abstractFactoryLoader = null;
private static Map<String,PluginDescription> installedPlugins=null;
private static PluginManagerImpl instance=null;
public static synchronized PluginManagerImpl get() {
if(instance==null)
instance=new PluginManagerImpl();
return instance;
}
// INSTANCE
public PluginManagerImpl() {
load();
}
@Override
public Map<String, PluginDescription> getInstalledPlugins() {
return installedPlugins;

View File

@ -31,10 +31,10 @@ public class RequestManagerImpl implements RequestManager{
@Inject
public RequestManagerImpl(TicketManager ticketManager,PersistenceProvider persistenceProvider,PluginManager pluginManager) {
public RequestManagerImpl(TicketManager ticketManager,PersistenceProvider persistenceProvider) {
executor=Executors.newCachedThreadPool();
this.persistenceProvider=persistenceProvider;
this.pluginManager=pluginManager;
this.pluginManager=PluginManager.get();
this.ticketManager=ticketManager;
}

View File

@ -8,7 +8,7 @@ import org.gcube.data.transfer.model.TransferCapabilities;
import org.gcube.data.transfer.model.options.HttpDownloadOptions;
import org.gcube.data.transfer.model.options.TransferOptions;
import org.gcube.data.transfer.service.transfers.engine.CapabilitiesProvider;
import org.gcube.data.transfer.service.transfers.engine.impl.PluginManagerImpl;
import org.gcube.data.transfer.service.transfers.engine.PluginManager;
import org.glassfish.hk2.api.Factory;
public class CapabilitiesProviderFactory implements Factory<CapabilitiesProvider> {
@ -25,7 +25,7 @@ public class CapabilitiesProviderFactory implements Factory<CapabilitiesProvider
public TransferCapabilities get() {
return new TransferCapabilities("12345", "localhost", 80,
Collections.singleton((TransferOptions)HttpDownloadOptions.DEFAULT),
new HashSet<PluginDescription>(new PluginManagerImpl().getInstalledPlugins().values())
new HashSet<PluginDescription>(PluginManager.get().getInstalledPlugins().values())
,Collections.singleton("data-transfer-service"));
}
};

View File

@ -1,23 +0,0 @@
package org.gcube.data.transfer.service;
import org.gcube.data.transfer.service.transfers.engine.PluginManager;
import org.gcube.data.transfer.service.transfers.engine.impl.PluginManagerImpl;
import org.glassfish.hk2.api.Factory;
public class PluginManagerFactory implements Factory<PluginManager> {
static PluginManagerImpl impl=new PluginManagerImpl();
@Override
public void dispose(PluginManager arg0) {
// TODO Auto-generated method stub
}
@Override
public PluginManager provide() {
return impl;
}
}

View File

@ -14,8 +14,7 @@ public class RequestManagerFactory implements Factory<RequestManager> {
@Override
public RequestManager provide() {
return new RequestManagerImpl(new TicketManagerProvider().provide(),
new PersistenceProviderFactory().provide(),
new PluginManagerFactory().provide());
new PersistenceProviderFactory().provide());
}
}

View File

@ -52,7 +52,7 @@ public class TestCall extends JerseyTest {
bindFactory(CapabilitiesProviderFactory.class).to(CapabilitiesProvider.class);
bindFactory(RequestManagerFactory.class).to(RequestManager.class);
bindFactory(PersistenceProviderFactory.class).to(PersistenceProvider.class);
bindFactory(PluginManagerFactory.class).to(PluginManager.class);
// bindFactory(PluginManagerFactory.class).to(PluginManager.class);
}
}

View File

@ -3,7 +3,7 @@ package org.gcube.data.transfer.service;
import java.util.Map;
import org.gcube.data.transfer.model.PluginDescription;
import org.gcube.data.transfer.service.transfers.engine.impl.PluginManagerImpl;
import org.gcube.data.transfer.service.transfers.engine.PluginManager;
import org.junit.Assert;
import org.junit.Test;
@ -11,7 +11,7 @@ public class TestPlugins {
@Test
public void testPlugins(){
Map<String,PluginDescription> plugins=new PluginManagerImpl().getInstalledPlugins();
Map<String,PluginDescription> plugins=PluginManager.get().getInstalledPlugins();
Assert.assertNotNull(plugins);
System.out.println(plugins);
}