Issue #1638 Added cache of PluginDao objects in PluginFactory so they can safely cache data internally by not being recreated every store operation. Added default names to sample actions
Amend: Create copy on write for PluginFactory Change-Id: I5373d1efadc1ab3c5e368a3caae55a5ff85a2d6f Former-commit-id: 4249c63fb4ee62862cb9bbaa36d47607ba6784e8
This commit is contained in:
parent
bba3563265
commit
6e70b21f5f
3 changed files with 29 additions and 6 deletions
|
@ -59,10 +59,11 @@ public class LatLonReadoutAction extends AbstractRightClickAction {
|
|||
private boolean hasLatLonReadout = false;
|
||||
|
||||
public LatLonReadoutAction() {
|
||||
this.actionText = "Lat/Lon Readout";
|
||||
this("Lat/Lon Readout");
|
||||
}
|
||||
|
||||
public LatLonReadoutAction(String actionText) {
|
||||
super(AS_CHECK_BOX);
|
||||
this.actionText = actionText;
|
||||
}
|
||||
|
||||
|
@ -83,8 +84,8 @@ public class LatLonReadoutAction extends AbstractRightClickAction {
|
|||
pane.getDescriptor().getResourceList().removeRsc(rsc);
|
||||
}
|
||||
List<ISamplingResource> samplers = pane.getDescriptor()
|
||||
.getResourceList()
|
||||
.getResourcesByTypeAsType(ISamplingResource.class);
|
||||
.getResourceList()
|
||||
.getResourcesByTypeAsType(ISamplingResource.class);
|
||||
for (ISamplingResource sampler : samplers) {
|
||||
if (sampled) {
|
||||
break;
|
||||
|
|
|
@ -53,10 +53,11 @@ public class SampleAction extends AbstractRightClickAction {
|
|||
private boolean sampling = false;
|
||||
|
||||
public SampleAction() {
|
||||
this.actionText = "Sample";
|
||||
this("Sample");
|
||||
}
|
||||
|
||||
public SampleAction(String actionText) {
|
||||
super(AS_CHECK_BOX);
|
||||
this.actionText = actionText;
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
|
||||
package com.raytheon.uf.edex.database.plugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.apache.commons.beanutils.ConstructorUtils;
|
||||
|
@ -68,6 +71,10 @@ public class PluginFactory {
|
|||
return instance;
|
||||
}
|
||||
|
||||
private Map<Class<PluginDao>, PluginDao> pluginDaoMap = new HashMap<Class<PluginDao>, PluginDao>();
|
||||
|
||||
private Object daoMapLock = new Object();
|
||||
|
||||
/**
|
||||
* Private constructor
|
||||
*
|
||||
|
@ -98,8 +105,22 @@ public class PluginFactory {
|
|||
if (props != null) {
|
||||
try {
|
||||
Class<PluginDao> clz = (Class<PluginDao>) props.getDao();
|
||||
return (PluginDao) ConstructorUtils.invokeConstructor(clz,
|
||||
pluginName);
|
||||
PluginDao dao = pluginDaoMap.get(clz);
|
||||
if (dao == null) {
|
||||
synchronized (daoMapLock) {
|
||||
// Create dao
|
||||
dao = (PluginDao) ConstructorUtils.invokeConstructor(
|
||||
clz, pluginName);
|
||||
// Copy dao mapping
|
||||
Map<Class<PluginDao>, PluginDao> pluginDaoMapCopy = new HashMap<Class<PluginDao>, PluginDao>(
|
||||
pluginDaoMap);
|
||||
// Add dao
|
||||
pluginDaoMapCopy.put(clz, dao);
|
||||
// Reset mapping
|
||||
pluginDaoMap = pluginDaoMapCopy;
|
||||
}
|
||||
}
|
||||
return dao;
|
||||
} catch (Exception e) {
|
||||
throw new PluginException("Error instantiating DAO for "
|
||||
+ pluginName + " plugin!", e);
|
||||
|
|
Loading…
Add table
Reference in a new issue