use of io.fabric8.common.util.Filter in project fabric8 by jboss-fuse.
the class BaseRepository method findProviders.
@Override
public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) {
Map<Requirement, Collection<Capability>> result = new HashMap<Requirement, Collection<Capability>>();
for (Requirement requirement : requirements) {
CapabilitySet set = capSets.get(requirement.getNamespace());
if (set != null) {
SimpleFilter sf;
if (requirement instanceof RequirementImpl) {
sf = ((RequirementImpl) requirement).getFilter();
} else {
String filter = requirement.getDirectives().get(Constants.FILTER_DIRECTIVE);
sf = (filter != null) ? SimpleFilter.parse(filter) : new SimpleFilter(null, null, SimpleFilter.MATCH_ALL);
}
result.put(requirement, set.match(sf, true));
} else {
result.put(requirement, Collections.<Capability>emptyList());
}
}
return result;
}
use of io.fabric8.common.util.Filter in project fabric8 by jboss-fuse.
the class ProfileWatcherImpl method findProfileArifacts.
// For each profile and version return the map of bundle locations to parsers
private Map<ProfileVersionKey, Map<String, Parser>> findProfileArifacts() throws Exception {
Map<ProfileVersionKey, Map<String, Parser>> profileArtifacts = new HashMap<ProfileVersionKey, Map<String, Parser>>();
ProfileService profileService = fabricService.get().adapt(ProfileService.class);
DownloadManager downloadManager = DownloadManagers.createDownloadManager(fabricService.get(), executorService);
Container[] containers = fabricService.get().getContainers();
for (Container container : containers) {
Profile[] profiles = container.getProfiles();
boolean javaOrProcessContainer = ChildContainers.isJavaOrProcessContainer(fabricService.get(), container);
// TODO allow filter on a profile here?
for (Profile profile : profiles) {
Profile overlay = profileService.getOverlayProfile(profile);
ProfileVersionKey key = new ProfileVersionKey(profile);
// if (!profileArtifacts.containsKey(key)) {
Map<String, Parser> artifacts = null;
if (javaOrProcessContainer) {
List<Profile> singletonList = Collections.singletonList(profile);
artifacts = JavaContainers.getJavaContainerArtifacts(fabricService.get(), singletonList, executorService);
} else {
artifacts = AgentUtils.getProfileArtifacts(fabricService.get(), downloadManager, overlay);
}
if (artifacts != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Profile " + profile.getId() + " maps to artefacts: " + artifacts.keySet());
}
profileArtifacts.put(key, artifacts);
}
// }
}
}
return profileArtifacts;
}
use of io.fabric8.common.util.Filter in project fabric8 by jboss-fuse.
the class ProfileWatcherImpl method getCurrentActiveProfileVersions.
/**
* Gets the set of active profile ids and versions
*/
protected SortedSet<String> getCurrentActiveProfileVersions() {
SortedSet<String> answer = new TreeSet<String>();
Container[] containers = fabricService.get().getContainers();
for (Container container : containers) {
container.getProvisionList();
Profile[] profiles = container.getProfiles();
// TODO allow filter on a profile here?
for (Profile profile : profiles) {
String id = profile.getId();
String version = profile.getVersion();
answer.add(id + "/" + version);
}
}
return answer;
}
use of io.fabric8.common.util.Filter in project fabric8 by jboss-fuse.
the class Manager method removed.
@SuppressWarnings("unchecked")
public void removed(final Collection listenerInfos) {
for (ListenerInfo listenerInfo : (Collection<ListenerInfo>) listenerInfos) {
// Ignore our own listeners or those that don't have any filter
if (listenerInfo.getBundleContext() == bundleContext || listenerInfo.getFilter() == null) {
continue;
}
SimpleFilter exFilter = listeners.remove(listenerInfo);
// Iterate through known services and dereference them if needed
Set<EndpointDescription> matches = remoteEndpoints.match(exFilter);
for (EndpointDescription endpoint : matches) {
Map<Long, ImportRegistration> registrations = importedServices.get(endpoint);
if (registrations != null) {
ImportRegistration registration = registrations.get(listenerInfo.getBundleContext().getBundle().getBundleId());
if (registration != null) {
registration.removeReference(listenerInfo);
if (!registration.hasReferences()) {
registration.getImportedService().unregister();
registrations.remove(listenerInfo.getBundleContext().getBundle().getBundleId());
}
}
}
}
}
}
use of io.fabric8.common.util.Filter in project fabric8 by jboss-fuse.
the class Manager method added.
//
// ListenerHook
//
@SuppressWarnings("unchecked")
public void added(final Collection listenerInfos) {
for (ListenerInfo listenerInfo : (Collection<ListenerInfo>) listenerInfos) {
// Ignore our own listeners or those that don't have any filter
if (listenerInfo.getBundleContext() == bundleContext || listenerInfo.getFilter() == null) {
continue;
}
// Make sure we only import remote services
String filter = "(&" + listenerInfo.getFilter() + "(!(" + ENDPOINT_FRAMEWORK_UUID + "=" + this.uuid + ")))";
SimpleFilter exFilter = SimpleFilter.parse(filter);
listeners.put(listenerInfo, exFilter);
// Iterate through known services and import them if needed
Set<EndpointDescription> matches = remoteEndpoints.match(exFilter);
for (EndpointDescription endpoint : matches) {
doImportService(endpoint, listenerInfo);
}
}
}
Aggregations