You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wink.apache.org by bl...@apache.org on 2009/09/18 23:39:03 UTC
svn commit: r816792 -
/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java
Author: bluk
Date: Fri Sep 18 21:39:03 2009
New Revision: 816792
URL: http://svn.apache.org/viewvc?rev=816792&view=rev
Log:
ResourceRegistry thread safety
Change ResourceRegistry to only sort the
collection when a resource has been added
and while protected under a writers lock
Modified:
incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java
Modified: incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java?rev=816792&r1=816791&r2=816792&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java (original)
+++ incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java Fri Sep 18 21:39:03 2009
@@ -65,7 +65,6 @@
.getLogger(ResourceRegistry.class);
private List<ResourceRecord> rootResources;
- private boolean dirty;
private ResourceRecordFactory resourceRecordsFactory;
@@ -80,7 +79,6 @@
ApplicationValidator applicationValidator) {
this.applicationValidator = applicationValidator;
rootResources = new LinkedList<ResourceRecord>();
- dirty = false;
resourceRecordsFactory = new ResourceRecordFactory(factoryRegistry);
ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
readersLock = readWriteLock.readLock();
@@ -127,7 +125,7 @@
ResourceRecord record = getRecord(instance);
record.setPriority(priority);
rootResources.add(record);
- dirty = true;
+ assertSorted();
} finally {
writersLock.unlock();
}
@@ -151,7 +149,7 @@
ResourceRecord record = getRecord(clazz);
record.setPriority(priority);
rootResources.add(record);
- dirty = true;
+ assertSorted();
} finally {
writersLock.unlock();
}
@@ -198,7 +196,6 @@
public List<ResourceRecord> getRecords() {
readersLock.lock();
try {
- assertSorted();
return Collections.unmodifiableList(rootResources);
} finally {
readersLock.unlock();
@@ -232,15 +229,12 @@
* Verify that the root resources list is sorted
*/
private void assertSorted() {
- if (dirty) {
- // we use the reverse-order comparator because the sort method
- // will sort the elements in ascending order, but we want
- // them sorted in descending order
- Collections.sort(rootResources, Collections.reverseOrder());
- uriToResourceCache.get(Boolean.TRUE).clear();
- uriToResourceCache.get(Boolean.FALSE).clear();
- dirty = false;
- }
+ // we use the reverse-order comparator because the sort method
+ // will sort the elements in ascending order, but we want
+ // them sorted in descending order
+ Collections.sort(rootResources, Collections.reverseOrder());
+ uriToResourceCache.get(Boolean.TRUE).clear();
+ uriToResourceCache.get(Boolean.FALSE).clear();
}
/**
@@ -266,7 +260,6 @@
readersLock.lock();
try {
- assertSorted();
List<ResourceRecord> previousMatched = null;
/*
* the previous matches are cached so if a previous URI used is