Skip to content

Commit 7932ad8

Browse files
committed
er
1 parent 7017066 commit 7932ad8

11 files changed

Lines changed: 157 additions & 114 deletions

File tree

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717

1818
import java.util.function.Supplier;
1919

20+
import org.jspecify.annotations.Nullable;
21+
2022
import app.packed.application.BootstrapApp.Image;
2123
import app.packed.build.BuildGoal;
2224
import app.packed.component.ComponentHandle;
2325
import app.packed.component.ComponentPath;
2426
import app.packed.component.Sidehandle;
25-
import org.jspecify.annotations.Nullable;
2627
import internal.app.packed.application.ApplicationSetup;
2728
import internal.app.packed.application.PackedApplicationInstaller;
2829
import internal.app.packed.application.PackedBootstrapImage.ImageEager;
@@ -118,26 +119,10 @@ public final C configuration() {
118119
return configuration.get();
119120
}
120121

121-
/**
122-
* The image
123-
*
124-
* @return the base image for the application
125-
* @throws IllegalStateException
126-
* if the application was build with {@link BuildGoal#IMAGE}.
127-
*/
128-
// Tror jeg fjerner den her... BaseImage er kun noget man bruger ved rødder tænker jeg???
129-
final BootstrapApp.Image<A> image() {
130-
BootstrapApp.Image<A> i = image;
131-
if (i == null) {
132-
throw new IllegalStateException("The application must be installed with BuildImage, was " + application.goal);
133-
}
134-
return i;
135-
}
136-
137122
public final Sidehandle sidehandle() {
138123
Sidehandle sidehandle = application.sidehandle;
139124
if (sidehandle == null) {
140-
throw new UnsupportedOperationException("Operation has not been attached to a sidehandle");
125+
throw new UnsupportedOperationException("Application has not been attached to a sidehandle");
141126
}
142127
return sidehandle;
143128
}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222
/**
2323
* Launches an application.
2424
*/
25+
26+
// Grunden til vi ikke gider koere abstract klasse, er at metoderne alligevel skal overrides.
27+
// Fordi vi koere method chanining. Subclasses skal ikke returnere ApplicationLauncher men
28+
// Subclass
29+
30+
31+
// Vi mangler to ting vil jeg mere
32+
/// 1) Noget med nogle options a.la. DEBUG all
33+
/// 2) Noget med Configs (naar det kommer)
2534
public interface ApplicationLauncher {
2635

2736
default ApplicationLauncher args(String... args) {
@@ -41,11 +50,10 @@ default <T> ApplicationLauncher provide(Class<? super T> key, T instance) {
4150

4251
default ApplicationLauncher provide(Object instance) {
4352
requireNonNull(instance, "object cannot be null");
44-
return provideCaptured(this, instance.getClass(), instance);
53+
return provide(this, instance.getClass(), instance);
4554
}
4655

47-
private static <T> ApplicationLauncher provideCaptured(
48-
ApplicationLauncher self, Class<T> type, Object instance) {
56+
private static <T> ApplicationLauncher provide(ApplicationLauncher self, Class<T> type, Object instance) {
4957
return self.provide(type, type.cast(instance));
5058
}
5159
}

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

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ public sealed interface BootstrapApp<I> extends ApplicationInterface permits Pac
112112
* if the application threw an exception that could not be handled
113113
* @see App#run(Assembly, Wirelet...)
114114
*/
115-
I launch(RunState state, Assembly assembly, Wirelet... wirelets);
115+
default I launch(RunState state, Assembly assembly, Wirelet... wirelets) {
116+
return launcher(assembly, wirelets).launch(state);
117+
}
116118

117119
Launcher<I> launcher(Assembly assembly, Wirelet... wirelets);
118120

@@ -162,33 +164,6 @@ default <E> BootstrapApp<E> map(Function<? super I, ? extends E> mapper) {
162164
// withExpectingResult
163165
BootstrapApp<I> withExpectsResult(Class<?> resultType);
164166

165-
/**
166-
* Augment the driver with the specified wirelets, that will be processed when building or instantiating new
167-
* applications.
168-
* <p>
169-
* For example, to : <pre> {@code
170-
* BootstrapApp<App> app = ...;
171-
* app = app.with(ApplicationWirelets.timeToRun(2, TimeUnit.MINUTES));
172-
* }</pre>
173-
*
174-
* ApplicationW
175-
* <p>
176-
* This method will make no attempt of validating the specified wirelets.
177-
*
178-
* <p>
179-
* Wirelets that were specified when creating the driver, or through previous invocation of this method. Will be
180-
* processed before the specified wirelets.
181-
*
182-
* @param wirelets
183-
* the wirelets to add
184-
* @return the new bootstrap app
185-
*/
186-
// Before orAfter
187-
default BootstrapApp<I> withWirelets(boolean before, Wirelet... wirelets) {
188-
// Lad os ogsaa lige se med expectsResult, inde vi implementere det
189-
throw new UnsupportedOperationException();
190-
}
191-
192167
static <A> BootstrapApp<A> of(LifecycleKind lifecycleKind, Bean<A> bean) {
193168
return PackedBootstrapApp.of(lifecycleKind, bean);
194169
}
@@ -243,15 +218,6 @@ default <E> Image<E> map(Function<? super A, ? extends E> mapper) {
243218
*/
244219
interface Launcher<A> extends ApplicationLauncher {
245220

246-
/**
247-
* Create a new instance of the application in the initialized state.
248-
*
249-
* @return
250-
*/
251-
default A initialize() {
252-
return launch(RunState.INITIALIZED);
253-
}
254-
255221
/**
256222
* Launches an instance of the application that this image represents in the specified state.
257223
* <p>
@@ -290,14 +256,6 @@ public Image<E> imageOf(Assembly assembly, Wirelet... wirelets) {
290256
return ba.map(mapper);
291257
}
292258

293-
/** {@inheritDoc} */
294-
@Override
295-
public E launch(RunState state, Assembly assembly, Wirelet... wirelets) {
296-
A result = app.launch(state, assembly, wirelets);
297-
E e = mapper.apply(result);
298-
return e;
299-
}
300-
301259
/** {@inheritDoc} */
302260
@Override
303261
public ApplicationMirror mirrorOf(Assembly assembly, Wirelet... wirelets) {
@@ -324,4 +282,32 @@ public void verify(Assembly assembly, Wirelet... wirelets) {
324282
public Launcher<E> launcher(Assembly assembly, Wirelet... wirelets) {
325283
throw new UnsupportedOperationException();
326284
}
327-
}
285+
}
286+
287+
///**
288+
//* Augment the driver with the specified wirelets, that will be processed when building or instantiating new
289+
//* applications.
290+
//* <p>
291+
//* For example, to : <pre> {@code
292+
//* BootstrapApp<App> app = ...;
293+
//* app = app.with(ApplicationWirelets.timeToRun(2, TimeUnit.MINUTES));
294+
//* }</pre>
295+
//*
296+
//* ApplicationW
297+
//* <p>
298+
//* This method will make no attempt of validating the specified wirelets.
299+
//*
300+
//* <p>
301+
//* Wirelets that were specified when creating the driver, or through previous invocation of this method. Will be
302+
//* processed before the specified wirelets.
303+
//*
304+
//* @param wirelets
305+
//* the wirelets to add
306+
//* @return the new bootstrap app
307+
//*/
308+
//// Before orAfter <---- Just this question alone makes we want to not support it
309+
//@Deprecated
310+
//default BootstrapApp<I> withWirelets(boolean before, Wirelet... wirelets) {
311+
// // Lad os ogsaa lige se med expectsResult, inde vi implementere det
312+
// throw new UnsupportedOperationException();
313+
//}

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,6 @@ public void run() {
8686
public App start() {
8787
return image.launch(RunState.RUNNING);
8888
}
89-
//
90-
// /** {@inheritDoc} */
91-
// @Override
92-
// public void checkedRun(Wirelet... wirelets) throws UnhandledApplicationException {
93-
// image.checkedLaunch(RunState.TERMINATED, wirelets);
94-
// }
95-
//
96-
// /** {@inheritDoc} */
97-
// @Override
98-
// public App checkedStart(Wirelet... wirelets) throws UnhandledApplicationException {
99-
// return image.checkedLaunch(RunState.RUNNING, wirelets);
100-
// }
10189

10290
/** {@inheritDoc} */
10391
@Override
@@ -118,6 +106,7 @@ record AppLauncher(BootstrapApp.Launcher<PackedApp> launcher) implements App.Lau
118106
/** {@inheritDoc} */
119107
@Override
120108
public <T> AppLauncher provide(Key<? super T> key, T value) {
109+
launcher.provide(key, value);
121110
return this;
122111
}
123112

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@
2525
import app.packed.container.Wirelet;
2626
import app.packed.extension.BaseExtension;
2727
import app.packed.lifecycle.LifecycleKind;
28-
import app.packed.lifecycle.RunState;
2928
import internal.app.packed.ValueBased;
29+
import internal.app.packed.application.PackedApplicationInstaller;
3030
import internal.app.packed.application.PackedApplicationTemplate;
3131
import internal.app.packed.application.PackedApplicationTemplate.ApplicationInstallingSource;
32+
import internal.app.packed.application.PackedBootstrapImage.ImageEager;
33+
import internal.app.packed.application.PackedBootstrapImage.ImageNonReusable;
34+
import internal.app.packed.application.PackedBootstrapLauncher;
3235
import internal.app.packed.bean.sidehandle.SidehandleBeanHandle;
3336
import internal.app.packed.extension.ExtensionSetup;
3437
import internal.app.packed.invoke.MethodHandleInvoker.ApplicationBaseLauncher;
3538
import internal.app.packed.invoke.ServiceSupport;
36-
import internal.app.packed.lifecycle.runtime.ApplicationLaunchContext;
3739

3840
/** Implementation of {@link BootstrapApp}. */
3941
@ValueBased
@@ -44,8 +46,8 @@ final class PackedBootstrapApp<A, H extends ApplicationHandle<A, ?>> implements
4446
// So beans do not uses hooks from various extensions
4547
// Or maybe we check this somewhere. I think SidehandleBinding is the only supported annotation + Lifecycle
4648
// Maybe all base extension actually.
47-
private static final PackedApplicationTemplate<?> BOOTSTRAP_APP_TEMPLATE =
48-
PackedApplicationTemplate.of(LifecycleKind.UNMANAGED, Bean.of(PackedBootstrapApp.class));
49+
private static final PackedApplicationTemplate<?> BOOTSTRAP_APP_TEMPLATE = PackedApplicationTemplate.of(LifecycleKind.UNMANAGED,
50+
Bean.of(PackedBootstrapApp.class));
4951

5052
/** The application launcher. */
5153
private final ApplicationBaseLauncher launcher;
@@ -67,31 +69,30 @@ private PackedBootstrapApp(PackedApplicationTemplate<H> template, ApplicationBas
6769
/** {@inheritDoc} */
6870
@Override
6971
public Image<A> imageOf(Assembly assembly, Wirelet... wirelets) {
70-
ApplicationInstaller<H> installer = template.newInstaller(this, BuildGoal.IMAGE, launcher, wirelets);
72+
PackedApplicationInstaller<H> installer = template.newInstaller(this, BuildGoal.IMAGE, launcher, wirelets);
7173

7274
// Build the application
7375
H handle = installer.install(assembly);
7476

75-
// Returns an image for the application
76-
return handle.image();
77+
// Create an image for the application
78+
BootstrapApp.Image<A> img = new ImageEager<>(handle);
79+
if (!installer.optionBuildReusableImage) {
80+
img = new ImageNonReusable<>(img);
81+
}
82+
83+
return img;
7784
}
7885

7986
/** {@inheritDoc} */
8087
@Override
81-
public A launch(RunState state, Assembly assembly, Wirelet... wirelets) {
88+
public Launcher<A> launcher(Assembly assembly, Wirelet... wirelets) {
8289
ApplicationInstaller<H> installer = template.newInstaller(this, BuildGoal.LAUNCH, launcher, wirelets);
8390

8491
// Build the application
8592
H handle = installer.install(assembly);
8693

87-
// Create and return an instance of the application interface, wirelets have already been specified in the installer
88-
return ApplicationLaunchContext.launch(handle, state);
89-
}
90-
91-
/** {@inheritDoc} */
92-
@Override
93-
public Launcher<A> launcher(Assembly assembly, Wirelet... wirelets) {
94-
return imageOf(assembly, wirelets);
94+
// Returns an launcher for the application
95+
return new PackedBootstrapLauncher<A>(handle);
9596
}
9697

9798
/** {@inheritDoc} */

modules/packed/src/main/java/app/packed/lifecycle/runtime/ManagedLifecycle.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,6 @@ public interface ManagedLifecycle {
110110
RunState currentState();
111111

112112
boolean isFailed();
113-
//
114-
// default int entryPointId() {
115-
// return -1;
116-
// }
117-
118-
// Vs main?????
119-
// Tror main er bl.a. propper det ind som et system image...
120113

121114
/**
122115
* Starts and awaits the component if it has not already been started.
@@ -152,10 +145,6 @@ default ManagedLifetimeState state() {
152145
*/
153146
void stop(StopOption... options);
154147

155-
default Optional<StopInfo> stopInfo() {
156-
return Optional.empty();
157-
}
158-
159148
default CompletableFuture<Void> stopAsync(StopOption... options) {
160149
return stopAsync(null, new StopOption[] {});
161150
}
@@ -177,6 +166,10 @@ default CompletableFuture<Void> stopAsync(StopOption... options) {
177166
// Does not take null. use StopAsync
178167
<T> CompletableFuture<T> stopAsync(T result, StopOption... options);
179168

169+
default Optional<StopInfo> stopInfo() {
170+
return Optional.empty();
171+
}
172+
180173
// Den er cool men sgu ikke super smart for forstaelsen
181174
// static void run(Assembly assembly, Wirelet... wirelets) {
182175
// ApplicationRuntimeImplementation.DRIVER.launch(assembly, wirelets);

modules/packed/src/main/java/app/packed/lifecycle/runtime/StopInfo.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,18 @@ private Trigger(String trigger) {
100100
// Session Time Out (Maa vaere SESSION_TIMEOUT)
101101
public static final Trigger TIMEOUT = new Trigger("Timeout");
102102

103-
/** An entry-point completed normally. */
104-
public static final Trigger ENTRY_POINT_COMPLETED = new Trigger("Normal");
105-
106103
public static final Trigger NORMAL = new Trigger("Normal");
107104

108105
public static final Trigger FAILED_INTERNALLY = new Trigger("Failed");
109106

110-
public static final Trigger RESTARTING = new Trigger("Restarting");
107+
//public static final Trigger RESTARTING = new Trigger("Restarting");
111108

112109
public static final Trigger UNKNOWN = new Trigger("Unknown");
113110

111+
@Override
112+
public String toString() {
113+
return trigger;
114+
}
114115
// WAS
115116
// NORMAL, EXECUTION_FAILED,
116117
// PERSISTING,

modules/packed/src/main/java/app/packed/lifecycle/runtime/LaunchArg.java renamed to modules/packed/src/main/java/app/packed/lifetime/LaunchArg.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package app.packed.lifecycle.runtime;
16+
package app.packed.lifetime;
1717

1818
/**
1919
*
2020
*/
2121
// Ideen er lidt at dette er runtime Wirelet
22+
// Hvorfor ikke bare en Doo <--- required
2223

2324
// Needs to be well integrated with application.properties
2425
public @interface LaunchArg {

modules/packed/src/main/java/app/packed/service/ServiceLocator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import app.packed.application.ApplicationMirror;
3030
import app.packed.application.BootstrapApp;
3131
import app.packed.assembly.Assembly;
32-
import app.packed.lifecycle.LifecycleKind;
3332
import app.packed.bean.Bean;
3433
import app.packed.bean.BeanIntrospector;
3534
import app.packed.bean.BeanTrigger.AutoService;
@@ -38,6 +37,7 @@
3837
import app.packed.component.SidehandleBinding;
3938
import app.packed.container.Wirelet;
4039
import app.packed.extension.BaseExtension;
40+
import app.packed.lifecycle.LifecycleKind;
4141
import app.packed.lifecycle.RunState;
4242
import app.packed.operation.Op1;
4343
import internal.app.packed.lifecycle.runtime.PackedExtensionContext;
@@ -387,7 +387,7 @@ private Image(BootstrapApp.Image<ServiceLocator> image) {
387387

388388
/** Creates a new service locator application from this image. */
389389
public ServiceLocator initialize() {
390-
return image.initialize();
390+
return image.launch(RunState.INITIALIZED);
391391
}
392392
}
393393
}

0 commit comments

Comments
 (0)