Skip to content

Commit 01acafc

Browse files
committed
wer
s
1 parent e1a8e87 commit 01acafc

File tree

72 files changed

+1582
-748
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1582
-748
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public final C configuration() {
117117
* @throws IllegalStateException
118118
* if the application was build with {@link BuildGoal#IMAGE}.
119119
*/
120+
// Tror jeg fjerner den her... BaseImage er kun noget man bruger ved rødder tænker jeg???
120121
public final BaseImage<A> image() {
121122
BaseImage<A> i = image;
122123
if (i == null) {
@@ -141,10 +142,18 @@ public final boolean isConfigurable() {
141142
* @param wirelets
142143
* optional wirelets
143144
* @return the application instance
145+
*
146+
* @throws UnsupportedOperationException
147+
* if managed and not a root container\
148+
* @see #launch(GuestManager, Wirelet...)
144149
*/
145150
@SuppressWarnings("unchecked")
151+
// Tror den her bliver hidden
152+
// Problemet er at den er statisk. Der er ingen runtime information.
153+
// Hvis vi har startet 23 applikationer, faar de stadig ingen input
146154
public final A launch(RunState state, Wirelet... wirelets) {
147155
requireNonNull(state, "state is null");
156+
// TODO fix
148157
if (!application.completedBuilding) {
149158
throw new IllegalStateException("Application has not finished building");
150159
}

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

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.stream.Stream;
1010

1111
import app.packed.assembly.AssemblyMirror;
12+
import app.packed.bean.BeanMirror;
1213
import app.packed.build.BuildGoal;
1314
import app.packed.component.ComponentMirror;
1415
import app.packed.component.ComponentPath;
@@ -59,6 +60,34 @@ public ApplicationMirror(ApplicationHandle<?, ?> handle) {
5960
this.handle = requireNonNull(handle);
6061
}
6162

63+
/**
64+
* {@return a stream of all of the operations declared in the application.}
65+
* <p>
66+
* Unlike {@link #beans()}, this stream includes beans that are owned by extensions.
67+
*/
68+
public Stream<BeanMirror> allBeans() {
69+
return containers().stream().flatMap(ContainerMirror::allBeans);
70+
}
71+
72+
/** {@return a stream of all of the operations declared by the user in the application.} */
73+
public Stream<OperationMirror> allOperations() {
74+
return allBeans().flatMap(BeanMirror::operations);
75+
}
76+
77+
/**
78+
* Returns a stream of all of the operations declared by the bean with the specified mirror type.
79+
*
80+
* @param <T>
81+
* @param operationType
82+
* the type of operations to include
83+
* @return a collection of all of the operations declared by the bean of the specified type.
84+
*/
85+
@SuppressWarnings("unchecked")
86+
public <T extends OperationMirror> Stream<T> allOperations(Class<T> operationType) {
87+
requireNonNull(operationType, "operationType is null");
88+
return (Stream<T>) allOperations().filter(f -> operationType.isAssignableFrom(f.getClass()));
89+
}
90+
6291
/** {@return a tree representing all the assemblies used for creating this application} */
6392
public TreeView<AssemblyMirror> assemblies() {
6493
return new PackedTreeView<>(handle.application.container().assembly, null, c -> c.mirror());
@@ -69,6 +98,15 @@ public AssemblyMirror assembly() {
6998
return handle.application.container().assembly.mirror();
7099
}
71100

101+
/** {@return a stream of all of the bean declared by the user in the application.} */
102+
public Stream<BeanMirror> beans() {
103+
return containers().stream().flatMap(ContainerMirror::beans);
104+
}
105+
// ApplicationMirror
106+
// All namespaces with root container
107+
// All namespaces in the whole application
108+
// All namespaces with a non-user owner
109+
72110
/** {@return the build goal that was used when building the application} */
73111
public BuildGoal buildGoal() {
74112
return handle.application.deployment.goal;
@@ -158,6 +196,9 @@ public String name() {
158196
return handle.application.container().name();
159197
}
160198

199+
// Alternatively all keysspaces not owned by the application must be prefixed with $
200+
// $FooExtension$main I think I like this better
201+
// NamespaceKey <Type, Owner?, ContainerPath, Name>
161202

162203
// Application owned namespace...
163204
// Optional???
@@ -177,18 +218,9 @@ public <N extends NamespaceMirror<?>> Optional<N> namespace(Class<N> type, Strin
177218
return Optional.empty();
178219
}
179220

180-
// ApplicationMirror
181-
// All namespaces with root container
182-
// All namespaces in the whole application
183-
// All namespaces with a non-user owner
184-
185-
// Alternatively all keysspaces not owned by the application must be prefixed with $
186-
// $FooExtension$main I think I like this better
187-
// NamespaceKey <Type, Owner?, ContainerPath, Name>
188-
189-
/** {@return a stream of all of the operations declared by the bean.} */
221+
/** {@return a stream of all of the operations declared by the user in the application.} */
190222
public Stream<OperationMirror> operations() {
191-
return handle.application.container().stream().map(s -> s.mirror()).flatMap(ContainerMirror::operations);
223+
return beans().flatMap(BeanMirror::operations);
192224
}
193225

194226
/**
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) 2008 Kasper Nielsen.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package app.packed.application;
17+
18+
import java.util.Optional;
19+
import java.util.stream.Stream;
20+
21+
import app.packed.application.repository.ApplicationLauncher;
22+
import app.packed.application.repository.ManagedInstance;
23+
import app.packed.extension.BaseExtension;
24+
import app.packed.extension.BaseExtensionPoint;
25+
import internal.app.packed.extension.ExtensionSetup;
26+
27+
/**
28+
* An application repository that can be used to install applications at runtime or retrieve applications that were
29+
* installed at build-time.
30+
* <p>
31+
* This interface only supported unmanaged applications.
32+
* If you need to create managed applications uses {@link app.packed.application.guestmanager.ManagedApplicationRepository}.
33+
*/
34+
public interface ApplicationRepository<I, H extends ApplicationHandle<I, ?>> {
35+
36+
Optional<H> handle(String name);
37+
38+
/**
39+
* {@return a stream of all applications (represented by their application handle} that have been installed into the
40+
* repository}
41+
*/
42+
Stream<H> handles();
43+
44+
Optional<ManagedInstance<I>> instance(String name);
45+
46+
Stream<ManagedInstance<I>> instances();
47+
48+
Optional<ApplicationLauncher<I>> launcher(String name);
49+
50+
Stream<ApplicationLauncher<I>> launchers();
51+
52+
/**
53+
* Creates an installer for a new application based on {@link #template()}.
54+
*
55+
* @return an installer for a new application
56+
*/
57+
ApplicationTemplate.Installer<H> newApplication();
58+
59+
/** {@return the template that is used for all applications in this repository} */
60+
ApplicationTemplate<H> template();
61+
62+
static <A, H extends ApplicationHandle<A, ?>> ApplicationRepositoryConfiguration<A, H> install(BaseExtensionPoint point) {
63+
throw new UnsupportedOperationException();
64+
}
65+
66+
// Syntes maaske vi skal tage H med.. Saa kan vi lave en god default key
67+
static <A, H extends ApplicationHandle<A, ?>> ApplicationRepositoryConfiguration<A, H> install(Class<H> handleKind, ApplicationTemplate<H> template,
68+
BaseExtension extension) {
69+
return ApplicationRepositoryHandle.install(handleKind, template, ExtensionSetup.crack(extension), ExtensionSetup.crack(extension).container.assembly);
70+
}
71+
72+
static <A, H extends ApplicationHandle<A, ?>> ApplicationRepositoryConfiguration<A, H> provide(Class<H> handleKind, ApplicationTemplate<H> template,
73+
BaseExtension extension) {
74+
return install(handleKind, template, extension).provide();
75+
}
76+
77+
// Shared with ContainerRepository
78+
interface Entry {
79+
boolean isBuild();
80+
boolean isLazy(); // Built on first usage
81+
82+
// An application can be, NA, INSTALLING, AVAILABLE
83+
// Don't know if we at runtime
84+
// Hvad hvis man ikke vil installere noget paa runtime...
85+
}
86+
}

modules/packed/src/main/java/app/packed/application/repository/ApplicationRepositoryConfiguration.java renamed to modules/packed/src/main/java/app/packed/application/ApplicationRepositoryConfiguration.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package app.packed.application.repository;
16+
package app.packed.application;
1717

1818
import java.util.function.Consumer;
1919

20-
import app.packed.application.ApplicationHandle;
21-
import app.packed.application.ApplicationTemplate;
22-
import app.packed.binding.Key;
2320
import app.packed.service.ProvidableBeanConfiguration;
2421

2522
/**
@@ -35,24 +32,24 @@
3532
// I don't know don't we always??
3633

3734
// Maybe we don't extend it ServiableBean and have a provideAtRuntime();
38-
public final class ApplicationRepositoryConfiguration<H extends ApplicationHandle<?, ?>> extends ProvidableBeanConfiguration<ApplicationRepository<H>> {
35+
public final class ApplicationRepositoryConfiguration<I, H extends ApplicationHandle<I, ?>> extends ProvidableBeanConfiguration<ApplicationRepository<I, H>> {
3936

4037
/** The application repository bean handle. */
41-
final ApplicationRepositoryHandle<H> handle;
38+
final ApplicationRepositoryHandle<I, H> handle;
4239

4340
/**
4441
* @param handle
4542
* the bean's handle
4643
*/
47-
ApplicationRepositoryConfiguration(ApplicationRepositoryHandle<H> handle) {
44+
ApplicationRepositoryConfiguration(ApplicationRepositoryHandle<I, H> handle) {
4845
super(handle);
4946
this.handle = handle;
5047
}
5148

5249
// Okay, vi har elastic search in an Assembly. Byg den
5350
// Expose some services. Og vi har nok en masse shared services.
5451
// Tror ikke helt vi er klar
55-
52+
// Ved ikke om det har noget med repository at goere. Det tror jeg egentlig ikke...
5653
public void buildDependecy(Consumer<? super ApplicationTemplate.Installer<H>> installer) {
5754
handle.repository.add(installer);
5855
}
@@ -63,21 +60,16 @@ public void buildDependecy(Consumer<? super ApplicationTemplate.Installer<H>> in
6360
* @param installer
6461
* a consumer that performs the actual installation of the application
6562
*/
66-
public void installChildApplication(Consumer<? super ApplicationTemplate.Installer<H>> installer) {
63+
public void installApplication(Consumer<? super ApplicationTemplate.Installer<H>> installer) {
6764
handle.repository.add(installer);
6865
}
6966

7067
@Override
71-
public ApplicationRepositoryConfiguration<H> provideAs(Class<? super ApplicationRepository<H>> key) {
72-
super.provideAs(key);
68+
public ApplicationRepositoryConfiguration<I, H> provide() {
69+
super.provide();
7370
return this;
7471
}
7572

76-
@Override
77-
public ApplicationRepositoryConfiguration<H> provideAs(Key<? super ApplicationRepository<H>> key) {
78-
super.provideAs(key);
79-
return this;
80-
}
8173

8274
/** {@return the templates that are available in the repository) */
8375
@SuppressWarnings("unchecked")
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 2008 Kasper Nielsen.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package app.packed.application;
17+
18+
import java.lang.reflect.ParameterizedType;
19+
20+
import app.packed.bean.BeanHandle;
21+
import app.packed.bean.BeanInstaller;
22+
import app.packed.bean.BeanKind;
23+
import app.packed.bean.BeanTemplate;
24+
import app.packed.binding.Key;
25+
import app.packed.binding.Variable;
26+
import app.packed.lifecycle.LifecycleKind;
27+
import internal.app.packed.application.PackedApplicationTemplate;
28+
import internal.app.packed.application.repository.AbstractApplicationRepository;
29+
import internal.app.packed.application.repository.BuildApplicationRepository;
30+
import internal.app.packed.application.repository.ManagedApplicationRepository;
31+
import internal.app.packed.application.repository.UnmanagedApplicationRepository;
32+
import internal.app.packed.bean.BeanSetup;
33+
import internal.app.packed.bean.PackedBeanTemplate;
34+
import internal.app.packed.build.AuthoritySetup;
35+
import internal.app.packed.extension.ExtensionSetup;
36+
import internal.app.packed.util.types.Types;
37+
38+
class ApplicationRepositoryHandle<I, H extends ApplicationHandle<I, ?>> extends BeanHandle<ApplicationRepositoryConfiguration<I, H>> {
39+
40+
private static final PackedBeanTemplate REPOSITORY_BEAN_TEMPLATE = (PackedBeanTemplate) BeanTemplate.of(BeanKind.CONTAINER,
41+
b -> b.createAs(AbstractApplicationRepository.class));
42+
43+
private final Class<H> handleKind;
44+
45+
final BuildApplicationRepository repository;
46+
47+
private ApplicationRepositoryHandle(BeanInstaller installer, Class<H> handleKind, BuildApplicationRepository repository) {
48+
super(installer);
49+
this.handleKind = handleKind;
50+
this.repository = repository;
51+
}
52+
53+
@Override
54+
public Key<?> defaultKey() {
55+
// We need to know the template type either, from the template itself, or when creating the repository.
56+
// Think we might as well just do it in the template
57+
ParameterizedType p = Types.createNewParameterizedType(ApplicationRepository.class, repository.template.guestClass(), handleKind);
58+
Variable v = Variable.of(p);
59+
Key<?> key = Key.fromVariable(v);
60+
return key;
61+
}
62+
63+
/** {@inheritDoc} */
64+
@Override
65+
protected ApplicationRepositoryConfiguration<I, H> newBeanConfiguration() {
66+
return new ApplicationRepositoryConfiguration<>(this);
67+
}
68+
69+
/** {@inheritDoc} */
70+
@Override
71+
protected void onClose() {
72+
bindServiceInstance(BuildApplicationRepository.class, repository);
73+
BeanSetup.crack(this).container.application.subChildren.add(repository);
74+
}
75+
76+
static <A, H extends ApplicationHandle<A, ?>> ApplicationRepositoryConfiguration<A, H> install(Class<H> handleKind, ApplicationTemplate<H> template,
77+
ExtensionSetup es, AuthoritySetup<?> owner) {
78+
PackedApplicationTemplate<H> t = (PackedApplicationTemplate<H>) template;
79+
if (t.guestClass() == Void.class) {
80+
throw new UnsupportedOperationException("Does not support application templates of Void.class guest type");
81+
}
82+
83+
// Create a new installer for the repository bean
84+
85+
Class<?> cl = t.containerTemplate().lifecycleKind() == LifecycleKind.UNMANAGED ? UnmanagedApplicationRepository.class
86+
: ManagedApplicationRepository.class;
87+
88+
BeanInstaller installer = ApplicationRepositoryHandle.REPOSITORY_BEAN_TEMPLATE.newInstaller(es, owner);
89+
ApplicationRepositoryHandle<A, H> h = installer.install(cl, i -> new ApplicationRepositoryHandle<>(i, handleKind, new BuildApplicationRepository(t)));
90+
91+
// Create a new installer for the guest bean
92+
BeanInstaller i = PackedApplicationTemplate.GB.newInstaller(es, owner);
93+
t.installGuestBean(i, h.repository::onCodeGenerated);
94+
95+
return h.configuration();
96+
}
97+
}

0 commit comments

Comments
 (0)