Skip to content

Commit

Permalink
feat(platform): add wildcard support for unregistering capabilities a…
Browse files Browse the repository at this point in the history
…nd intentions

closes #61
  • Loading branch information
mofogasy committed Mar 16, 2021
1 parent 26bb891 commit ee03c3c
Show file tree
Hide file tree
Showing 8 changed files with 1,109 additions and 952 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { BrokerGateway } from './broker-gateway';
import { MessagingChannel } from '../../ɵmessaging.model';
import { filterByChannel, pluckMessage } from '../../operators';
import { filter } from 'rxjs/operators';
import { matchesIntentQualifier } from '../../qualifier-tester';
import { matchesWildcardQualifier } from '../../qualifier-tester';
import { IntentClient, IntentOptions, IntentSelector } from './intent-client';
import { Beans } from '@scion/toolkit/bean-manager';
import { MessageHandler } from './message-handler';
Expand Down Expand Up @@ -53,7 +53,7 @@ export class ɵIntentClient implements IntentClient { // tslint:disable-line:cla
filterByChannel<IntentMessage<T>>(MessagingChannel.Intent),
pluckMessage(),
filter(message => !selector || !selector.type || selector.type === message.intent.type),
filter(message => !selector || !selector.qualifier || matchesIntentQualifier(selector.qualifier, message.intent.qualifier)),
filter(message => !selector || !selector.qualifier || matchesWildcardQualifier(selector.qualifier, message.intent.qualifier)),
);
}

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* SPDX-License-Identifier: EPL-2.0
*/

import { isEqualQualifier, matchesWildcardQualifier, QualifierMatcher } from '../../qualifier-tester';
import { invertQualifiers, matchesWildcardQualifier, matchesWildcardQualifiersMutually, QualifierMatcher } from '../../qualifier-tester';
import { Observable, Subject } from 'rxjs';
import { Arrays, Maps } from '@scion/toolkit/util';
import { Qualifier } from '../../platform.model';
Expand Down Expand Up @@ -42,7 +42,8 @@ export class ManifestObjectStore<T extends ManifestObject> {
* Wildcards in the qualifier criterion, if any, are not interpreted as wildcards, but as exact values instead.
*/
public remove(filter: ManifestObjectFilter): void {
const objectsToRemove = this.find(filter, isEqualQualifier);
// Qualifiers are inverted in order to support wildcards in the qualifier filter.
const objectsToRemove = this.find(filter, invertQualifiers(matchesWildcardQualifier));
this._remove(objectsToRemove);
}

Expand All @@ -51,9 +52,9 @@ export class ManifestObjectStore<T extends ManifestObject> {
*
* @param filter - Control which manifest objects to return.
* Specified filter criteria are "AND"ed together. If no filter criterion is specified, no filtering takes place.
* @param qualifierMatcher - Control how to match qualifiers if specified in the filter. If not specified, {@link matchesWildcardQualifier} is used.
* @param qualifierMatcher - Control how to match qualifiers if specified in the filter. If not specified, {@link matchesWildcardQualifiersMutually} is used.
*/
public find(filter: ManifestObjectFilter, qualifierMatcher: QualifierMatcher = matchesWildcardQualifier): T[] {
public find(filter: ManifestObjectFilter, qualifierMatcher: QualifierMatcher = matchesWildcardQualifiersMutually): T[] {
const filterById = filter.id !== undefined;
const filterByType = filter.type !== undefined;
const filterByApp = filter.appSymbolicName !== undefined;
Expand Down Expand Up @@ -108,7 +109,8 @@ export interface ManifestObject {
/**
* Allows filtering manifest objects like capabilities or intentions.
*
* All specified filter criteria are "AND"ed together. If no filter criterion is specified, no filtering takes place.
* All specified filter criteria are "AND"ed together. Unspecified filter criteria are ignored.
* If no filter criterion is specified, no filtering takes place, thus all available objects are returned.
*
* @category Manifest
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ApplicationRegistry } from '../application-registry';
import { runSafe } from '../../safe-runner';
import { filterArray } from '@scion/toolkit/operators';
import { ManifestRegistry } from './manifest-registry';
import { matchesIntentQualifier, matchesWildcardQualifier } from '../../qualifier-tester';
import { matchesWildcardQualifier } from '../../qualifier-tester';
import { Beans, PreDestroy } from '@scion/toolkit/bean-manager';
import { stringifyError } from '../../error.util';

Expand Down Expand Up @@ -50,7 +50,7 @@ export class ɵManifestRegistry implements ManifestRegistry, PreDestroy { // tsl
*/
public resolveCapabilitiesByIntent(intent: Intent, appSymbolicName: string): Capability[] {
const filter: ManifestObjectFilter = {type: intent.type, qualifier: intent.qualifier || {}};
return this._capabilityStore.find(filter, matchesIntentQualifier)
return this._capabilityStore.find(filter, matchesWildcardQualifier)
.filter(capability => this.isCapabilityVisibleToMicroApplication(capability, appSymbolicName));
}

Expand All @@ -61,8 +61,8 @@ export class ɵManifestRegistry implements ManifestRegistry, PreDestroy { // tsl
const filter: ManifestObjectFilter = {appSymbolicName, type: intent.type, qualifier: intent.qualifier || {}};
return (
Beans.get(ApplicationRegistry).isIntentionCheckDisabled(appSymbolicName) ||
this._intentionStore.find(filter, matchesIntentQualifier).length > 0 ||
this._capabilityStore.find(filter, matchesIntentQualifier).length > 0
this._intentionStore.find(filter, matchesWildcardQualifier).length > 0 ||
this._capabilityStore.find(filter, matchesWildcardQualifier).length > 0
);
}

Expand All @@ -74,7 +74,7 @@ export class ɵManifestRegistry implements ManifestRegistry, PreDestroy { // tsl
return (
Beans.get(ApplicationRegistry).isIntentionCheckDisabled(appSymbolicName) ||
capability.metadata.appSymbolicName === appSymbolicName ||
this._intentionStore.find({appSymbolicName, type: capability.type, qualifier: capability.qualifier}, matchesWildcardQualifier).length > 0
this._intentionStore.find({appSymbolicName, type: capability.type, qualifier: capability.qualifier}).length > 0
);
}

Expand Down Expand Up @@ -226,7 +226,7 @@ export class ɵManifestRegistry implements ManifestRegistry, PreDestroy { // tsl
// The queried capabilities may change on both, capability or intention change, because the computation
// of visible and qualified capabilities depends on registered capabilities and manifested intentions.
const registryChange$ = merge(this._capabilityStore.change$, this._intentionStore.change$);
const finder$ = defer(() => of(this._capabilityStore.find(lookupFilter, matchesWildcardQualifier)));
const finder$ = defer(() => of(this._capabilityStore.find(lookupFilter)));
return finder$
.pipe(
expand(() => registryChange$.pipe(take(1), mergeMapTo(finder$))),
Expand All @@ -248,7 +248,7 @@ export class ɵManifestRegistry implements ManifestRegistry, PreDestroy { // tsl
const replyTo = request.headers.get(MessageHeaders.ReplyTo);
const lookupFilter = request.body || {};

const finder$ = defer(() => of(this._intentionStore.find(lookupFilter, matchesWildcardQualifier)));
const finder$ = defer(() => of(this._intentionStore.find(lookupFilter)));
return finder$
.pipe(
expand(() => this._intentionStore.change$.pipe(take(1), mergeMapTo(finder$))),
Expand Down
Loading

0 comments on commit ee03c3c

Please sign in to comment.