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

Use repo event method #511

Merged
merged 2 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
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 @@ -186,13 +186,14 @@ public void initialize(RepositoryState state) {
*/
public void publishRepositoryReferences() {
IProvisioningEventBus bus = getProvisioningAgent().getService(IProvisioningEventBus.class);
if (bus == null)
if (bus == null) {
return;

}
List<IRepositoryReference> repositoriesSnapshot = createRepositoriesSnapshot();
for (IRepositoryReference reference : repositoriesSnapshot) {
bus.publishEvent(new RepositoryEvent(reference.getLocation(), reference.getType(),
RepositoryEvent.DISCOVERED, reference.isEnabled()));
RepositoryEvent event = RepositoryEvent.newDiscoveryEvent(reference.getLocation(), reference.getNickname(),
reference.getType(), reference.isEnabled());
bus.publishEvent(event);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,23 @@ private boolean addRepository(URI location, boolean isEnabled, boolean signalAdd
RepositoryInfo<T> info = new RepositoryInfo<>();
info.location = location;
info.isEnabled = isEnabled;
return addRepository(info, signalAdd);
}

private boolean addRepository(RepositoryInfo<T> info, boolean signalAdd) {

boolean added = true;
synchronized (repositoryLock) {
if (repositories == null)
restoreRepositories();
if (contains(location))
if (contains(info.location))
return false;
added = repositories.put(getKey(location), info) == null;
added = repositories.put(getKey(info.location), info) == null;
// save the given repository in the preferences.
remember(info, true);
}
if (added && signalAdd)
broadcastChangeEvent(location, getRepositoryType(), RepositoryEvent.ADDED, isEnabled);
broadcastChangeEvent(info.location, getRepositoryType(), RepositoryEvent.ADDED, info.isEnabled);
return added;
}

Expand Down Expand Up @@ -837,8 +842,13 @@ private boolean matchesFlags(RepositoryInfo<T> info, int flags) {
public void notify(EventObject o) {
if (o instanceof RepositoryEvent) {
RepositoryEvent event = (RepositoryEvent) o;
if (event.getKind() == RepositoryEvent.DISCOVERED && event.getRepositoryType() == getRepositoryType())
addRepository(event.getRepositoryLocation(), event.isRepositoryEnabled(), true);
if (event.getKind() == RepositoryEvent.DISCOVERED && event.getRepositoryType() == getRepositoryType()) {
RepositoryInfo<T> info = new RepositoryInfo<>();
info.location = event.getRepositoryLocation();
info.isEnabled = event.isRepositoryEnabled();
info.nickname = event.getRepositoryNickname();
addRepository(info, true);
}
}
}

Expand Down
Loading