Singleton Management
This commit is contained in:
parent
35bbfde328
commit
0e26e2c75d
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.validation.metadata.ConstraintDescriptor;
|
|
||||||
|
|
||||||
import org.gcube.spatial.data.sdi.engine.RoleManager;
|
import org.gcube.spatial.data.sdi.engine.RoleManager;
|
||||||
import org.gcube.spatial.data.sdi.model.credentials.AccessType;
|
import org.gcube.spatial.data.sdi.model.credentials.AccessType;
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package org.gcube.spatial.data.sdi.engine.impl.factories;
|
package org.gcube.spatial.data.sdi.engine.impl.factories;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.gcube.spatial.data.sdi.engine.GISManager;
|
import org.gcube.spatial.data.sdi.engine.GISManager;
|
||||||
import org.gcube.spatial.data.sdi.engine.impl.GISManagerImpl;
|
import org.gcube.spatial.data.sdi.engine.impl.GISManagerImpl;
|
||||||
import org.glassfish.hk2.api.Factory;
|
import org.glassfish.hk2.api.Factory;
|
||||||
|
|
||||||
|
import lombok.Synchronized;
|
||||||
|
|
||||||
public class GeoServerManagerFactory implements Factory<GISManager>{
|
public class GeoServerManagerFactory implements Factory<GISManager>{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,14 +16,14 @@ public class GeoServerManagerFactory implements Factory<GISManager>{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GISManager provide() {
|
public GISManager provide() {
|
||||||
return new GISManagerImpl();
|
return getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private GISManager instance=null;
|
private static GISManager instance=null;
|
||||||
|
|
||||||
@Singleton
|
@Synchronized
|
||||||
private GISManager getInstance() {
|
private static GISManager getInstance() {
|
||||||
if(instance==null)
|
if(instance==null)
|
||||||
instance=new GISManagerImpl();
|
instance=new GISManagerImpl();
|
||||||
return instance;
|
return instance;
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class RoleManagerFactory implements Factory<RoleManager>{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private RoleManager instance;
|
private static RoleManager instance;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RoleManager provide() {
|
public RoleManager provide() {
|
||||||
|
@ -21,7 +21,7 @@ public class RoleManagerFactory implements Factory<RoleManager>{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private RoleManager getInstance() {
|
private static RoleManager getInstance() {
|
||||||
if(instance==null)
|
if(instance==null)
|
||||||
instance=new RoleManagerImpl();
|
instance=new RoleManagerImpl();
|
||||||
return instance;
|
return instance;
|
||||||
|
|
|
@ -20,11 +20,11 @@ public class SDIManagerFactory implements Factory<SDIManager>{
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public SDIManager provide() {
|
public SDIManager provide() {
|
||||||
return getInstance();
|
return getInstance(gnManager,gisManager,thManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private SDIManager sdiManager=null;
|
private static SDIManager sdiManager=null;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private GeoNetworkManager gnManager;
|
private GeoNetworkManager gnManager;
|
||||||
|
@ -36,7 +36,7 @@ public class SDIManagerFactory implements Factory<SDIManager>{
|
||||||
|
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private SDIManager getInstance() {
|
private static SDIManager getInstance(GeoNetworkManager gnManager, GISManager gisManager,ThreddsManager thManager) {
|
||||||
if(sdiManager==null)
|
if(sdiManager==null)
|
||||||
sdiManager=new SDIManagerImpl(gnManager,thManager,gisManager);
|
sdiManager=new SDIManagerImpl(gnManager,thManager,gisManager);
|
||||||
return sdiManager;
|
return sdiManager;
|
||||||
|
|
|
@ -4,6 +4,8 @@ import org.gcube.spatial.data.sdi.engine.TemporaryPersistence;
|
||||||
import org.gcube.spatial.data.sdi.engine.impl.TemporaryPersistenceImpl;
|
import org.gcube.spatial.data.sdi.engine.impl.TemporaryPersistenceImpl;
|
||||||
import org.glassfish.hk2.api.Factory;
|
import org.glassfish.hk2.api.Factory;
|
||||||
|
|
||||||
|
import lombok.Synchronized;
|
||||||
|
|
||||||
public class TemporaryPersistenceFactory implements Factory<TemporaryPersistence>{
|
public class TemporaryPersistenceFactory implements Factory<TemporaryPersistence>{
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,11 +16,22 @@ public class TemporaryPersistenceFactory implements Factory<TemporaryPersistence
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TemporaryPersistence provide() {
|
public TemporaryPersistence provide() {
|
||||||
TemporaryPersistenceImpl temp=new TemporaryPersistenceImpl();
|
return getInstance();
|
||||||
|
|
||||||
temp.init();
|
|
||||||
|
|
||||||
return temp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static TemporaryPersistence temp=null;
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
private static TemporaryPersistence getInstance(){
|
||||||
|
if(temp==null) {
|
||||||
|
temp=new TemporaryPersistenceImpl();
|
||||||
|
try {
|
||||||
|
temp.init();
|
||||||
|
}catch(Exception e) {
|
||||||
|
throw new RuntimeException("Unable to init temp ",e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ import org.gcube.spatial.data.sdi.engine.ThreddsManager;
|
||||||
import org.gcube.spatial.data.sdi.engine.impl.ThreddsManagerImpl;
|
import org.gcube.spatial.data.sdi.engine.impl.ThreddsManagerImpl;
|
||||||
import org.glassfish.hk2.api.Factory;
|
import org.glassfish.hk2.api.Factory;
|
||||||
|
|
||||||
|
import lombok.Synchronized;
|
||||||
|
|
||||||
public class ThreddsManagerFactory implements Factory<ThreddsManager>{
|
public class ThreddsManagerFactory implements Factory<ThreddsManager>{
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -15,7 +17,7 @@ public class ThreddsManagerFactory implements Factory<ThreddsManager>{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ThreddsManager provide() {
|
public ThreddsManager provide() {
|
||||||
return new ThreddsManagerImpl(manager);
|
return getInstance(manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -23,4 +25,13 @@ public class ThreddsManagerFactory implements Factory<ThreddsManager>{
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ThreddsManager instance=null;
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
private static ThreddsManager getInstance(TemplateManager manager) {
|
||||||
|
if(instance==null)
|
||||||
|
instance=new ThreddsManagerImpl(manager);
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue