Skip to content

Commit feb5e7d

Browse files
committed
Updates
1 parent 6381861 commit feb5e7d

File tree

8 files changed

+156
-75
lines changed

8 files changed

+156
-75
lines changed

TODO.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
Major Architectual
22
Hooks
3-
Namespaces/Extensions
43
Lifetime
54

65
Cleanup

modules/packed/src/main/java/app/packed/application/ApplicationMirror.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ public OperationMirror.OfStream<OperationMirror> operations() {
212212
return OperationMirror.OfStream.of(beans().flatMap(BeanMirror::operations));
213213
}
214214

215+
public <O extends OverviewMirror<?>> O extensionOverview(Class<? extends Extension<?>> extensionType, Class<O> type) {
216+
return PackedOverviewHandle.ofExtension(application, extensionType, type);
217+
}
218+
215219
public <O extends OverviewMirror<?>> O overview(Class<O> type) {
216220
return PackedOverviewHandle.ofApplication(application, type);
217221
}

modules/packed/src/main/java/app/packed/extension/Extension.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import app.packed.container.ContainerHandle;
3434
import app.packed.extension.Extension.ExtensionProperty;
3535
import app.packed.extension.ExtensionPoint.ExtensionPointHandle;
36-
import app.packed.namespace.OverviewMirror;
3736
import app.packed.service.ProvidableBeanConfiguration;
3837
import app.packed.util.TreeView;
3938
import internal.app.packed.container.ContainerSetup;
@@ -291,10 +290,6 @@ protected ExtensionMirror<E> newExtensionMirror() {
291290
throw new InternalExtensionException("This method must be overridden by " + extension.extensionType);
292291
}
293292

294-
protected OverviewMirror<E> newOverviewMirror() {
295-
throw new InternalExtensionException("This method must be overridden by " + extension.extensionType);
296-
}
297-
298293
/**
299294
* Returns a new extension point for the extension
300295
* <p>

modules/packed/src/main/java/app/packed/namespace/NamespaceMirror.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import app.packed.util.TreeView;
3434
import internal.app.packed.bean.introspection.IntrospectorOnAutoService;
3535
import internal.app.packed.extension.base.BaseExtensionBeanIntrospector;
36+
import internal.app.packed.component.PackedOverviewHandle;
3637
import internal.app.packed.namespace.NamespaceSetup;
3738
import internal.app.packed.util.PackedTreeView;
3839
import internal.app.packed.util.accesshelper.AccessHelper;
@@ -106,6 +107,10 @@ public ComponentPath componentPath() {
106107
public Set<String> componentTags() {
107108
throw new UnsupportedOperationException();
108109
}
110+
111+
public <O extends OverviewMirror<?>> O overview(Class<O> type) {
112+
return PackedOverviewHandle.ofNamespace(namespace, type);
113+
}
109114
}
110115

111116
final class NamespaceMirrorBeanIntrospector extends BaseExtensionBeanIntrospector {

modules/packed/src/main/java/app/packed/namespace/Overview.md

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,3 @@
1-
----
2-
Namespace
3-
NamespaceNode
4-
5-
6-
------
7-
Namespace
8-
Set<ResourceKey> keys();
9-
Set<ResourcePath> resourcePaths();
10-
11-
NamespaceResource
12-
ResourceKey
13-
ComponentPath
14-
15-
We need namespace because stuff with ids is shared across containers.
16-
Or for example multiple databases.
17-
18-
Service.Namespace: ServiceNamespace
19-
Service: ServiceNamespace/Key
20-
21-
// BeanNamespace -> all beans within a container have a unique name
22-
23-
/// Extra namespaces
24-
25-
// Tror ikke man som udgangspunkt kan lave namespaces lazily.
26-
// Altsaa man kan jo sige main er lazy. fx for eventbus
27-
28-
A namespace has an id, a namespacetype, a name type, and an extend.
29-
30-
// Namespace:Kind:Container:id
31-
32-
// Namespace:Service:/:main
33-
34-
35-
HVORFOR fungere namespace bridge ikke
36-
37-
// Den fungere ikke super godt. Problemet er at det er svaert at faa fat i namespace handles.
38-
// Med mindre vi laver en masse generics magi.
39-
// Meget lettere at lave sine egen wirelets.
40-
// Og metoder på NamespaceConfiguration
411

422

433
Usecases

modules/packed/src/main/java/app/packed/namespace/OverviewHandle.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,32 @@
2020
import internal.app.packed.component.PackedOverviewHandle;
2121

2222
/**
23+
* A handle that provides access to operations within a particular scope (such as an application or namespace) for a
24+
* specific extension type. Overview handles are the backing implementation for {@link OverviewMirror} subclasses.
25+
* <p>
26+
* This interface is sealed and cannot be implemented directly by user code.
2327
*
28+
* @param <E>
29+
* the type of extension whose operations are accessible through this handle
30+
*
31+
* @see OverviewMirror
2432
*/
2533
public sealed interface OverviewHandle<E extends Extension<E>> permits PackedOverviewHandle {
2634

35+
/**
36+
* {@return a stream of all operations within the scope of this handle that were installed by the extension type {@code E}}
37+
*/
2738
OperationMirror.OfStream<OperationMirror> operations();
2839

29-
<T extends OperationMirror> OperationMirror.OfStream<T> operations(Class<T> operations);
30-
31-
// isOverviewForWholeApplication
32-
// isOverviewForExtension
33-
// IsOverviewForNamespace
34-
// IsOverviewForSingleContainer <--- (not sure if we want to implement
40+
/**
41+
* Returns a stream of all operations within the scope of this handle that were installed by the extension type
42+
* {@code E} and are of the specified mirror type.
43+
*
44+
* @param <T>
45+
* the type of operation mirror
46+
* @param operationType
47+
* the class of the operation mirror type to filter by
48+
* @return a stream of matching operations
49+
*/
50+
<T extends OperationMirror> OperationMirror.OfStream<T> operations(Class<T> operationType);
3551
}

