use of org.apache.karaf.features.RepositoryEvent in project karaf by apache.
the class FeaturesServiceMBeanImpl method getFeaturesListener.
public FeaturesListener getFeaturesListener() {
return new FeaturesListener() {
public void featureEvent(FeatureEvent event) {
if (!event.isReplay()) {
Notification notification = new Notification(FEATURE_EVENT_TYPE, objectName, sequenceNumber++);
notification.setUserData(new JmxFeatureEvent(event).asCompositeData());
sendNotification(notification);
}
}
public void repositoryEvent(RepositoryEvent event) {
if (!event.isReplay()) {
Notification notification = new Notification(REPOSITORY_EVENT_TYPE, objectName, sequenceNumber++);
notification.setUserData(new JmxRepositoryEvent(event).asCompositeData());
sendNotification(notification);
}
}
};
}
use of org.apache.karaf.features.RepositoryEvent in project karaf by apache.
the class FeaturesServiceImpl method removeRepository.
@Override
public void removeRepository(URI uri, boolean uninstall) throws Exception {
Repository repo = getRepository(uri);
if (repo == null) {
return;
}
Set<Repository> repos = getReposToRemove(repo);
Set<String> features = new HashSet<>();
for (Repository tranRepo : repos) {
features.addAll(getRequiredFeatureIds(tranRepo));
}
if (!features.isEmpty()) {
if (uninstall) {
uninstallFeatures(features, EnumSet.noneOf(Option.class));
} else {
throw new IllegalStateException("The following features are required from the repository: " + String.join(", ", features));
}
}
synchronized (lock) {
// Remove repo
if (!state.repositories.remove(uri.toString())) {
return;
}
// Clean cache
featureCache = null;
repositories.removeRepository(uri);
saveState();
}
callListeners(new RepositoryEvent(repo, RepositoryEvent.EventType.RepositoryRemoved, false));
}
use of org.apache.karaf.features.RepositoryEvent in project karaf by apache.
the class FeaturesServiceImpl method registerListener.
//
// Listeners support
//
@Override
public void registerListener(FeaturesListener listener) {
listeners.add(listener);
try {
Set<String> repositories = new TreeSet<>();
Map<String, Set<String>> installedFeatures = new TreeMap<>();
synchronized (lock) {
repositories.addAll(state.repositories);
installedFeatures.putAll(copy(state.installedFeatures));
}
for (String uri : repositories) {
Repository repository = new RepositoryImpl(URI.create(uri), cfg.blacklisted);
listener.repositoryEvent(new RepositoryEvent(repository, RepositoryEvent.EventType.RepositoryAdded, true));
}
for (Map.Entry<String, Set<String>> entry : installedFeatures.entrySet()) {
for (String id : entry.getValue()) {
Feature feature = org.apache.karaf.features.internal.model.Feature.valueOf(id);
listener.featureEvent(new FeatureEvent(FeatureEvent.EventType.FeatureInstalled, feature, entry.getKey(), true));
}
}
} catch (Exception e) {
LOGGER.error("Error notifying listener about the current state", e);
}
}
use of org.apache.karaf.features.RepositoryEvent in project karaf by apache.
the class FeaturesServiceImpl method addRepository.
@Override
public void addRepository(URI uri, boolean install) throws Exception {
Repository repository = repositories.loadAndValidate(uri);
synchronized (lock) {
repositories.addRepository(repository);
featureCache = null;
// Add repo
if (!state.repositories.add(uri.toString())) {
return;
}
saveState();
}
callListeners(new RepositoryEvent(repository, RepositoryEvent.EventType.RepositoryAdded, false));
// install the features in the repo
if (install) {
HashSet<String> features = new HashSet<>();
for (Feature feature : repository.getFeatures()) {
features.add(feature.getId());
}
installFeatures(features, EnumSet.noneOf(FeaturesService.Option.class));
}
}
use of org.apache.karaf.features.RepositoryEvent in project karaf by apache.
the class EventAdminListener method repositoryEvent.
public void repositoryEvent(RepositoryEvent event) {
try {
EventAdmin eventAdmin = tracker.getService();
if (eventAdmin == null) {
return;
}
Dictionary<String, Object> props = new Hashtable<>();
props.put(EventConstants.TYPE, event.getType());
props.put(EventConstants.EVENT, event);
props.put(EventConstants.TIMESTAMP, System.currentTimeMillis());
props.put(EventConstants.REPOSITORY_URI, event.getRepository().getURI().toString());
String topic;
switch(event.getType()) {
case RepositoryAdded:
topic = EventConstants.TOPIC_REPOSITORY_ADDED;
break;
case RepositoryRemoved:
topic = EventConstants.TOPIC_REPOSITORY_REMOVED;
break;
default:
throw new IllegalStateException("Unknown repository event type: " + event.getType());
}
eventAdmin.postEvent(new Event(topic, props));
} catch (IllegalStateException e) {
LOGGER.warn("Unable to post event to EventAdmin", e);
}
}
Aggregations