// $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.
-*/
+ * 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.CacheManager;
import net.sf.ehcache.statistics.LiveCacheStatistics;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.wb.swt.SWTResourceManager;
import eu.etaxonomy.cdm.api.cache.CdmCacher;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
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.session.NullSession;
import eu.etaxonomy.taxeditor.store.CdmStore;
/**
public class SessionsViewPart extends ViewPart implements ICdmEntitySessionManagerObserver {
public static final String ID = "eu.etaxonomy.taxeditor.view.sessions.SessionsViewPart"; //$NON-NLS-1$
+ public static final String OPEN_INSPECT_SESSIONS_DIALOG_ID = "eu.etaxonomy.taxeditor.store.open.InspectSessionsDialog";
private Table tableSessions;
private final String[] titles = { "Owner", "In Memory", "On Disk"};
private Text txtCdmModelInMemory;
private Text txtCdmModelOnDisk;
private Text txtDefaultOnDisk;
+
public SessionsViewPart() {
this.cdmEntitySessionManager = CdmStore.getCurrentSessionManager();
if(cdmEntitySessionManager != null) {
@Override
public void createPartControl(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
- container.setLayout(new GridLayout(6, false));
+ container.setLayout(new GridLayout(5, false));
{
Label lblNoOfSessions = new Label(container, SWT.NONE);
lblNoOfSessions.setFont(SWTResourceManager.getFont("Ubuntu", 10, SWT.NORMAL));
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);
}
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 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 : ");
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));
gd_txtCdmModelOnDisk.widthHint = 130;
txtCdmModelOnDisk.setLayoutData(gd_txtCdmModelOnDisk);
}
- new Label(container, SWT.NONE);
{
Button btnRefresh = new Button(container, SWT.NONE);
btnRefresh.addSelectionListener(new SelectionAdapter() {
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);
+ {
+ Button btnInspectActiveSession = new Button(container, SWT.NONE);
+ btnInspectActiveSession.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ AbstractUtility.executeCommand(OPEN_INSPECT_SESSIONS_DIALOG_ID, this, null);
}
- new Label(container, SWT.NONE);
+ });
+ btnInspectActiveSession.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1));
+ btnInspectActiveSession.setText("Inspect Active Session");
+ }
+ new Label(container, SWT.NONE);
+ new Label(container, SWT.NONE);
+
+ {
+ tableSessions = new Table(container, SWT.BORDER | SWT.FULL_SELECTION);
+ GridData gd_tableSessions = new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1);
+ gd_tableSessions.widthHint = 769;
+ tableSessions.setLayoutData(gd_tableSessions);
+ tableSessions.setHeaderVisible(true);
+ tableSessions.setLinesVisible(true);
+ }
createActions();
initializeToolBar();
for (String title : titles) {
- TableColumn column = new TableColumn(tableSessions, SWT.NULL);
- column.setWidth(200);
- column.setText(title);
+ TableColumn column = new TableColumn(tableSessions, SWT.NULL);
+ column.setWidth(200);
+ column.setText(title);
}
changed();
@Override
public void changed() {
+ if(tableSessions.isDisposed()) {
+ return;
+ }
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));
- }
+ addSession(session);
+ }
+ ICdmEntitySession nullSession = cdmEntitySessionManager.getNullSession();
+ if(nullSession != null) {
+ addSession(nullSession);
}
for (int i=0; i<titles.length; i++) {
tableSessions.getColumn (i).pack ();
}
CdmRemoteCacheManager instance = CdmRemoteCacheManager.getInstance();
- int cdmEnityCacheSize = instance.getDefaultCacheManager().getCacheNames().length;
+ int cdmEnityCacheSize = CacheManager.create().getCacheNames().length;
txtNoOfCaches.setText(String.valueOf(cdmEnityCacheSize));
- Cache defaultCache = instance.getDefaultCacheManager().getCache(CdmCacher.DEFAULT_CACHE_NAME);
+ Cache defaultCache = CacheManager.create().getCache(CdmCacher.DEFAULT_CACHE_NAME);
txtDefaultInMemory.setText("");
txtDefaultOnDisk.setText("");
if(defaultCache != null) {
}
+ private void addSession(ICdmEntitySession session) {
+
+ TableItem item = new TableItem(tableSessions, SWT.NULL);
+
+ String activePrefix = "";
+ if(session.isActive()) {
+ activePrefix = "*";
+ }
+ String sessionOwnerString = "";
+ if(session instanceof NullSession) {
+ sessionOwnerString = "Null Session";
+ } else {
+ if(session.getOwner() != null) {
+ sessionOwnerString = session.getOwner().toString();
+ }
+ }
+ item.setText(0, activePrefix + sessionOwnerString);
+ LiveCacheStatistics cacheStatistics = session.getCacheStatistics();
+ item.setText(1, getInMemoryStats(cacheStatistics));
+ item.setText(2, getOnDiskStats(cacheStatistics));
+ }
+
private String getInMemoryStats(LiveCacheStatistics statistics) {
- long localHeapSize = statistics.getLocalHeapSize();
+ if(statistics != null) {
+ long localHeapSize = statistics.getLocalHeapSize();
- long localHeapSizeInBytes = statistics.getLocalHeapSizeInBytes();
- String localHeapSizeInBytesStr =
- (new DecimalFormat("#.##")).format(localHeapSizeInBytes/1048576.0);
- return String.valueOf(localHeapSize) + " objects / " + localHeapSizeInBytesStr + " Mb";
+ long localHeapSizeInBytes = statistics.getLocalHeapSizeInBytes();
+ String localHeapSizeInBytesStr =
+ (new DecimalFormat("#.##")).format(localHeapSizeInBytes/1048576.0);
+ return String.valueOf(localHeapSize) + " objects / " + localHeapSizeInBytesStr + " Mb";
+ }
+ return "";
}
private String getOnDiskStats(LiveCacheStatistics statistics) {
- long localDiskSize = statistics.getLocalDiskSize();
+ if(statistics != null) {
+ long localDiskSize = statistics.getLocalDiskSize();
- long localDiskSizeInBytes = statistics.getLocalDiskSizeInBytes();
- String localDiskSizeInBytesStr =
- (new DecimalFormat("#.##")).format(localDiskSizeInBytes/1048576.0);
- return String.valueOf(localDiskSize) + " objects / " + localDiskSizeInBytesStr + " Mb";
+ long localDiskSizeInBytes = statistics.getLocalDiskSizeInBytes();
+ String localDiskSizeInBytesStr =
+ (new DecimalFormat("#.##")).format(localDiskSizeInBytes/1048576.0);
+ return String.valueOf(localDiskSize) + " objects / " + localDiskSizeInBytesStr + " Mb";
+ }
+ return "";
}
/**