modules/packed/src/main/java/app/packed/namespace/OverviewMirror.java

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,58 @@
2222
import internal.app.packed.component.PackedOverviewHandle;
2323

2424
/**
25+
* A mirror that provides a read-only, extension-scoped view of operations within a particular scope such as an
26+
* application, namespace, or container.
27+
* <p>
28+
* Subclasses are defined by extension authors to expose domain-specific queries over the operations that their
29+
* extension installs. For example, a {@code JobOverviewMirror} might expose methods like {@code daemons()} or
30+
* {@code jobs()} that filter and return extension-specific operation mirror types.
31+
* <p>
32+
* An overview mirror is obtained via {@link app.packed.application.ApplicationMirror#overview(Class)}.
33+
* <p>
34+
* Subclasses must declare exactly one constructor taking an {@link OverviewHandle} parameter.
2535
*
36+
* @param <E>
37+
* the type of extension whose operations this overview provides access to
38+
*
39+
* @see OverviewHandle
40+
* @see app.packed.application.ApplicationMirror#overview(Class)
2641
*/
27-
// I don't think there is going to be any navigation, other than from
28-
29-
// OverviewMirror.of(ApplicationMirror, ComponentPath, boolean includeExtensions)
30-
// ExtensionMirror.overview(SomeOverviewMirror.class)
31-
32-
// ApplicationMirror.allOverview(xxx) <--
33-
34-
// Options, includeExtensions?
35-
//// 99% of the time you are not interested in extensions Who cares about the extensions services, nevertheless,
36-
/// extension will find it interesting to find them in some way ServiceOverview Also
3742
public abstract class OverviewMirror<E extends Extension<E>> {
38-
// ComponentPath componentPath();
43+
44+
/** The backing handle. */
3945
final PackedOverviewHandle<E> handle;
4046

47+
/**
48+
* Creates a new overview mirror backed by the specified handle.
49+
*
50+
* @param overviewHandle
51+
* the handle providing access to operations
52+
*/
4153
protected OverviewMirror(OverviewHandle<E> overviewHandle) {
4254
this.handle = (PackedOverviewHandle<E>) requireNonNull(overviewHandle);
4355
}
4456

57+
/**
58+
* {@return a stream of all operations within this overview's scope that were installed by extension {@code E}}
59+
* <p>
60+
* Only operations on userland beans are included; extension-owned beans are excluded.
61+
*/
4562
protected final OperationMirror.OfStream<OperationMirror> operations() {
4663
return handle.operations();
4764
}
4865

49-
protected final <T extends OperationMirror> OperationMirror.OfStream<T> operations(Class<T> operations) {
50-
return handle.operations(operations);
66+
/**
67+
* Returns a stream of operations within this overview's scope that were installed by extension {@code E} and match the
68+
* specified mirror type.
69+
*
70+
* @param <T>
71+
* the type of operation mirror
72+
* @param operationType
73+
* the class of the operation mirror type to filter by
74+
* @return a stream of matching operations
75+
*/
76+
protected final <T extends OperationMirror> OperationMirror.OfStream<T> operations(Class<T> operationType) {
77+
return handle.operations(operationType);
5178
}
5279
}

modules/packed/src/main/java/internal/app/packed/component/PackedOverviewHandle.java

Lines changed: 85 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919

2020
import app.packed.application.ApplicationMirror;
2121
import app.packed.extension.Extension;
22+
import app.packed.namespace.NamespaceMirror;
2223
import app.packed.namespace.OverviewHandle;
2324
import app.packed.namespace.OverviewMirror;
2425
import app.packed.operation.OperationMirror;
2526
import internal.app.packed.application.ApplicationSetup;
27+
import internal.app.packed.namespace.NamespaceSetup;
2628
import internal.app.packed.extension.ExtensionClassModel;
2729
import internal.app.packed.invoke.ConstructorSupport;
2830
import internal.app.packed.invoke.ConstructorSupport.OverviewMirrorFactory;
@@ -33,6 +35,16 @@
3335
*/
3436
public abstract sealed class PackedOverviewHandle<E extends Extension<E>> implements OverviewHandle<E> {
3537

38+
/** Cache OverviewMirror constructor factories. */
39+
private static final ClassValue<OverviewMirrorFactory> CONSTRUCTORS = new ClassValue<>() {
40+
41+
@SuppressWarnings("unchecked")
42+
@Override
43+
protected OverviewMirrorFactory computeValue(Class<?> type) {
44+
return ConstructorSupport.findOverviewMirrorConstructor((Class<? extends OverviewMirror<?>>) type);
45+
}
46+
};
47+
3648
/** Extract the extension type variable from OverviewMirror. */
3749
private static final ClassValue<Class<? extends Extension<?>>> EXTENSION_TYPES = new ClassValue<>() {
3850

@@ -44,15 +56,11 @@ protected Class<? extends Extension<?>> computeValue(Class<?> type) {
4456
}
4557
};
4658

47-
/** Cache OverviewMirror constructor factories. */
48-
private static final ClassValue<OverviewMirrorFactory> CONSTRUCTORS = new ClassValue<>() {
4959

50-
@SuppressWarnings("unchecked")
51-
@Override
52-
protected OverviewMirrorFactory computeValue(Class<?> type) {
53-
return ConstructorSupport.findOverviewMirrorConstructor((Class<? extends OverviewMirror<?>>) type);
54-
}
55-
};
60+
@Override
61+
public final <T extends OperationMirror> OperationMirror.OfStream<T> operations(Class<T> operationType) {
62+
return (OperationMirror.OfStream<T>) operations().ofType(operationType);
63+
}
5664

5765
@SuppressWarnings("unchecked")
5866
public static <O extends OverviewMirror<?>> O ofApplication(ApplicationSetup application, Class<O> type) {
@@ -66,6 +74,43 @@ public static <O extends OverviewMirror<?>> O ofApplication(ApplicationSetup app
6674
return (O) factory.create(handle);
6775
}
6876

77+
/**
78+
* @param <O>
79+
* @param application
80+
* @param extensionType
81+
* @param type
82+
* @return
83+
*/
84+
@SuppressWarnings("unchecked")
85+
public static <O extends OverviewMirror<?>> O ofExtension(ApplicationSetup application, Class<? extends Extension<?>> extensionType, Class<O> type) {
86+
requireNonNull(extensionType, "extensionType is null");
87+
requireNonNull(type, "type is null");
88+
89+
Class<? extends Extension<?>> mirrorExtensionType = EXTENSION_TYPES.get(type);
90+
if (extensionType != mirrorExtensionType) {
91+
throw new IllegalArgumentException(
92+
"extensionType " + extensionType + " does not match the extension type of " + type + " which is " + mirrorExtensionType);
93+
}
94+
95+
OverviewMirrorFactory factory = CONSTRUCTORS.get(type);
96+
97+
PackedExtensionOverviewHandle<?> handle = new PackedExtensionOverviewHandle<>(application.mirror(), extensionType);
98+
99+
return (O) factory.create(handle);
100+
}
101+
102+
@SuppressWarnings("unchecked")
103+
public static <O extends OverviewMirror<?>> O ofNamespace(NamespaceSetup namespace, Class<O> type) {
104+
requireNonNull(type, "type is null");
105+
106+
Class<? extends Extension<?>> extensionType = EXTENSION_TYPES.get(type);
107+
OverviewMirrorFactory factory = CONSTRUCTORS.get(type);
108+
109+
PackedNamespaceOverviewHandle<?> handle = new PackedNamespaceOverviewHandle<>(namespace.mirror(), extensionType);
110+
111+
return (O) factory.create(handle);
112+
}
113+
69114
public static final class PackedApplicationOverviewHandle<E extends Extension<E>> extends PackedOverviewHandle<E> {
70115

71116
private final ApplicationMirror applicationMirror;
@@ -82,9 +127,39 @@ public OperationMirror.OfStream<OperationMirror> operations() {
82127
return applicationMirror.operations().filter(op -> op.installedByExtension() == extensionType);
83128
}
84129

130+
}
131+
132+
public static final class PackedExtensionOverviewHandle<E extends Extension<E>> extends PackedOverviewHandle<E> {
133+
134+
private final ApplicationMirror applicationMirror;
135+
136+
private final Class<? extends Extension<?>> extensionType;
137+
138+
public PackedExtensionOverviewHandle(ApplicationMirror applicationMirror, Class<? extends Extension<?>> extensionType) {
139+
this.applicationMirror = requireNonNull(applicationMirror);
140+
this.extensionType = requireNonNull(extensionType);
141+
}
142+
143+
@Override
144+
public OperationMirror.OfStream<OperationMirror> operations() {
145+
return applicationMirror.allOperations().filter(op -> op.bean().owner().isExtension(extensionType));
146+
}
147+
}
148+
149+
public static final class PackedNamespaceOverviewHandle<E extends Extension<E>> extends PackedOverviewHandle<E> {
150+
151+
private final NamespaceMirror namespaceMirror;
152+
153+
private final Class<? extends Extension<?>> extensionType;
154+
155+
public PackedNamespaceOverviewHandle(NamespaceMirror namespaceMirror, Class<? extends Extension<?>> extensionType) {
156+
this.namespaceMirror = requireNonNull(namespaceMirror);
157+
this.extensionType = requireNonNull(extensionType);
158+
}
159+
85160
@Override
86-
public <T extends OperationMirror> OperationMirror.OfStream<T> operations(Class<T> operationType) {
87-
return (OperationMirror.OfStream<T>) operations().ofType(operationType);
161+
public OperationMirror.OfStream<OperationMirror> operations() {
162+
return namespaceMirror.operations().filter(op -> op.installedByExtension() == extensionType);
88163
}
89164
}
90165
}

0 commit comments

Comments
 (0)