Merge pull request #1437 from aschweer/DS-3246-cocoon-recycling-ds6

[DS-3246] Improve cleanup in recyclable components
This commit is contained in:
Tim Donohue
2016-06-29 14:40:21 -05:00
committed by GitHub
21 changed files with 77 additions and 63 deletions

View File

@@ -312,6 +312,8 @@ public class ItemExport extends AbstractDSpaceTransformer implements
this.errors = null;
this.message = null;
this.availableExports = null;
this.response = null;
this.request = null;
super.recycle();
}

View File

@@ -393,6 +393,7 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr
public void recycle()
{
this.validity = null;
this.availableExports = null;
super.recycle();
}

View File

@@ -91,8 +91,6 @@ public class ItemViewer extends AbstractDSpaceTransformer implements CacheablePr
private final String sfxFile = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("dspace.dir")
+ File.separator + "config" + File.separator + "sfx.xml";
private String sfxQuery = null;
private static final Logger log = LoggerFactory.getLogger(ItemViewer.class);
protected SFXFileReaderService sfxFileReaderService = SfxServiceFactory.getInstance().getSfxFileReaderService();
@@ -201,7 +199,7 @@ public class ItemViewer extends AbstractDSpaceTransformer implements CacheablePr
String sfxserverUrl = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("sfx.server.url");
if (sfxserverUrl != null && sfxserverUrl.length() > 0)
{
sfxQuery = "";
String sfxQuery = "";
// parse XML file -> XML document will be build
sfxQuery = sfxFileReaderService.loadSFXFile(sfxFile, item);

View File

@@ -71,15 +71,10 @@ public class BrowseFacet extends AbstractDSpaceTransformer implements CacheableP
public static final String OFFSET = "offset";
public static final String FACET_FIELD = "field";
private ConfigurationService config = null;
private SearchService searchService = null;
public BrowseFacet() {
config = DSpaceServicesFactory.getInstance().getConfigurationService();
searchService = DSpaceServicesFactory.getInstance().getServiceManager().getServiceByName(SearchService.class.getName(),SearchService.class);
}
/**
@@ -448,6 +443,7 @@ public class BrowseFacet extends AbstractDSpaceTransformer implements CacheableP
// Clear out our item's cache.
this.queryResults = null;
this.validity = null;
this.queryResults = null;
super.recycle();
}

View File

@@ -530,6 +530,7 @@ public class SearchFacetFilter extends AbstractDSpaceTransformer implements Cach
public void recycle() {
// Clear out our item's cache.
this.queryResults = null;
this.queryArgs = null;
this.validity = null;
super.recycle();
}

View File

@@ -79,12 +79,6 @@ public class SimpleSearch extends AbstractSearch implements CacheableProcessingC
private static final Message T_filter_notauthority = message("xmlui.Discovery.SimpleSearch.filter.notauthority");
private static final Message T_did_you_mean = message("xmlui.Discovery.SimpleSearch.did_you_mean");
private SearchService searchService = null;
public SimpleSearch() {
searchService = DSpaceServicesFactory.getInstance().getServiceManager().getServiceByName(SearchService.class.getName(),SearchService.class);
}
/**
* Add Page metadata.

View File

@@ -132,8 +132,9 @@ public class JSONDiscoverySearcher extends AbstractReader implements Recyclable
{
out.write(buffer, 0, length);
}
out.flush();
}
out.flush();
out.close();
}
/**
@@ -163,4 +164,12 @@ public class JSONDiscoverySearcher extends AbstractReader implements Recyclable
return dso;
}
@Override
public void recycle() {
response = null;
JSONStream = null;
super.recycle();
}
}

View File

@@ -283,4 +283,9 @@ public class PageNotFoundTransformer extends AbstractDSpaceTransformer implement
}
}
@Override
public void recycle() {
this.bodyEvent = null;
super.recycle();
}
}

View File

@@ -48,7 +48,6 @@ public class HandleResolverReader extends AbstractReader implements Recyclable {
public static final String CONTENTTYPE = "application/json; charset=utf-8";
private Request req;
private Response resp;
private String action;
private String handle;
@@ -60,7 +59,6 @@ public class HandleResolverReader extends AbstractReader implements Recyclable {
Parameters par) throws ProcessingException, SAXException,
IOException
{
this.req = ObjectModelHelper.getRequest(objectModel);
this.resp = ObjectModelHelper.getResponse(objectModel);
this.action = par.getParameter("action", "listprefixes");
this.handle = par.getParameter("handle", null);
@@ -153,13 +151,13 @@ public class HandleResolverReader extends AbstractReader implements Recyclable {
ByteArrayInputStream inputStream = new ByteArrayInputStream(jsonString.getBytes("UTF-8"));
IOUtils.copy(inputStream, out);
out.flush();
out.close();
} catch (Exception e) {
log.error("Error: ", e);
}
}
public void recycle() {
this.req = null;
this.resp = null;
this.action = null;
this.handle = null;

View File

@@ -247,6 +247,9 @@ public class CSVOutputter extends AbstractReader implements Recyclable
public void recycle() {
this.request = null;
this.response = null;
this.context = null;
this.writer = null;
super.recycle();
}
}

View File

@@ -36,13 +36,8 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr
private static final Message T_context_swordclient_head = message("xmlui.swordclient.Navigation.context_head");
private static final Message T_swordclient_copy = message("xmlui.swordclient.Navigation.context_copy");
/** Cached validity object */
private SourceValidity validity;
protected AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService();
/**
* Generate the unique caching key.
* This key must be unique inside the space of this component.

View File

@@ -51,10 +51,6 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr
protected AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService();
protected GroupService groupService = EPersonServiceFactory.getInstance().getGroupService();
/** exports available for download */
java.util.List<String> availableExports = null;
/**
* Generate the unique cache key.
*
@@ -81,15 +77,6 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr
return HashUtil.hash("anonymous");
}
if (availableExports != null && availableExports.size()>0) {
StringBuilder key = new StringBuilder(context.getCurrentUser().getEmail());
for(String fileName : availableExports){
key.append(":").append(fileName);
}
return HashUtil.hash(key.toString());
}
return HashUtil.hash(context.getCurrentUser().getEmail());
}

View File

@@ -80,4 +80,5 @@ public class AspectGenerator extends FileGenerator implements
// Use the standard FileGenerator to get the next Aspect.
super.setup(resolver, objectModel, aspectPath, par);
}
}

View File

@@ -55,14 +55,16 @@ public class AspectMatcher extends AbstractLogEnabled implements Matcher
String[] parts = uri.split("/");
int aspectID;
int aspectID = 0;
try
{
aspectID = Integer.valueOf(parts[0]);
if (parts[0].matches("\\d+")) {
aspectID = Integer.valueOf(parts[0]);
}
}
catch (NumberFormatException nfe)
{
aspectID = 0;
// ignore
}

View File

@@ -11,6 +11,7 @@ import java.io.*;
import java.net.URLEncoder;
import java.sql.SQLException;
import java.util.List;
import java.util.Date;
import java.util.Map;
import javax.mail.internet.MimeUtility;
@@ -163,8 +164,8 @@ public class BitstreamReader extends AbstractReader implements Recyclable
/** True if bitstream is readable by anonymous users */
protected boolean isAnonymouslyReadable;
/** Item containing the Bitstream */
private Item item = null;
/** The last modified date of the item containing the bitstream */
private Date itemLastModified = null;
/** True if user agent making this request was identified as spider. */
private boolean isSpider = false;
@@ -203,6 +204,8 @@ public class BitstreamReader extends AbstractReader implements Recyclable
this.request = ObjectModelHelper.getRequest(objectModel);
this.response = ObjectModelHelper.getResponse(objectModel);
Item item = null;
// Check to see if a context already exists or not. We may
// have been aggregated into an http request by the XSL document
// pulling in an XML-based bitstream. In this case the context has
@@ -264,6 +267,10 @@ public class BitstreamReader extends AbstractReader implements Recyclable
}
}
if (item != null) {
itemLastModified = item.getLastModified();
}
// if initial search was by sequence number and found nothing,
// then try to find bitstream by name (assuming we have a file name)
if((sequence > -1 && bitstream==null) && name!=null)
@@ -603,7 +610,7 @@ public class BitstreamReader extends AbstractReader implements Recyclable
{
// Check for if-modified-since header -- ONLY if not authenticated
long modSince = request.getDateHeader("If-Modified-Since");
if (modSince != -1 && item != null && item.getLastModified().getTime() < modSince)
if (modSince != -1 && itemLastModified != null && itemLastModified.getTime() < modSince)
{
// Item has not been modified since requested date,
// hence bitstream has not been, either; return 304
@@ -618,12 +625,11 @@ public class BitstreamReader extends AbstractReader implements Recyclable
// users in the cache for a response later to anonymous user.
try
{
if (item != null && (isSpider || ContextUtil.obtainContext(request).getCurrentUser() == null))
if (itemLastModified != null && (isSpider || ContextUtil.obtainContext(request).getCurrentUser() == null))
{
// TODO: Currently just borrow the date of the item, since
// we don't have last-mod dates for Bitstreams
response.setDateHeader("Last-Modified", item.getLastModified()
.getTime());
response.setDateHeader("Last-Modified", itemLastModified.getTime());
}
}
catch (SQLException e)
@@ -783,6 +789,10 @@ public class BitstreamReader extends AbstractReader implements Recyclable
this.bitstreamInputStream = null;
this.bitstreamSize = 0;
this.bitstreamMimeType = null;
this.bitstreamName = null;
this.itemLastModified = null;
this.tempFile = null;
super.recycle();
}

View File

@@ -246,6 +246,7 @@ public class ItemExportDownloadReader extends AbstractReader implements Recyclab
}
out.flush();
}
out.close();
}
/**
@@ -264,6 +265,8 @@ public class ItemExportDownloadReader extends AbstractReader implements Recyclab
this.request = null;
this.compressedExportInputStream = null;
this.compressedExportSize = 0;
this.compressedExportName = null;
super.recycle();
}

View File

@@ -44,6 +44,7 @@ public class JSONControlledVocabularyReader extends AbstractReader {
IOUtils.copy(inputStream, out);
out.flush();
}
out.close();
} catch (Exception e) {
log.error("Error while generating controlled vocabulary json, vocabulary identifier: " + vocabularyIdentifier, e);
}

View File

@@ -209,7 +209,10 @@ public class MetadataExportReader extends AbstractReader implements Recyclable
public void recycle() {
this.response = null;
this.request = null;
this.exporter = null;
this.filename = null;
this.csv = null;
super.recycle();
}

View File

@@ -132,6 +132,8 @@ public class SitemapReader extends AbstractReader implements Recyclable
String fileStem = (param == null ? "sitemap_index" : "sitemap" + param);
sendFile(fileStem + ext, this.forSitemapsOrg);
out.close();
}
/**
@@ -206,5 +208,6 @@ public class SitemapReader extends AbstractReader implements Recyclable
this.request = null;
this.sitemapMimeType = null;
this.forSitemapsOrg = false;
super.recycle();
}
}

View File

@@ -45,6 +45,6 @@ public class JQueryLoaderReader extends AbstractReader {
out.write(buffer, 0, length);
}
out.flush();
out.close();
}
}

View File

@@ -45,7 +45,7 @@ public class RequestUtils {
int i = -1;
// Iterate through the values in the form.
valueLoop: while (1 == 1)
valueLoop: while (true)
{
i++;
String value = null;
@@ -117,7 +117,7 @@ public class RequestUtils {
int i = -1;
// Iterate through the values in the form.
valueLoop: while (1 == 1)
valueLoop: while (true)
{
i++;
String value = null;
@@ -181,16 +181,18 @@ public class RequestUtils {
public static int getIntParameter(Request request, String param)
{
String val = request.getParameter(param);
try
{
return Integer.parseInt(val.trim());
}
catch (Exception e)
{
// Problem with parameter
return -1;
}
if (val != null)
{
try
{
return Integer.parseInt(val.trim());
}
catch (Exception e)
{
// Problem with parameter -- ignore
}
}
return -1;
}