CdmTransientEntityCacher, CdmEntitySession, CdmEntitySessionManager, ICdmEntitySession, ICdmEntitySessionManager, ICdmEntitySessionManagerObserver, MockCdmEntitySession, MockCdmEntitySessionManager , eu.etaxonomy.taxeditor.cdmlib/src/main/resources/cdmlib-ehcache.xml : added statistics config , getter method for live stats and observer to update when sessions are bound and disposed
eu.etaxonomy.taxeditor.store/plugin.xml, SessionsViewPart : added new sessions debug view
MatchStrategyConfigurator : moved to cdmlib
ParseHandler, AbstractMatchingPreferences, NonViralNameMatchingPreference, ReferenceMatchingPreference, TeamOrPersonMatchingPreference : refactored after removal of MatchStrategyConfigurator replaced by enum MatchStrategy
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/ICdmEntitySession.java -text
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/ICdmEntitySessionEnabled.java -text
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/ICdmEntitySessionManager.java -text
+eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/ICdmEntitySessionManagerObserver.java -text
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/mock/MockCdmEntitySession.java -text
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/mock/MockCdmEntitySessionManager.java -text
eu.etaxonomy.taxeditor.cdmlib/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/AbstractPostOperation.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/AbstractPostTaxonOperation.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/operation/IPostOperationEnabled.java -text
-eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/parser/MatchStrategyConfigurator.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/parser/ParseHandler.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/CdmPreferences.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/ChecklistEditorGeneralPreference.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewPart.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewer.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/reporting/ReportingViewPart.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/sessions/SessionsViewPart.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/specimenSearch/SpecimenProviderSelectionComposite.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/specimenSearch/SpecimenProviderSelectionController.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/specimenSearch/SpecimenSearchComposite.java -text
junit.framework;uses:="org.junit.runner.manipulation,org.junit.runner,org.junit.runner.notification",
net.sf.ehcache,
net.sf.ehcache.config,
+ net.sf.ehcache.statistics,
net.sf.ehcache.store,
net.sf.json;uses:="net.sf.json.processors,net.sf.json.util,org.apache.commons.lang.exception",
org.apache.commons.collections;uses:="org.apache.commons.collections.keyvalue,new org.apache.commons.collections",
package eu.etaxonomy.taxeditor.remoting.cache;
import java.io.File;
-import java.io.IOException;
import java.io.InputStream;
import net.sf.ehcache.Cache;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
-import org.springframework.stereotype.Component;
import eu.etaxonomy.cdm.common.CdmUtils;
-public class CdmRemoteCacheManager {
-
+public class CdmRemoteCacheManager {
+
private CacheManager cdmlibModelCacheManager;
-
+
private static CdmRemoteCacheManager cdmRemoteCacheManager = null;
-
+
public static final Resource CDMLIB_CACHE_MANAGER_CONFIG_RESOURCE =
new ClassPathResource("cdmlib-ehcache.xml");
-
-
+
+ public static final String CDM_MODEL_CACHE_NAME = "cdmModelGetMethodsCache";
+
+
public enum CdmCacheManagerType {
CDMLIB_MODEL,
DEFAULT
}
public static CdmRemoteCacheManager getInstance(){
- if(cdmRemoteCacheManager == null) {
- cdmRemoteCacheManager = new CdmRemoteCacheManager();
+ if(cdmRemoteCacheManager == null) {
+ cdmRemoteCacheManager = new CdmRemoteCacheManager();
}
return cdmRemoteCacheManager;
}
private CdmRemoteCacheManager() {
-
- System.setProperty("ehcache.disk.store.dir", CdmUtils.getCdmHomeDir().getAbsolutePath() + File.separator + "cdmlib-model");
+
+ System.setProperty("ehcache.disk.store.dir", CdmUtils.getCdmHomeDir().getAbsolutePath() + File.separator + "cdmlib-model");
try {
- // NOTE:Programmatically creating the cache manager may solve the problem of
+ // NOTE:Programmatically creating the cache manager may solve the problem of
// recreating data written to disk on startup
// see https://stackoverflow.com/questions/1729605/ehcache-persist-to-disk-issues
//String cacheFilePath = CDMLIB_CACHE_MANAGER_CONFIG_RESOURCE.getFile().getAbsolutePath();
InputStream in = this.getClass().getClassLoader().getResourceAsStream("cdmlib-ehcache.xml");
cdmlibModelCacheManager = new CacheManager(in);
-
+
} catch (CacheException e) {
throw new CdmClientCacheException(e);
}
// throw new CdmClientCacheException(e);
// }
}
-
+
public Cache getCdmModelGetMethodsCache(){
- return cdmlibModelCacheManager.getCache("cdmModelGetMethodsCache");
+ return cdmlibModelCacheManager.getCache(CDM_MODEL_CACHE_NAME);
+ }
+
+ public CacheManager getCdmModelGetMethodsCacheManager() {
+ return cdmlibModelCacheManager;
+ }
+
+ public CacheManager getDefaultCacheManager() {
+ return CacheManager.create();
}
-
+
public void shutdown(CdmCacheManagerType ccmt) {
CacheManager cm;
- switch(ccmt) {
- case CDMLIB_MODEL:
+ switch(ccmt) {
+ case CDMLIB_MODEL:
cdmlibModelCacheManager.shutdown();
break;
case DEFAULT:
break;
default:
//do nothing
- }
+ }
}
-
+
public static void checkCacheProperties() {
String pathToCache = System.getProperty("ehcache.disk.store.dir");
if(pathToCache == null || pathToCache.isEmpty()) {
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
import javassist.util.proxy.ProxyFactory;
import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;
import net.sf.ehcache.config.CacheConfiguration;
+import net.sf.ehcache.config.SizeOfPolicyConfiguration;
+import net.sf.ehcache.statistics.LiveCacheStatistics;
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
import org.apache.log4j.Logger;
+import org.hibernate.collection.internal.PersistentList;
+import org.hibernate.collection.internal.PersistentMap;
+import org.hibernate.collection.internal.PersistentSet;
+import org.hibernate.collection.internal.PersistentSortedMap;
+import org.hibernate.collection.internal.PersistentSortedSet;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import eu.etaxonomy.cdm.api.cache.CdmServiceCacher;
import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.common.PersistentMultiLanguageText;
+import eu.etaxonomy.taxeditor.remoting.CdmRemotingException;
import eu.etaxonomy.taxeditor.remoting.cache.EntityCacherDebugResult.CdmEntityInfo;
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
cdmlibModelCache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache();
this.cdmEntitySessionManager = cdmEntitySessionManager;
+
}
public CdmTransientEntityCacher(Object obj, ICdmEntitySessionManager cdmEntitySessionManager) {
* @return
*/
private CacheConfiguration getEntityCacheConfiguration(String cacheId) {
+ SizeOfPolicyConfiguration sizeOfConfig = new SizeOfPolicyConfiguration();
+ sizeOfConfig.setMaxDepth(10000);
+ sizeOfConfig.setMaxDepthExceededBehavior("abort");
// For a better understanding on how to size caches, refer to
// http://ehcache.org/documentation/configuration/cache-size
return new CacheConfiguration(cacheId, 500)
.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU)
- .eternal(false)
+ //.eternal(true);
// default ttl and tti set to 2 hours
.timeToLiveSeconds(60*60*2)
- .timeToIdleSeconds(60*60*2);
+ .timeToIdleSeconds(60*60*2)
+ .statistics(true)
+ .sizeOfPolicy(sizeOfConfig);
+
+
}
cdmServiceCacher = css;
}
+ public LiveCacheStatistics getCacheStatistics() {
+ return cache.getLiveCacheStatistics();
+ }
+
/**
* Returns the cache corresponding to the cache id
*
}
}
+ if(o != null && o instanceof PersistentCollection) {
+ PersistentCollection pc = ((PersistentCollection)o);
+ if(pc.wasInitialized()) {
+ o = getObject(pc);
+ field.set(cdmEntity, o);
+ }
+ }
+
//field.set(cdmEntity, o);
CdmBase cdmEntityInSubGraph = null;
if(o != null
// up-to-date by setting to the value of the cdm entity being loaded
// the only execption to this is found below
field.set(cachedCdmEntity, o);
+
// the only exception to updating the field to the latest value
// is the case where the field has been already initialised, cached and
// is not the same as the one in the cache, in which case we set the value
public void dispose() {
cache.removeAll();
cache.flush();
-
+ cdmServiceCacher.getDefaultCacheManager().removeCache(cacheId);
}
if(obj instanceof CdmBase) {
return (T) debugRecursive((CdmBase)obj, alreadyVisitedEntities, entityCacherDebugResult);
} else if (obj instanceof Map) {
- return (T) debugRecursive((Map<T,T>)obj, alreadyVisitedEntities, entityCacherDebugResult);
+ return (T) debug((Map<T,T>)obj, alreadyVisitedEntities, entityCacherDebugResult);
} else if (obj instanceof Collection) {
- return (T) debugRecursive((Collection<T>)obj, alreadyVisitedEntities, entityCacherDebugResult);
+ return (T) debug((Collection<T>)obj, alreadyVisitedEntities, entityCacherDebugResult);
}
logger.info("No caching yet for type " + obj.getClass().getName());
private CdmBase debugRecursive(CdmBase cdmEntity, Set<CdmBase> alreadyVisitedEntities, EntityCacherDebugResult entityCacherDebugResult) {
- CdmBase cachedCdmEntity = debug(cdmEntity);
+
// we want to recursive through the cdmEntity (and not the cachedCdmEntity)
// since there could be new or deleted objects in the cdmEntity sub-graph
// this object will be either a CdmBase or a Collection / Map
// with CdmBase as the generic type
- CdmBase cdmEntityInSubGraph = getDebugCdmBaseTypeFieldValue(cdmEntity, cachedCdmEntity, field, alreadyVisitedEntities, entityCacherDebugResult);
+ CdmBase cdmEntityInSubGraph = getDebugCdmBaseTypeFieldValue(cdmEntity, field, alreadyVisitedEntities, entityCacherDebugResult);
if(cdmEntityInSubGraph != null) {
if(!alreadyVisitedEntities.contains(cdmEntityInSubGraph)) {
logger.info("recursive debugging object of type " + cdmEntityInSubGraph.getClass().getName() + " with id " + cdmEntityInSubGraph.getId());
throw new CdmClientCacheException("CdmEntity with class " + cdmEntity.getClass().getName() + " is not found in the cdmlib model cache. " +
"The cache may be corrupted or not in sync with the latest model version" );
}
- return cachedCdmEntity;
+ return cdmEntity;
}
private CdmBase getDebugCdmBaseTypeFieldValue(CdmBase cdmEntity,
- CdmBase cachedCdmEntity,
String fieldName,
Set<CdmBase> alreadyVisitedEntities,
EntityCacherDebugResult entityCacherDebugResult) {
- // this method attempts to make sure that for any two objects found in
- // the object graph, if they are equal then they should also be the same,
- // which is crucial for the merge to work
- if(cachedCdmEntity == null) {
- throw new CdmClientCacheException("When trying to set field value, the cached cdm entity cannot be null");
- }
Class<?> clazz = cdmEntity.getClass();
try {
if(o != null && o instanceof HibernateProxy) {
LazyInitializer hli = ((HibernateProxy)o).getHibernateLazyInitializer();
if(!hli.isUninitialized()) {
- o = ((HibernateProxy) o).getHibernateLazyInitializer().getImplementation();
+ o = hli.getImplementation();
+ }
+ }
+
+ if(o != null && o instanceof PersistentCollection) {
+ PersistentCollection pc = ((PersistentCollection)o);
+ if(pc.wasInitialized()) {
+ o = getObject(pc);
}
}
CdmBase cdmEntityInSubGraph = null;
if(CdmBase.class.isAssignableFrom(o.getClass())) {
logger.info("found initialised cdm entity '" + fieldName + "' in object of type " + clazz.getName() + " with id " + cdmEntity.getId());
cdmEntityInSubGraph = (CdmBase)o;
+ for(CdmBase visitedEntity : alreadyVisitedEntities) {
+ if(cdmEntityInSubGraph.equals(visitedEntity) && cdmEntityInSubGraph != visitedEntity) {
+ //logger.info(" - found duplicate entity at " + fieldName + "' in object of type " + clazz.getName() + " with id " + cdmEntity.getId());
+ CdmEntityInfo cei = entityCacherDebugResult.new CdmEntityInfo(cdmEntityInSubGraph, cdmEntity, field);
+ CdmEntityInfo dupCei = entityCacherDebugResult.new CdmEntityInfo(visitedEntity, null, field);
+ entityCacherDebugResult.addDuplicateEntity(cei, dupCei);
+ }
+ }
+
CdmBase cachedCdmEntityInSubGraph = getFromCache(cdmEntityInSubGraph);
// the only exception to updating the field to the latest value
// is the case where the field has been already initialised, cached and
// is not the same as the one in the cache, in which case we set the value
// of the field to the one found in the cache
- if(cachedCdmEntityInSubGraph != null) {
- if(cachedCdmEntityInSubGraph != cdmEntityInSubGraph) {
- logger.info(" - found duplicate entity at " + fieldName + "' in object of type " + clazz.getName() + " with id " + cdmEntity.getId());
- CdmEntityInfo cei = entityCacherDebugResult.new CdmEntityInfo(cdmEntityInSubGraph, cdmEntity, field);
- CdmEntityInfo cachedCei = entityCacherDebugResult.new CdmEntityInfo(cachedCdmEntityInSubGraph, null, field);
- entityCacherDebugResult.addDuplicateEntity(cei, cachedCei);
- }
- } else {
+
+ if(cachedCdmEntityInSubGraph == null) {
// found a cdm entity which is not in cache - need to record this
- logger.info(" - found entity not in cache " + fieldName + "' in object of type " + clazz.getName() + " with id " + cdmEntity.getId());
+ //logger.info(" - found entity not in cache " + fieldName + "' in object of type " + clazz.getName() + " with id " + cdmEntity.getId());
CdmEntityInfo cei = entityCacherDebugResult.new CdmEntityInfo(cdmEntityInSubGraph, cdmEntity, field);
entityCacherDebugResult.addEntityNotInCache(cei);
}
}
}
+ public static Object getObject(PersistentCollection pc) {
+ if(pc != null) {
+ if(pc instanceof PersistentSet) {
+ return new HashSet((Set)pc);
+ }
+ if(pc instanceof PersistentSortedSet) {
+ return new TreeSet((Set)pc);
+ }
+ if(pc instanceof PersistentList) {
+ return new ArrayList((List)pc);
+ }
+ if(pc instanceof PersistentMap || pc instanceof PersistentMultiLanguageText) {
+ return new HashMap((Map)pc);
+ }
+ if(pc instanceof PersistentSortedMap) {
+ return new TreeMap((Map)pc);
+ }
+ throw new CdmRemotingException("Cannot get Collection field for type " + pc.getClass().getName());
+ }
+ return null;
+ }
}
CdmEntityInfo cachedCei = entry.getValue();
sb.append(" - entity : " + cei.getCb().getUserFriendlyTypeName() + "/" + cei.getCb().getId() +
" as field " + cei.getField().getName() +
- " of entity" + cei.getCbOwner().getUserFriendlyTypeName() + "/" + cei.getCbOwner().getId());
+ " of entity " + cei.getCbOwner().getUserFriendlyTypeName() + "/" + cei.getCbOwner().getId());
sb.append(System.getProperty("line.separator"));
- sb.append(" - cached entity : " + cachedCei.getCb().getUserFriendlyTypeName() + "/" + cachedCei.getCb().getId() +
+ sb.append(" - duplicate entity : " + cachedCei.getCb().getUserFriendlyTypeName() + "/" + cachedCei.getCb().getId() +
" as field " + cachedCei.getField().getName());
+ sb.append(System.getProperty("line.separator"));
sb.append("-----------");
}
}
import java.util.Set;
import java.util.UUID;
+import net.sf.ehcache.statistics.LiveCacheStatistics;
+
+import org.apache.log4j.Logger;
import org.apache.poi.ss.formula.functions.T;
import eu.etaxonomy.cdm.api.service.IService;
public class CdmEntitySession implements ICdmEntitySession {
+ private static final Logger logger = Logger.getLogger(CdmEntitySession.class);
private final CdmEntitySessionManager cdmEntitySessionManager;
@Override
public void bind() {
+ logger.info("Binding session with owner " + sessionOwner.toString());
cdmEntitySessionManager.bind(sessionOwner);
+ cdmEntitySessionManager.notifyObservers();
}
+
/* (non-Javadoc)
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#dispose()
*/
CdmPostDataChangeObservableListener.getDefault().unregister(observer);
}
changeObservers.clear();
+ cdmEntitySessionManager.dispose(sessionOwner);
}
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#update(eu.etaxonomy.cdm.api.service.IService, eu.etaxonomy.cdm.model.common.CdmBase)
*/
@Override
- public <T extends CdmBase> void remoteUpdate(IService<T> service, T cdmBase) {
- service.merge(cdmBase);
+ public <T extends CdmBase> T remoteUpdate(IService<T> service, T cdmBase) {
+ debug(cdmBase);
+ T mergedCdmBase = service.merge(cdmBase);
+ //cdmTransientEntityCacher.clear();
// FIXME:Remoting not really sure if we need to reload the new
// merged object or can we keep using the old one
//return load(mergedCdmBase);
+
+ return mergedCdmBase;
+ }
+
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#isActive()
+ */
+ @Override
+ public boolean isActive() {
+ return cdmEntitySessionManager.getActiveSession() == this;
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#getOwner()
+ */
+ @Override
+ public ICdmEntitySessionEnabled getOwner() {
+ return sessionOwner;
+ }
+
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#getNoOfObjectsInCache()
+ */
+ @Override
+ public LiveCacheStatistics getCacheStatistics() {
+ return cdmTransientEntityCacher.getCacheStatistics();
+ }
+
+
+
+
*/
package eu.etaxonomy.taxeditor.session;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
public class CdmEntitySessionManager implements ICdmEntitySessionManager {
private static final Logger logger = Logger.getLogger(CdmEntitySessionManager.class);
- private final Map<ICdmEntitySessionEnabled, CdmEntitySession> ownerSessionMap =
- new HashMap<ICdmEntitySessionEnabled, CdmEntitySession>();
+ private final Map<ICdmEntitySessionEnabled, ICdmEntitySession> ownerSessionMap =
+ new HashMap<ICdmEntitySessionEnabled, ICdmEntitySession>();
+
+ private final List<ICdmEntitySessionManagerObserver> sessionObservers = new ArrayList<ICdmEntitySessionManagerObserver>();
private ICdmEntitySession activeSession;
@Override
public ICdmEntitySession newSession(ICdmEntitySessionEnabled sessionOwner, boolean setAsActive) {
- CdmEntitySession session = ownerSessionMap.get(sessionOwner);
+ ICdmEntitySession session = ownerSessionMap.get(sessionOwner);
if(session == null) {
session = new CdmEntitySession(sessionOwner, this);
addToOwnerSessionMap(sessionOwner, session);
+
}
if(setAsActive) {
activeSession = session;
+
}
+
return session;
}
@Override
public ICdmEntitySession getActiveSession() {
-
return activeSession;
}
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#getSessions()
+ */
+ @Override
+ public Collection<ICdmEntitySession> getSessions() {
+ return ownerSessionMap.values();
+ }
+
+
/* (non-Javadoc)
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#bind(eu.etaxonomy.taxeditor.session.ISessionEventListener)
*/
if(session == null) {
session = newSession(sessionOwner,true);
}
+
activeSession = session;
+
}
/* (non-Javadoc)
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#dispose(eu.etaxonomy.taxeditor.session.ISessionEventListener)
*/
- @Override
- public void dispose(ICdmEntitySessionEnabled owner) {
+ void dispose(ICdmEntitySessionEnabled owner) {
ICdmEntitySession session = ownerSessionMap.get(owner);
if(session == null) {
logger.info("No Session connected to owner, nothing to dispose");
return;
}
- session.dispose();
+ ownerSessionMap.remove(owner);
+ notifyObservers();
}
- void addToOwnerSessionMap(ICdmEntitySessionEnabled owner, CdmEntitySession session) {
+ void addToOwnerSessionMap(ICdmEntitySessionEnabled owner, ICdmEntitySession session) {
ownerSessionMap.put(owner, session);
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#addSessionListener()
+ */
+ @Override
+ public void addSessionObserver(ICdmEntitySessionManagerObserver sessionObserver) {
+ sessionObservers.add(sessionObserver);
+ }
+
+ public void notifyObservers() {
+ for(ICdmEntitySessionManagerObserver sessionObserver : sessionObservers) {
+ sessionObserver.changed();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#isRemoting()
+ */
+ @Override
+ public boolean isRemoting() {
+ // FIXME:Remoting stupid method to check whether we are in remoting
+ return true;
+ }
+
+
+
+
}
import java.util.Set;
import java.util.UUID;
+import net.sf.ehcache.statistics.LiveCacheStatistics;
import eu.etaxonomy.cdm.api.service.IService;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.common.ICdmBase;
public interface ICdmEntitySession {
+ public ICdmEntitySessionEnabled getOwner();
+
+ public LiveCacheStatistics getCacheStatistics();
+
public <O extends Object> O load(O obj);
public <T extends CdmBase> T load(T cdmBase);
public <T extends CdmBase> UUID remoteSave(IService<T> service, T cdmBase);
- public <T extends CdmBase> void remoteUpdate(IService<T> service, T cdmBase);
+ public <T extends CdmBase> T remoteUpdate(IService<T> service, T cdmBase);
*/
public void fireNotifications();
+ public boolean isActive();
+
// public abstract <T extends CdmBase> Collection<T> load(
// ISessionEventListener sessionOwner, Collection<T> cdmBaseList);
- public abstract <T extends CdmBase> Collection<T> load(
- Collection<T> cdmBaseList);
+ public abstract <T extends CdmBase> Collection<T> load(Collection<T> cdmBaseList);
- public abstract void dispose(ICdmEntitySessionEnabled owner);
+ //public abstract void dispose(ICdmEntitySessionEnabled owner);
/**
* @return
*/
public ICdmEntitySession getActiveSession();
+ public Collection<ICdmEntitySession> getSessions();
+
+ public void addSessionObserver(ICdmEntitySessionManagerObserver sessionObserver);
+
//FIXME:Remoting would be nice to have these methods working,
// but they can only be useful if we can 'intelligently'
// get from a model class to the correspoding service class
// public abstract void commit(IService service, CdmBase cdmBase);
+ public boolean isRemoting();
+
}
\ No newline at end of file
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.session;
+
+/**
+ * @author cmathew
+ * @date 16 Feb 2015
+ *
+ */
+public interface ICdmEntitySessionManagerObserver {
+
+ public void changed();
+
+}
import java.util.Set;
import java.util.UUID;
+import net.sf.ehcache.statistics.LiveCacheStatistics;
import eu.etaxonomy.cdm.api.service.IService;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.common.ICdmBase;
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#update(eu.etaxonomy.cdm.api.service.IService, eu.etaxonomy.cdm.model.common.CdmBase)
*/
@Override
- public <T extends CdmBase> void remoteUpdate(IService<T> service, T cdmBase) {
-
+ public <T extends CdmBase> T remoteUpdate(IService<T> service, T cdmBase) {
+ return cdmBase;
}
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#getOwner()
+ */
+ @Override
+ public ICdmEntitySessionEnabled getOwner() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#getCacheStatistics()
+ */
+ @Override
+ public LiveCacheStatistics getCacheStatistics() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#isActive()
+ */
+ @Override
+ public boolean isActive() {
+ return false;
+ }
+
}
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManagerObserver;
public class MockCdmEntitySessionManager implements ICdmEntitySessionManager {
}
- @Override
- public void dispose(ICdmEntitySessionEnabled owner) {
-
- }
-
/* (non-Javadoc)
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#newSession(eu.etaxonomy.taxeditor.session.ISessionEventListener, boolean)
*/
return new MockCdmEntitySession();
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#getSessions()
+ */
+ @Override
+ public Collection<ICdmEntitySession> getSessions() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#addSessionObserver(eu.etaxonomy.taxeditor.session.ICdmEntitySessionManagerObserver)
+ */
+ @Override
+ public void addSessionObserver(ICdmEntitySessionManagerObserver sessionObserver) {
+
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#isRemoting()
+ */
+ @Override
+ public boolean isRemoting() {
+ return false;
+ }
+
}
<ehcache name="cdmlibModelCacheManager">
<diskStore path="ehcache.disk.store.dir/cdmlib" />
<cache name="cdmModelGetMethodsCache" maxElementsInMemory="1" maxElementsOnDisk="0" eternal="true"
- overflowToDisk="true" diskPersistent="true" memoryStoreEvictionPolicy="LRU">
+ overflowToDisk="true" diskPersistent="true" memoryStoreEvictionPolicy="LRU" statistics="true">
+ <sizeOfPolicy maxDepth="1000" maxDepthExceededBehavior="abort"/>
</cache>
</ehcache>
\ No newline at end of file
public abstract <T extends CdmBase> List<T> getRootEntities();
- public <T extends CdmBase> void update() {
- List<T> rootEntities = getRootEntities();
- if(rootEntities != null) {
- for(T cdmBase : rootEntities) {
- cdmEntitySession.remoteUpdate(getService(), cdmBase);
- }
- }
- }
+ public abstract <T extends CdmBase> void update();
}
public List<TaxonNode> getRootEntities() {
return Arrays.asList(taxonNode);
}
+
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#update()
+ */
+ @Override
+ public <T extends CdmBase> void update() {
+ taxonNode = getCdmEntitySession().remoteUpdate(service, taxonNode);
+ }
}
}
public void dispose() {
- CdmStore.getCurrentSessionManager().dispose(this);
+ cdmEntitySession.dispose();
}
id="eu.etaxonomy.taxeditor.view.derivateSearch.DerivateSearchView"
name="%view.name.6"
restorable="true">
+ </view>
+ <view
+ allowMultiple="false"
+ class="eu.etaxonomy.taxeditor.view.sessions.SessionsViewPart"
+ id="eu.etaxonomy.taxeditor.view.sessions.SessionsViewPart"
+ name="Sessions"
+ restorable="false">
</view>
</extension>
<extension
</reference>
</visibleWhen>
</command>
+ <command
+ commandId="org.eclipse.ui.views.showView"
+ label="Sessions"
+ style="push">
+ <parameter
+ name="org.eclipse.ui.views.showView.viewId"
+ value="eu.etaxonomy.taxeditor.view.sessions.SessionsViewPart">
+ </parameter>
+ </command>
</menu>
</menuContribution>
<menuContribution
+++ /dev/null
-// $Id$
-/**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-
-package eu.etaxonomy.taxeditor.parser;
-
-import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
-import eu.etaxonomy.cdm.model.name.NonViralName;
-import eu.etaxonomy.cdm.model.reference.Reference;
-import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
-import eu.etaxonomy.cdm.strategy.match.MatchException;
-import eu.etaxonomy.cdm.strategy.match.MatchMode;
-import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
-
-/**
- * This class defines the MatchStrategies that will be used by the ParseHandler.
- *
- * @author n.hoffmann
- * @created Jan 22, 2010
- * @version 1.0
- */
-public class MatchStrategyConfigurator {
-
- /**
- * <p>NonViralNameMatchStrategy</p>
- *
- * @throws eu.etaxonomy.cdm.strategy.match.MatchException if any.
- * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
- */
- public static IMatchStrategy NonViralNameMatchStrategy() throws MatchException{
- return getDefaultNonViralNameMatchStrategy();// PreferencesUtil.getMatchStrategy(NonViralName.class);
- }
-
- /**
- * <p>TeamOrPersonMatchStrategy</p>
- *
- * @throws eu.etaxonomy.cdm.strategy.match.MatchException if any.
- * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
- */
- public static IMatchStrategy TeamOrPersonMatchStrategy() throws MatchException{
- return null;// PreferencesUtil.getMatchStrategy(TeamOrPersonBase.class);
- }
-
- /**
- * <p>ReferenceMatchStrategy</p>
- *
- * @throws eu.etaxonomy.cdm.strategy.match.MatchException if any.
- * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
- */
- public static IMatchStrategy ReferenceMatchStrategy() throws MatchException{
- return getDefaultReferenceMatchStrategy();// PreferencesUtil.getMatchStrategy(ReferenceBase.class);
- }
-
- /**
- * <p>getDefaultNonViralNameMatchStrategy</p>
- *
- * @throws eu.etaxonomy.cdm.strategy.match.MatchException if any.
- * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
- */
- public static IMatchStrategy getDefaultNonViralNameMatchStrategy() throws MatchException{
- IMatchStrategy strategy = PreferencesUtil.getDefaultMatchStrategy(NonViralName.class);
-
- strategy.setMatchMode("nomenclaturalReference", MatchMode.IGNORE);
- strategy.setMatchMode("combinationAuthorTeam", MatchMode.IGNORE);
- strategy.setMatchMode("exCombinationAuthorTeam", MatchMode.IGNORE);
- strategy.setMatchMode("basionymAuthorTeam", MatchMode.IGNORE);
- strategy.setMatchMode("exBasionymAuthorTeam", MatchMode.IGNORE);
-
- return strategy;
- }
-
- /**
- * <p>getDefaultTeamOrPersonMatchStrategy</p>
- *
- * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
- * @throws eu.etaxonomy.cdm.strategy.match.MatchException if any.
- */
- public static IMatchStrategy getDefaultTeamOrPersonMatchStrategy() throws MatchException{
- IMatchStrategy strategy = PreferencesUtil.getDefaultMatchStrategy(TeamOrPersonBase.class);
-
- return strategy;
- }
-
-
- /**
- * <p>getDefaultReferenceMatchStrategy</p>
- *
- * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
- * @throws eu.etaxonomy.cdm.strategy.match.MatchException if any.
- */
- public static IMatchStrategy getDefaultReferenceMatchStrategy() throws MatchException{
- IMatchStrategy strategy = PreferencesUtil.getDefaultMatchStrategy(Reference.class);
-
- strategy.setMatchMode("title", MatchMode.EQUAL);
- strategy.setMatchMode("inReference", MatchMode.IGNORE);
-
- return strategy;
- }
-
- /**
- * <p>setMatchStrategy</p>
- *
- * @param matchStrategy a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
- */
- public static void setMatchStrategy(IMatchStrategy matchStrategy) {
- PreferencesUtil.setMatchStrategy(matchStrategy);
- }
-
-}
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
import eu.etaxonomy.cdm.model.reference.Reference;
import eu.etaxonomy.cdm.strategy.match.MatchException;
+import eu.etaxonomy.cdm.strategy.match.MatchStrategyConfigurator.MatchStrategy;
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
return new ArrayList<INomenclaturalReference>();
}
try{
- return CdmStore.getService(ICommonService.class).findMatching(nomenclaturalReference, MatchStrategyConfigurator.ReferenceMatchStrategy());
+ return CdmStore.getService(ICommonService.class).findMatching(nomenclaturalReference, MatchStrategy.Reference);
}catch (MatchException e) {
MessagingUtils.error(this.getClass(), "Error finding matching references", e);
}
}
try{
- return CdmStore.getService(ICommonService.class).findMatching(authorTeam, MatchStrategyConfigurator.TeamOrPersonMatchStrategy());
+ return CdmStore.getService(ICommonService.class).findMatching(authorTeam, MatchStrategy.TeamOrPerson);
}catch (MatchException e) {
MessagingUtils.error(this.getClass(), "Error finding matching authors", e);
}
private List<TaxonNameBase> findMatchingLatinNames(TaxonNameBase taxonNameBase) {
try {
- return CdmStore.getService(ICommonService.class).findMatching(taxonNameBase, MatchStrategyConfigurator.NonViralNameMatchStrategy());
+ return CdmStore.getService(ICommonService.class).findMatching(taxonNameBase, MatchStrategy.NonViralName);
} catch (MatchException e) {
MessagingUtils.error(this.getClass(), "Error finding matching names", e);
import eu.etaxonomy.cdm.strategy.match.MatchException;
import eu.etaxonomy.cdm.strategy.match.MatchMode;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
-import eu.etaxonomy.taxeditor.parser.MatchStrategyConfigurator;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.CdmStore;
/**
/** {@inheritDoc} */
@Override
protected void performApply() {
- MatchStrategyConfigurator.setMatchStrategy(matchStrategy);
+ PreferencesUtil.setMatchStrategy(matchStrategy);
super.performApply();
}
// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
import eu.etaxonomy.cdm.model.name.NonViralName;
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
import eu.etaxonomy.cdm.strategy.match.MatchException;
+import eu.etaxonomy.cdm.strategy.match.MatchStrategyConfigurator;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
-import eu.etaxonomy.taxeditor.parser.MatchStrategyConfigurator;
/**
* <p>NonViralNameMatchingPreference class.</p>
* @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
*/
/** {@inheritDoc} */
- public void init(IWorkbench workbench) {
+ @Override
+ public void init(IWorkbench workbench) {
clazz = NonViralName.class;
-
+
try {
matchStrategy = MatchStrategyConfigurator.NonViralNameMatchStrategy();
} catch (MatchException e) {
throw new RuntimeException(e);
}
}
-
+
/* (non-Javadoc)
* @see eu.etaxonomy.taxeditor.preference.matching.AbstractMatchingPreferences#getDefaultMatchStrategy()
*/
// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
import eu.etaxonomy.cdm.model.reference.Reference;
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
import eu.etaxonomy.cdm.strategy.match.MatchException;
+import eu.etaxonomy.cdm.strategy.match.MatchStrategyConfigurator;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
-import eu.etaxonomy.taxeditor.parser.MatchStrategyConfigurator;
/**
* <p>ReferenceMatchingPreference class.</p>
* @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
*/
/** {@inheritDoc} */
- public void init(IWorkbench workbench) {
+ @Override
+ public void init(IWorkbench workbench) {
clazz = Reference.class;
-
+
try {
matchStrategy = MatchStrategyConfigurator.ReferenceMatchStrategy();
} catch (MatchException e) {
// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
import eu.etaxonomy.cdm.strategy.match.MatchException;
+import eu.etaxonomy.cdm.strategy.match.MatchStrategyConfigurator;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
-import eu.etaxonomy.taxeditor.parser.MatchStrategyConfigurator;
/**
* <p>TeamOrPersonMatchingPreference class.</p>
* @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
*/
/** {@inheritDoc} */
- public void init(IWorkbench workbench) {
+ @Override
+ public void init(IWorkbench workbench) {
clazz = TeamOrPersonBase.class;
-
+
try {
matchStrategy = MatchStrategyConfigurator.TeamOrPersonMatchStrategy();
} catch (MatchException e) {
MessagingUtils.error(this.getClass(), e);
throw new RuntimeException(e);
}
- }
+ }
/* (non-Javadoc)
* @see eu.etaxonomy.taxeditor.preference.matching.AbstractMatchingPreferences#getDefaultMatchStrategy()
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.view.sessions;
+
+import java.text.DecimalFormat;
+import java.util.Collection;
+
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.statistics.LiveCacheStatistics;
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.part.ViewPart;
+import org.eclipse.wb.swt.SWTResourceManager;
+
+import eu.etaxonomy.cdm.api.cache.CdmCacher;
+import eu.etaxonomy.taxeditor.remoting.cache.CdmRemoteCacheManager;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManagerObserver;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * @author cmathew
+ * @date 16 Feb 2015
+ *
+ */
+public class SessionsViewPart extends ViewPart implements ICdmEntitySessionManagerObserver {
+
+ public static final String ID = "eu.etaxonomy.taxeditor.view.sessions.SessionsViewPart"; //$NON-NLS-1$
+ private Table tableSessions;
+
+ private final String[] titles = { "Owner", "In Memory", "On Disk"};
+
+ private final ICdmEntitySessionManager cdmEntitySessionManager;
+ private Text txtNoOfSessions;
+ private Text txtNoOfCaches;
+ private Text txtDefaultInMemory;
+ private Text txtCdmModelInMemory;
+ private Text txtCdmModelOnDisk;
+ private Text txtDefaultOnDisk;
+ public SessionsViewPart() {
+ this.cdmEntitySessionManager = CdmStore.getCurrentSessionManager();
+ if(cdmEntitySessionManager != null) {
+ cdmEntitySessionManager.addSessionObserver(this);
+ }
+ }
+
+ /**
+ * Create contents of the view part.
+ * @param parent
+ */
+ @Override
+ public void createPartControl(Composite parent) {
+ Composite container = new Composite(parent, SWT.NONE);
+ container.setLayout(new GridLayout(6, false));
+ {
+ Label lblNoOfSessions = new Label(container, SWT.NONE);
+ lblNoOfSessions.setFont(SWTResourceManager.getFont("Ubuntu", 10, SWT.NORMAL));
+ lblNoOfSessions.setAlignment(SWT.RIGHT);
+ GridData gd_lblNoOfSessions = new GridData(SWT.RIGHT, SWT.FILL, false, false, 1, 1);
+ gd_lblNoOfSessions.widthHint = 115;
+ gd_lblNoOfSessions.minimumHeight = 30;
+ lblNoOfSessions.setLayoutData(gd_lblNoOfSessions);
+ lblNoOfSessions.setText("No. of Sessions : ");
+ }
+ {
+ txtNoOfSessions = new Text(container, SWT.BORDER);
+ txtNoOfSessions.setEditable(false);
+ txtNoOfSessions.setBackground(SWTResourceManager.getColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
+ GridData gd_txtNoOfSessions = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+ gd_txtNoOfSessions.widthHint = 50;
+ txtNoOfSessions.setLayoutData(gd_txtNoOfSessions);
+ }
+ new Label(container, SWT.NONE);
+ new Label(container, SWT.NONE);
+ new Label(container, SWT.NONE);
+ new Label(container, SWT.NONE);
+ {
+ Label lblNoOfCaches = new Label(container, SWT.CENTER);
+ lblNoOfCaches.setAlignment(SWT.RIGHT);
+ lblNoOfCaches.setFont(SWTResourceManager.getFont("Ubuntu", 10, SWT.NORMAL));
+ GridData gd_lblNoOfCaches = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
+ gd_lblNoOfCaches.widthHint = 150;
+ lblNoOfCaches.setLayoutData(gd_lblNoOfCaches);
+ lblNoOfCaches.setText("No. of entity caches : ");
+ }
+ {
+ txtNoOfCaches = new Text(container, SWT.BORDER);
+ txtNoOfCaches.setEditable(false);
+ GridData gd_txtNoOfCaches = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+ gd_txtNoOfCaches.widthHint = 50;
+ txtNoOfCaches.setLayoutData(gd_txtNoOfCaches);
+ }
+ new Label(container, SWT.NONE);
+ new Label(container, SWT.NONE);
+ new Label(container, SWT.NONE);
+ new Label(container, SWT.NONE);
+
+ {
+ Label lblDefaultCache = new Label(container, SWT.CENTER);
+ lblDefaultCache.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblDefaultCache.setText("Default Cache, ");
+ lblDefaultCache.setFont(SWTResourceManager.getFont("Ubuntu", 10, SWT.NORMAL));
+ lblDefaultCache.setAlignment(SWT.RIGHT);
+ }
+ {
+ Label lblDefaultInMemory = new Label(container, SWT.CENTER);
+ lblDefaultInMemory.setText("in Memory : ");
+ lblDefaultInMemory.setFont(SWTResourceManager.getFont("Ubuntu", 10, SWT.NORMAL));
+ lblDefaultInMemory.setAlignment(SWT.RIGHT);
+ lblDefaultInMemory.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ }
+ {
+ txtDefaultInMemory = new Text(container, SWT.BORDER);
+ txtDefaultInMemory.setEditable(false);
+ GridData gd_txtDefaultInMemory = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+ gd_txtDefaultInMemory.widthHint = 130;
+ txtDefaultInMemory.setLayoutData(gd_txtDefaultInMemory);
+ }
+ {
+ Label lblDefaultOnDisk = new Label(container, SWT.CENTER);
+ lblDefaultOnDisk.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblDefaultOnDisk.setText("on Disk : ");
+ lblDefaultOnDisk.setFont(SWTResourceManager.getFont("Ubuntu", 10, SWT.NORMAL));
+ lblDefaultOnDisk.setAlignment(SWT.RIGHT);
+ }
+ {
+ txtDefaultOnDisk = new Text(container, SWT.BORDER);
+ txtDefaultOnDisk.setEditable(false);
+ txtDefaultOnDisk.setText("");
+ GridData gd_txtDefaultOnDisk = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+ gd_txtDefaultOnDisk.widthHint = 130;
+ txtDefaultOnDisk.setLayoutData(gd_txtDefaultOnDisk);
+ }
+ new Label(container, SWT.NONE);
+ {
+ Label lblCdmModelCache = new Label(container, SWT.CENTER);
+ lblCdmModelCache.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblCdmModelCache.setText("CDM Model Cache, ");
+ lblCdmModelCache.setFont(SWTResourceManager.getFont("Ubuntu", 10, SWT.NORMAL));
+ lblCdmModelCache.setAlignment(SWT.RIGHT);
+ }
+ {
+ Label lblCdmModelInMemory = new Label(container, SWT.CENTER);
+ lblCdmModelInMemory.setText("in Memory : ");
+ lblCdmModelInMemory.setFont(SWTResourceManager.getFont("Ubuntu", 10, SWT.NORMAL));
+ lblCdmModelInMemory.setAlignment(SWT.RIGHT);
+ GridData gd_lblCdmModelInMemory = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
+ gd_lblCdmModelInMemory.widthHint = 86;
+ lblCdmModelInMemory.setLayoutData(gd_lblCdmModelInMemory);
+ }
+ {
+ txtCdmModelInMemory = new Text(container, SWT.BORDER);
+ txtCdmModelInMemory.setEditable(false);
+ GridData gd_txtCdmModelInMemory = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+ gd_txtCdmModelInMemory.widthHint = 130;
+ txtCdmModelInMemory.setLayoutData(gd_txtCdmModelInMemory);
+ }
+ {
+ Label lblCdmModelOnDisk = new Label(container, SWT.CENTER);
+ lblCdmModelOnDisk.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ lblCdmModelOnDisk.setText("on Disk : ");
+ lblCdmModelOnDisk.setFont(SWTResourceManager.getFont("Ubuntu", 10, SWT.NORMAL));
+ lblCdmModelOnDisk.setAlignment(SWT.RIGHT);
+ }
+ {
+ txtCdmModelOnDisk = new Text(container, SWT.BORDER);
+ txtCdmModelOnDisk.setEditable(false);
+ txtCdmModelOnDisk.setText("");
+ GridData gd_txtCdmModelOnDisk = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+ gd_txtCdmModelOnDisk.widthHint = 130;
+ txtCdmModelOnDisk.setLayoutData(gd_txtCdmModelOnDisk);
+ }
+ new Label(container, SWT.NONE);
+ {
+ Button btnRefresh = new Button(container, SWT.NONE);
+ btnRefresh.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ changed();
+ }
+ });
+ GridData gd_btnRefresh = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
+ gd_btnRefresh.widthHint = 100;
+ btnRefresh.setLayoutData(gd_btnRefresh);
+ btnRefresh.setText("Refresh");
+ }
+ new Label(container, SWT.NONE);
+ new Label(container, SWT.NONE);
+ new Label(container, SWT.NONE);
+ new Label(container, SWT.NONE);
+ new Label(container, SWT.NONE);
+
+ {
+ tableSessions = new Table(container, SWT.BORDER | SWT.FULL_SELECTION);
+ tableSessions.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
+ tableSessions.setHeaderVisible(true);
+ tableSessions.setLinesVisible(true);
+ }
+ new Label(container, SWT.NONE);
+
+ createActions();
+ initializeToolBar();
+ initializeMenu();
+ }
+
+ /**
+ * Create the actions.
+ */
+ private void createActions() {
+
+
+ for (String title : titles) {
+ TableColumn column = new TableColumn(tableSessions, SWT.NULL);
+ column.setWidth(200);
+ column.setText(title);
+ }
+ changed();
+
+ }
+
+
+ @Override
+ public void changed() {
+ tableSessions.removeAll();
+ if(cdmEntitySessionManager != null) {
+ Collection<ICdmEntitySession> sessions = cdmEntitySessionManager.getSessions();
+ txtNoOfSessions.setText(String.valueOf(sessions.size()));
+ for(ICdmEntitySession session : sessions) {
+ if(session.getOwner() != null) {
+ TableItem item = new TableItem(tableSessions, SWT.NULL);
+ item.setText(session.getOwner().toString());
+ String activePrefix = "";
+ if(session.isActive()) {
+ activePrefix = "*";
+ }
+ item.setText(0, activePrefix + session.getOwner().toString());
+ LiveCacheStatistics cacheStatistics = session.getCacheStatistics();
+ item.setText(1, getInMemoryStats(cacheStatistics));
+ item.setText(2, getOnDiskStats(cacheStatistics));
+ }
+ }
+ for (int i=0; i<titles.length; i++) {
+ tableSessions.getColumn (i).pack ();
+ }
+ }
+
+ CdmRemoteCacheManager instance = CdmRemoteCacheManager.getInstance();
+ int cdmEnityCacheSize = instance.getDefaultCacheManager().getCacheNames().length;
+ txtNoOfCaches.setText(String.valueOf(cdmEnityCacheSize));
+
+ Cache defaultCache = instance.getDefaultCacheManager().getCache(CdmCacher.DEFAULT_CACHE_NAME);
+ txtDefaultInMemory.setText("");
+ txtDefaultOnDisk.setText("");
+ if(defaultCache != null) {
+ LiveCacheStatistics liveCacheStatistics = defaultCache.getLiveCacheStatistics();
+ txtDefaultInMemory.setText(getInMemoryStats(liveCacheStatistics));
+ txtDefaultOnDisk.setText(getOnDiskStats(liveCacheStatistics));
+ }
+
+ Cache cdmModelGetMethodsCache = instance.getCdmModelGetMethodsCache();
+ txtCdmModelInMemory.setText("");
+ txtCdmModelOnDisk.setText("");
+ if(cdmModelGetMethodsCache != null) {
+ LiveCacheStatistics liveCacheStatistics = cdmModelGetMethodsCache.getLiveCacheStatistics();
+ txtCdmModelInMemory.setText(getInMemoryStats(liveCacheStatistics));
+ txtCdmModelOnDisk.setText(getOnDiskStats(liveCacheStatistics));
+ }
+
+ }
+
+ private String getInMemoryStats(LiveCacheStatistics statistics) {
+ long localHeapSize = statistics.getLocalHeapSize();
+
+ long localHeapSizeInBytes = statistics.getLocalHeapSizeInBytes();
+ String localHeapSizeInBytesStr =
+ (new DecimalFormat("#.##")).format(localHeapSizeInBytes/1048576.0);
+ return String.valueOf(localHeapSize) + " objects / " + localHeapSizeInBytesStr + " Mb";
+ }
+
+ private String getOnDiskStats(LiveCacheStatistics statistics) {
+ long localDiskSize = statistics.getLocalDiskSize();
+
+ long localDiskSizeInBytes = statistics.getLocalDiskSizeInBytes();
+ String localDiskSizeInBytesStr =
+ (new DecimalFormat("#.##")).format(localDiskSizeInBytes/1048576.0);
+ return String.valueOf(localDiskSize) + " objects / " + localDiskSizeInBytesStr + " Mb";
+ }
+
+ /**
+ * Initialize the toolbar.
+ */
+ private void initializeToolBar() {
+ IToolBarManager toolbarManager = getViewSite().getActionBars().getToolBarManager();
+ }
+
+ /**
+ * Initialize the menu.
+ */
+ private void initializeMenu() {
+ IMenuManager menuManager = getViewSite().getActionBars().getMenuManager();
+ }
+
+ @Override
+ public void setFocus() {
+ // Set the focus
+ }
+
+}