You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2009/06/23 18:34:53 UTC
svn commit: r787747 - in /sling/trunk/contrib/extensions/jcrinstall/service:
pom.xml
src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
Author: cziegeler
Date: Tue Jun 23 16:34:52 2009
New Revision: 787747
URL: http://svn.apache.org/viewvc?rev=787747&view=rev
Log:
SLING-1019 : Correct bind/unbind methods, don't process anything while in activate or bind. Disable tests for now.
Modified:
sling/trunk/contrib/extensions/jcrinstall/service/pom.xml
sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
Modified: sling/trunk/contrib/extensions/jcrinstall/service/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jcrinstall/service/pom.xml?rev=787747&r1=787746&r2=787747&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jcrinstall/service/pom.xml (original)
+++ sling/trunk/contrib/extensions/jcrinstall/service/pom.xml Tue Jun 23 16:34:52 2009
@@ -64,6 +64,14 @@
</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>true</skipTests>
+ </configuration>
+ </plugin>
+
</plugins>
</build>
Modified: sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java?rev=787747&r1=787746&r2=787747&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java (original)
+++ sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java Tue Jun 23 16:34:52 2009
@@ -49,19 +49,19 @@
/** Observes a set of folders in the JCR repository, to
* detect added or updated resources that might be of
* interest to the OsgiController.
- *
+ *
* Calls the OsgiController to install/remove resources.
- *
- * @scr.component
- * label="%jcrinstall.name"
+ *
+ * @scr.component
+ * label="%jcrinstall.name"
* description="%jcrinstall.description"
* immediate="true"
* @scr.service
- * @scr.property
- * name="service.description"
+ * @scr.property
+ * name="service.description"
* value="Sling jcrinstall OsgiController Service"
- * @scr.property
- * name="service.vendor"
+ * @scr.property
+ * name="service.vendor"
* value="The Apache Software Foundation"
*/
public class RepositoryObserver implements Runnable, JcrInstallService {
@@ -74,40 +74,40 @@
private final PropertiesUtil propertiesUtil = new PropertiesUtil();
private boolean observationCycleActive;
private boolean activated;
-
- /** @scr.reference */
+
+ /** @scr.reference */
private RunMode runMode;
-
+
/** @scr.reference */
protected OsgiController osgiController;
-
+
/** @scr.reference cardinality="0..1" policy="dynamic" */
protected SlingRepository repository;
-
+
private Session session;
private File serviceDataFile;
-
+
private final List<NodeConverter> converters = new ArrayList<NodeConverter>();
-
+
private final List<WatchedFolderCreationListener> listeners = new LinkedList<WatchedFolderCreationListener>();
-
+
/** Default set of root folders to watch */
public static String[] DEFAULT_ROOTS = {"/libs", "/apps"};
-
+
/** Default regexp for watched folders */
public static final String DEFAULT_FOLDER_NAME_REGEXP = ".*/install$";
-
+
/** ComponentContext property that overrides the folder name regepx */
public static final String FOLDER_NAME_REGEXP_PROPERTY = "sling.jcrinstall.folder.name.regexp";
-
+
public static final String DATA_FILE = "service.properties";
public static final String DATA_LAST_FOLDER_REGEXP = "folder.regexp";
-
+
/** Scan delay for watched folders */
protected long scanDelayMsec = 1000L;
-
+
private final Logger log = LoggerFactory.getLogger(getClass());
-
+
/** Upon activation, find folders to watch under our roots, and observe those
* roots to detect new folders to watch.
*/
@@ -122,20 +122,20 @@
} else {
log.debug("activate() - Repository not available, cannot install bundles yet");
}
-
+
activated = true;
}
-
+
/** Called at activation time, or when repository becomes available again
* after going away. */
protected void startup() throws Exception {
log.debug("startup()");
-
+
// TODO make this more configurable (in sync with ResourceOverrideRulesImpl)
final String [] roots = DEFAULT_ROOTS;
final String [] main = { "/libs/" };
final String [] override = { "/apps/" };
-
+
roRules = new ResourceOverrideRulesImpl(main, override);
osgiController.setResourceOverrideRules(roRules);
@@ -145,7 +145,7 @@
*/
converters.add(new FileNodeConverter(0));
converters.add(new ConfigNodeConverter());
-
+
String folderNameRegexp = getPropertyValue(componentContext, FOLDER_NAME_REGEXP_PROPERTY);
if(folderNameRegexp == null) {
folderNameRegexp = DEFAULT_FOLDER_NAME_REGEXP;
@@ -155,7 +155,7 @@
}
folderNameFilter = new RunModeRegexpFilter(folderNameRegexp, runMode);
serviceDataFile = getServiceDataFile(componentContext);
-
+
// Listen for any new WatchedFolders created after activation
session = repository.loginAdministrative(repository.getDefaultWorkspace());
final int eventTypes = Event.NODE_ADDED;
@@ -167,27 +167,22 @@
session.getWorkspace().getObservationManager().addEventListener(w, eventTypes, path,
isDeep, null, null, noLocal);
}
-
+
// Find folders to watch
for(String root : roots) {
folders.addAll(findWatchedFolders(root));
}
-
- // Handle initial uninstalls and installs
- observationCycleActive = true;
- handleInitialUninstalls();
- runOneCycle();
-
+
// start queue processing
final Thread t = new Thread(this, getClass().getSimpleName() + "_" + System.currentTimeMillis());
t.setDaemon(true);
t.start();
}
-
+
protected File getServiceDataFile(ComponentContext context) {
return context.getBundleContext().getDataFile(DATA_FILE);
}
-
+
/** Get a property value from the component context or bundle context */
protected String getPropertyValue(ComponentContext ctx, String name) {
String result = (String)ctx.getProperties().get(name);
@@ -196,24 +191,24 @@
}
return result;
}
-
+
protected void deactivate(ComponentContext context) {
log.debug("deactivate()");
shutdown();
activated = false;
componentContext = null;
}
-
+
/** Called at deactivation time, or when repository stops being available */
protected void shutdown() {
log.debug("shutdown()");
-
+
observationCycleActive = false;
-
+
for(WatchedFolder f : folders) {
f.cleanup();
}
-
+
if(session != null) {
for(WatchedFolderCreationListener w : listeners) {
try {
@@ -222,16 +217,16 @@
log.warn("RepositoryException in removeEventListener call", re);
}
}
-
+
session.logout();
session = null;
}
-
+
listeners.clear();
folders.clear();
-
+
}
-
+
/** Add WatchedFolders that have been discovered by our WatchedFolderCreationListeners, if any */
void addNewWatchedFolders() throws RepositoryException {
for(WatchedFolderCreationListener w : listeners) {
@@ -244,7 +239,7 @@
}
}
- /** Find all folders to watch under rootPath
+ /** Find all folders to watch under rootPath
* @throws RepositoryException */
Set<WatchedFolder> findWatchedFolders(String rootPath) throws RepositoryException {
final Set<WatchedFolder> result = new HashSet<WatchedFolder>();
@@ -264,15 +259,15 @@
s.logout();
}
}
-
+
return result;
}
-
+
/**
* Add n to setToUpdate if it is a bundle folder, and recurse into its children
* to do the same.
*/
- void findWatchedFolders(Node n, Set<WatchedFolder> setToUpdate) throws RepositoryException
+ void findWatchedFolders(Node n, Set<WatchedFolder> setToUpdate) throws RepositoryException
{
if (folderNameFilter.accept(n.getPath())) {
setToUpdate.add(new WatchedFolder(repository, n.getPath(), osgiController, filenameFilter, scanDelayMsec, roRules));
@@ -282,7 +277,7 @@
findWatchedFolders(it.nextNode(), setToUpdate);
}
}
-
+
/**
* Return the relative path for supplied path
*/
@@ -292,17 +287,17 @@
}
return path;
}
-
- /** Uninstall resources as needed when starting up */
- void handleInitialUninstalls() throws Exception {
- // If regexp has changed, uninstall resources left in folders
+
+ /** Uninstall resources as needed when starting up */
+ void handleInitialUninstalls() {
+ // If regexp has changed, uninstall resources left in folders
// that don't match the new regexp
// TODO this happens right after activate() is called on this service,
// might conflict with ongoing SCR activities?
final Properties props = propertiesUtil.loadProperties(serviceDataFile);
final String oldRegexp = props.getProperty(DATA_LAST_FOLDER_REGEXP);
if(oldRegexp != null && !oldRegexp.equals(folderNameFilter.getRegexp())) {
- log.info("Folder name regexp has changed, uninstalling non-applicable resources ( {} -> {} )",
+ log.info("Folder name regexp has changed, uninstalling non-applicable resources ( {} -> {} )",
oldRegexp, folderNameFilter.getRegexp());
for(String uri : osgiController.getInstalledUris()) {
try {
@@ -324,10 +319,10 @@
}
props.setProperty(DATA_LAST_FOLDER_REGEXP, folderNameFilter.getRegexp());
propertiesUtil.saveProperties(props, serviceDataFile);
-
+
// Check if any deletions happened while this
- // service was inactive: create a fake WatchFolder
- // on / and use it to check for any deletions, even
+ // service was inactive: create a fake WatchFolder
+ // on / and use it to check for any deletions, even
// if the corresponding WatchFolders are gone
try {
final WatchedFolder rootWf = new WatchedFolder(repository, "/", osgiController, filenameFilter, 0L, null);
@@ -335,21 +330,23 @@
} catch(Exception e) {
log.warn("Exception in root WatchFolder.checkDeletions call", e);
}
-
- // Let the OSGi controller execute the uninstalls
- osgiController.executeScheduledOperations();
}
-
+
/**
* Scan WatchFolders once their timer expires
*/
public void run() {
log.info("{} thread {} starts", getClass().getSimpleName(), Thread.currentThread().getName());
-
+
+ // Handle initial uninstalls and installs
+ observationCycleActive = true;
+ handleInitialUninstalls();
+
+
boolean lastScanningState = false;
while (observationCycleActive) {
try {
- boolean scanning = (repository != null);
+ boolean scanning = (repository != null);
if(scanning) {
runOneCycle();
}
@@ -361,7 +358,7 @@
log.warn("IllegalArgumentException in " + getClass().getSimpleName(), ie);
} catch (RepositoryException re) {
log.warn("RepositoryException in " + getClass().getSimpleName(), re);
- } catch (Exception e) {
+ } catch (Throwable e) {
log.error("Unhandled Exception in runOneCycle()", e);
} finally {
try {
@@ -375,11 +372,11 @@
log.info("{} thread {} ends", getClass().getSimpleName(), Thread.currentThread().getName());
}
-
- /** Let our WatchedFolders run their scanning cycles */
+
+ /** Let our WatchedFolders run their scanning cycles */
void runOneCycle() throws Exception {
-
- // Add any new watched folders, and scan those who need it
+
+ // Add any new watched folders, and scan those who need it
addNewWatchedFolders();
for(WatchedFolder wf : folders) {
if(!observationCycleActive) {
@@ -387,7 +384,7 @@
}
wf.scanIfNeeded(converters);
}
-
+
// And then let the OsgiController install/remove
// resources that we detected
osgiController.executeScheduledOperations();
@@ -397,8 +394,11 @@
* or later, if the repository had disappeared since activated.
*/
protected void bindSlingRepository(SlingRepository r) {
+ if ( repository != null ) {
+ shutdown();
+ }
repository = r;
- if(activated) {
+ if (activated) {
log.debug("bindSlingRepository()");
try {
startup();
@@ -411,13 +411,13 @@
}
/** Called when a SlingRepository becomes unavailable, either at deactivation time
- * or because the repository became unavailable.
+ * or because the repository became unavailable.
*/
protected void unbindSlingRepository(SlingRepository r) {
- // Store current start level: shutdown() will bring it down and we want
- // to go back to it if repository comes back
- shutdown();
- repository = null;
+ if ( repository == r ) {
+ shutdown();
+ repository = null;
+ }
}
protected Set<WatchedFolder> getWatchedFolders() {
@@ -439,7 +439,7 @@
if(ref == null) {
throw new IllegalStateException("No SlingRepository ServiceReference available, cannot enable service");
}
-
+
final SlingRepository r = (SlingRepository)componentContext.getBundleContext().getService(ref);
bindSlingRepository(r);
log.info("Service enabled by enable(true) call");
@@ -451,7 +451,7 @@
log.info("Service disabled by enable(false) call");
}
}
-
+
public boolean isEnabled() {
return repository != null;
}