/** * Registers a component unless this registry is frozen. * This will succeed even if this component name and version is already registered. * * @throws IllegalStateException if this chain is frozen */ public void register(ComponentId id, COMPONENT component) { if (frozen) throw new IllegalStateException("Cannot modify a frozen component registry"); Map<String, Map<Version, COMPONENT>> componentVersionsByName = componentsByNameByNamespace.get(id.getNamespace()); if (componentVersionsByName == null) { componentVersionsByName = new LinkedHashMap<>(); componentsByNameByNamespace.put(id.getNamespace(), componentVersionsByName); } Map<Version, COMPONENT> componentVersions = componentVersionsByName.get(id.getName()); if (componentVersions == null) { componentVersions = new LinkedHashMap<>(); componentVersionsByName.put(id.getName(), componentVersions); } componentVersions.put(id.getVersion(), component); componentsById.put(id, component); }
/** * Unregisters a component unless this registry is frozen. * Note that the component is not deconstructed or otherwise modified in any way, this * is the responsiblity of the caller. * * @param id the id of the component to be unregistered * @return the component that was unregistered, or null if no such component was already registered */ public COMPONENT unregister(ComponentId id) { if (frozen) throw new IllegalStateException("Cannot modify a frozen component registry"); COMPONENT removed = componentsById.remove(id); if (removed != null) { //removed is non-null, so it must be present here as well: Map<String, Map<Version, COMPONENT>> componentVersionsByName = componentsByNameByNamespace.get(id.getNamespace()); Map<Version, COMPONENT> componentVersions = componentVersionsByName.get(id.getName()); COMPONENT removedInner = componentVersions.remove(id.getVersion()); assert (removedInner == removed); //clean up if (componentVersions.isEmpty()) { componentVersionsByName.remove(id.getName()); } if (componentVersionsByName.isEmpty()) { componentsByNameByNamespace.remove(id.getNamespace()); } } return removed; }
public ComponentId nestInNamespace(ComponentId namespace) { if (namespace == null) { return this; } else { ComponentId newNamespace = getNamespace() == null ? namespace : getNamespace().nestInNamespace(namespace); return new ComponentId(getName(), getVersion(), newNamespace); } }
public FilterBindingsProvider(ComponentId componentId, ServerConfig config, FilterChainRepository filterChainRepository, ComponentRegistry<SecurityRequestFilter> legacyRequestFilters) { ComponentId serverId = componentId.getNamespace(); try { FilterUtil.setupFilters( componentId, legacyRequestFilters, toFilterSpecs(config.filter()), filterChainRepository, requestFilters, responseFilters); } catch (Exception e) { throw new RuntimeException("Invalid config for http server " + serverId, e); } }
private void configureLegacyFilters(ComponentId id, ComponentRegistry<SecurityRequestFilter> legacyRequestFilters) { ComponentId serverName = id.getNamespace(); if (SEARCH_SERVER_COMPONENT_ID.equals(serverName) && !legacyRequestFilters.allComponents().isEmpty()) { requestFilters.bind("http://*/*", SecurityRequestFilterChain.newInstance(legacyRequestFilters.allComponents())); } }
public ComponentSpecification toSpecification() { if (isAnonymous()) throw new RuntimeException("Can't generate a specification for an anonymous component id."); return new ComponentSpecification(getName(), getVersion().toSpecification(), getNamespace()); }
/** * Checks if a componentId matches a given spec */ public boolean matches(ComponentId id) { boolean versionMatch = getVersionSpecification().matches(id.getVersion()); return getName().equals(id.getName()) && versionMatch && namespaceMatch(id.getNamespace()); }
private Query createFederationQuery(Query query, Query outgoing, Window window, long timeout, Target target) { ComponentId chainId = target.getChain().getId(); String sourceName = chainId.getName(); outgoing.properties().set(SOURCENAME, sourceName); String providerName = chainId.getName(); if (chainId.getNamespace() != null) providerName = chainId.getNamespace().getName(); outgoing.properties().set(PROVIDERNAME, providerName); outgoing.setTimeout(timeout); switch (propagateSourceProperties) { case ALL: propagatePerSourceQueryProperties(query, outgoing, window, sourceName, providerName, Query.nativeProperties); break; case OFFSET_HITS: propagatePerSourceQueryProperties(query, outgoing, window, sourceName, providerName, queryAndHits); break; } //TODO: FederationTarget //TODO: only for target produced by this, not others target.modifyTargetQuery(outgoing); return outgoing; }