git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerCore@131591 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
1c9c4041c7
commit
15d687462e
4
pom.xml
4
pom.xml
|
@ -74,8 +74,8 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.resources</groupId>
|
||||
<artifactId>registry-publisher</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
<!-- <version>[1.2.4-SNAPSHOT, 2.0.0-SNAPSHOT)</version> -->
|
||||
<!-- <version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version> -->
|
||||
<version>[1.2.4-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<!-- changed from version 1.1.0-SNAPSHOT. If this change introduces problems, please revert -->
|
||||
</dependency>
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -5,8 +5,6 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -17,81 +15,75 @@ public class SessionManager {
|
|||
/** The logger. */
|
||||
private static final Logger logger = LoggerFactory.getLogger(SessionManager.class);
|
||||
|
||||
// protected static Thread thread = new CleanSessionThread();
|
||||
protected static Thread thread = new CleanSessionThread();
|
||||
protected static SessionManager sessionManager = new SessionManager();
|
||||
protected HashMap<String, ASLSession> sessions;
|
||||
|
||||
protected SessionManager() {
|
||||
sessions = new HashMap<String, ASLSession>();
|
||||
// thread.setDaemon(true);
|
||||
// thread.start();
|
||||
thread.setDaemon(true);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public static SessionManager getInstance() {
|
||||
return sessionManager;
|
||||
}
|
||||
|
||||
|
||||
public void setASLSession(HttpSession userSession, String username){
|
||||
ASLSession aslSession = new ASLSession(userSession, username);
|
||||
sessions.put(userSession.getId() + "_" + username, aslSession);
|
||||
}
|
||||
|
||||
public ASLSession getASLSession(String externalSessionID, String username)
|
||||
{
|
||||
ASLSession session = sessions.get(externalSessionID + "_" + username);
|
||||
// if(session == null || !session.isValid() || !session.getUsername().equals(username))
|
||||
// {
|
||||
// session = new ASLSession(externalSessionID, username);
|
||||
// sessions.put(externalSessionID + "_" + username, session);
|
||||
// }
|
||||
// if (session.getScope()!=null) //covers first helper's invocation
|
||||
// ScopeProvider.instance.set(session.getScopeName());
|
||||
//
|
||||
// if (session.getSecurityToken()!=null){
|
||||
// logger.debug("Setting SecurityTokenProvider to: "+session.getSecurityToken()+" in thread "+Thread.currentThread().getId());
|
||||
// SecurityTokenProvider.instance.set(session.getSecurityToken());
|
||||
// }
|
||||
if(session == null || !session.isValid() || !session.getUsername().equals(username))
|
||||
{
|
||||
session = new ASLSession(externalSessionID, username);
|
||||
sessions.put(externalSessionID + "_" + username, session);
|
||||
}
|
||||
if (session.getScope()!=null) //covers first helper's invocation
|
||||
ScopeProvider.instance.set(session.getScopeName());
|
||||
|
||||
if (session.getSecurityToken()!=null){
|
||||
logger.debug("Setting SecurityTokenProvider to: "+session.getSecurityToken()+" in thread "+Thread.currentThread().getId());
|
||||
SecurityTokenProvider.instance.set(session.getSecurityToken());
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// protected void finalize() throws Throwable {
|
||||
// thread.interrupt();
|
||||
// logger.debug(new Date(System.currentTimeMillis()) + " clean thread was interrupted");
|
||||
// thread.join();
|
||||
// logger.debug(new Date(System.currentTimeMillis()) + " clean thread was joint");
|
||||
// super.finalize();
|
||||
// }
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
thread.interrupt();
|
||||
logger.debug(new Date(System.currentTimeMillis()) + " clean thread was interrupted");
|
||||
thread.join();
|
||||
logger.debug(new Date(System.currentTimeMillis()) + " clean thread was joint");
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
|
||||
// protected static class CleanSessionThread extends Thread
|
||||
// {
|
||||
// public void run()
|
||||
// {
|
||||
// while(true)
|
||||
// {
|
||||
// try {
|
||||
// Thread.sleep(300000);
|
||||
// } catch (InterruptedException e) {
|
||||
// logger.error("Exception:", e);
|
||||
// logger.debug(new Date(System.currentTimeMillis()) + " clean thread was interrupted (in clean thread)");
|
||||
// break;
|
||||
// }
|
||||
// //TODO: cleanup invalid sessions: add locks...
|
||||
// Set<String> keys = sessionManager.sessions.keySet();
|
||||
// Iterator<String> iter = keys.iterator();
|
||||
// while(iter.hasNext())
|
||||
// {
|
||||
// String extSessionID = iter.next();
|
||||
// if(!sessionManager.sessions.get(extSessionID).isValid())
|
||||
// {
|
||||
// sessionManager.sessions.remove(extSessionID);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// logger.debug(new Date(System.currentTimeMillis()) + " clean thread was terminated");
|
||||
// }
|
||||
//
|
||||
// }
|
||||
protected static class CleanSessionThread extends Thread
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
try {
|
||||
Thread.sleep(300000);
|
||||
} catch (InterruptedException e) {
|
||||
logger.error("Exception:", e);
|
||||
logger.debug(new Date(System.currentTimeMillis()) + " clean thread was interrupted (in clean thread)");
|
||||
break;
|
||||
}
|
||||
//TODO: cleanup invalid sessions: add locks...
|
||||
Set<String> keys = sessionManager.sessions.keySet();
|
||||
Iterator<String> iter = keys.iterator();
|
||||
while(iter.hasNext())
|
||||
{
|
||||
String extSessionID = iter.next();
|
||||
if(!sessionManager.sessions.get(extSessionID).isValid())
|
||||
{
|
||||
sessionManager.sessions.remove(extSessionID);
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.debug(new Date(System.currentTimeMillis()) + " clean thread was terminated");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,12 +26,12 @@ import org.gcube.application.framework.core.session.SessionManager;
|
|||
import org.gcube.application.framework.core.util.CacheEntryConstants;
|
||||
import org.gcube.application.framework.core.util.QueryString;
|
||||
import org.gcube.application.framework.core.util.SessionConstants;
|
||||
//import org.gcube.common.resources.gcore.Resources;
|
||||
import org.gcube.common.resources.gcore.Resources;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
||||
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
||||
//import org.gcube.informationsystem.publisher.ScopedPublisher;
|
||||
//import org.gcube.informationsystem.publisher.stubs.registry.faults.PublisherException;
|
||||
import org.gcube.informationsystem.publisher.ScopedPublisher;
|
||||
import org.gcube.informationsystem.publisher.stubs.registry.faults.PublisherException;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.w3c.dom.Document;
|
||||
|
@ -62,7 +62,7 @@ public class GenericResource implements GenericResourceInfoI {
|
|||
// protected static ISPublisher publisher = null;
|
||||
// protected static ISClient client = null;
|
||||
|
||||
// protected static ScopedPublisher scopedPublisher = null;
|
||||
protected static ScopedPublisher scopedPublisher = null;
|
||||
protected static RegistryPublisher publisher = null;
|
||||
protected static DiscoveryClient<org.gcube.common.resources.gcore.GenericResource> client = null;
|
||||
|
||||
|
@ -82,7 +82,7 @@ public class GenericResource implements GenericResourceInfoI {
|
|||
session = SessionManager.getInstance().getASLSession(extrenalSessionID, username);
|
||||
try {
|
||||
ScopeProvider.instance.set(session.getScope());
|
||||
// scopedPublisher = RegistryPublisherFactory.scopedPublisher();
|
||||
scopedPublisher = RegistryPublisherFactory.scopedPublisher();
|
||||
publisher = RegistryPublisherFactory.create();
|
||||
} catch (Exception e) {
|
||||
logger.error("Exception:", e);
|
||||
|
@ -109,7 +109,7 @@ public class GenericResource implements GenericResourceInfoI {
|
|||
this.session = session;
|
||||
try {
|
||||
ScopeProvider.instance.set(session.getScope());
|
||||
// scopedPublisher = RegistryPublisherFactory.scopedPublisher();
|
||||
scopedPublisher = RegistryPublisherFactory.scopedPublisher();
|
||||
publisher = RegistryPublisherFactory.create();
|
||||
} catch (Exception e) {
|
||||
logger.error("Exception:", e);
|
||||
|
@ -316,8 +316,7 @@ public class GenericResource implements GenericResourceInfoI {
|
|||
//maybe should change the visibility (into public) of addScope() within the Resource class of common-gcore-resources package in order to use it here.
|
||||
List<String> scopes=new ArrayList<String>();
|
||||
scopes.add(session.getScope());
|
||||
|
||||
org.gcube.common.resources.gcore.GenericResource res = publisher.create(gCubeRes, scopes);
|
||||
org.gcube.common.resources.gcore.GenericResource res = scopedPublisher.create(gCubeRes, scopes);
|
||||
logger.info("Created Generic Resource with id: "+res.id()+" on scope: "+scopes.toString());
|
||||
|
||||
// 1-oct-2013 -- adding generic resource to cache
|
||||
|
@ -576,7 +575,7 @@ public class GenericResource implements GenericResourceInfoI {
|
|||
// //TODO
|
||||
// CachesManager.getInstance().getGenericResourceCache().get(queryString).setTimeToLive(0);
|
||||
// }
|
||||
} catch (Exception e) {
|
||||
} catch (PublisherException e) {
|
||||
logger.error("Exception:", e);
|
||||
throw new RemoteException();
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.gcube.common.resources.gcore.ServiceEndpoint;
|
|||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
||||
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
||||
//import org.gcube.informationsystem.publisher.ScopedPublisher;
|
||||
import org.gcube.informationsystem.publisher.ScopedPublisher;
|
||||
import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -32,8 +32,8 @@ public class RuntimeResource {
|
|||
private static final Logger logger = LoggerFactory.getLogger(RuntimeResource.class);
|
||||
|
||||
|
||||
// protected static ScopedPublisher scopedPublisher = null;
|
||||
protected static RegistryPublisher registryPublisher = null;
|
||||
protected static ScopedPublisher scopedPublisher = null;
|
||||
// protected static RegistryPublisher registryPublisher = null;
|
||||
protected static DiscoveryClient<ServiceEndpoint> client = null;
|
||||
|
||||
/**
|
||||
|
@ -47,9 +47,8 @@ public class RuntimeResource {
|
|||
session = SessionManager.getInstance().getASLSession(extrenalSessionID, username);
|
||||
try {
|
||||
ScopeProvider.instance.set(session.getScope());
|
||||
|
||||
// scopedPublisher = RegistryPublisherFactory.scopedPublisher();
|
||||
registryPublisher = RegistryPublisherFactory.create();
|
||||
scopedPublisher = RegistryPublisherFactory.scopedPublisher();
|
||||
// registryPublisher = RegistryPublisherFactory.create();
|
||||
} catch (Exception e) {
|
||||
logger.error("Exception:", e);
|
||||
}
|
||||
|
@ -71,8 +70,8 @@ public class RuntimeResource {
|
|||
this.session = session;
|
||||
try {
|
||||
ScopeProvider.instance.set(session.getScope());
|
||||
// scopedPublisher = RegistryPublisherFactory.scopedPublisher();
|
||||
registryPublisher = RegistryPublisherFactory.create();
|
||||
scopedPublisher = RegistryPublisherFactory.scopedPublisher();
|
||||
// registryPublisher = RegistryPublisherFactory.create();
|
||||
} catch (Exception e) {
|
||||
logger.error("Exception:", e);
|
||||
}
|
||||
|
@ -96,8 +95,8 @@ public class RuntimeResource {
|
|||
public String createRuntimeResource(ServiceEndpoint runtimeResource) throws RegistryNotFoundException {
|
||||
List<String> scopes = new ArrayList<String>();
|
||||
scopes.add(session.getScope());
|
||||
// ServiceEndpoint se = scopedPublisher.create(runtimeResource, scopes);
|
||||
ServiceEndpoint se = registryPublisher.create(runtimeResource);
|
||||
ServiceEndpoint se = scopedPublisher.create(runtimeResource, scopes);
|
||||
// ServiceEndpoint se = registryPublisher.create(runtimeResource);
|
||||
logger.debug("Created Runtime Resource with id: "+se.id()+" on scope: "+scopes.toString());
|
||||
return se.id();
|
||||
}
|
||||
|
@ -110,8 +109,8 @@ public class RuntimeResource {
|
|||
*/
|
||||
public String updateRuntimeResource(ServiceEndpoint runtimeResource) throws RemoteException {
|
||||
try {
|
||||
// ServiceEndpoint se = scopedPublisher.update(runtimeResource);
|
||||
ServiceEndpoint se = registryPublisher.update(runtimeResource);
|
||||
ServiceEndpoint se = scopedPublisher.update(runtimeResource);
|
||||
// ServiceEndpoint se = registryPublisher.update(runtimeResource);
|
||||
logger.debug("Updated Runtime Resource with id: "+runtimeResource.id()+"\tNew id : "+se.id());
|
||||
return se.id();
|
||||
} catch (Exception e) {
|
||||
|
@ -130,8 +129,8 @@ public class RuntimeResource {
|
|||
try {
|
||||
List<String> scopes=new ArrayList<String>();
|
||||
scopes.add(session.getScope());
|
||||
// ServiceEndpoint se = scopedPublisher.remove(runtimeResource,scopes);
|
||||
ServiceEndpoint se = registryPublisher.remove(runtimeResource);
|
||||
ServiceEndpoint se = scopedPublisher.remove(runtimeResource,scopes);
|
||||
// ServiceEndpoint se = registryPublisher.remove(runtimeResource);
|
||||
logger.debug("Deleted Runtime Resource with id: "+runtimeResource.id());
|
||||
return se.id();
|
||||
} catch (Exception e) {
|
||||
|
|
Loading…
Reference in New Issue