Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FELIX-2702] Start failing bundles when there's a change in bundles state #5

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public class DirectoryWatcher extends Thread implements BundleListener
// Represents artifacts that could not be installed
Map/* <File, Artifact> */ installationFailures = new HashMap/* <File, Artifact> */();

// flag (acces to which must be synchronized) that indicates wheter there's a change in state of system,
// which may result in an attempt to start the watched bundles
private Boolean stateChanged = Boolean.FALSE;

public DirectoryWatcher(Dictionary properties, BundleContext context)
{
super("fileinstall-" + getThreadName(properties));
Expand Down Expand Up @@ -335,7 +339,8 @@ public void run()

public void bundleChanged(BundleEvent bundleEvent)
{
if (bundleEvent.getType() == BundleEvent.UNINSTALLED)
int type = bundleEvent.getType();
if (type == BundleEvent.UNINSTALLED)
{
for (Iterator it = getArtifacts().iterator(); it.hasNext();)
{
Expand All @@ -349,6 +354,10 @@ public void bundleChanged(BundleEvent bundleEvent)
}
}
}
if (type == BundleEvent.INSTALLED || type == BundleEvent.RESOLVED || type == BundleEvent.UNINSTALLED ||
type == BundleEvent.UNRESOLVED || type == BundleEvent.UPDATED) {
setStateChanged(true);
}
}

private void process(Set files) throws InterruptedException
Expand Down Expand Up @@ -510,10 +519,12 @@ private void process(Set files) throws InterruptedException
{
// Refresh if any bundle got uninstalled or updated.
refresh((Bundle[]) toRefresh.toArray(new Bundle[toRefresh.size()]));
// set the state to reattempt starting managed bundles which aren't already STARTING or ACTIVE
setStateChanged(true);
}
}

if (startBundles)
if (startBundles && isStateChanged())
{
// Try to start all the bundles that are not persistently stopped
startAllBundles();
Expand All @@ -522,6 +533,9 @@ private void process(Set files) throws InterruptedException
delayedStart.removeAll(uninstalledBundles);
// Try to start newly installed bundles, or bundles which we missed on a previous round
startBundles(delayedStart);

// set the state as unchanged to not reattempt starting failed bundles
setStateChanged(false);
}
}

Expand Down Expand Up @@ -1490,5 +1504,17 @@ private void removeArtifact(File file)
currentManagedArtifacts.remove(file);
}
}

private void setStateChanged(boolean changed) {
synchronized (stateChanged) {
this.stateChanged = Boolean.valueOf(changed);
}
}

private boolean isStateChanged() {
synchronized (stateChanged) {
return stateChanged.booleanValue();
}
}

}