Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
trentjeff committed May 17, 2023
1 parent 2d27242 commit f1c07eb
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 15 deletions.
20 changes: 12 additions & 8 deletions examples/pico/application/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
This example shows how a multi-module application can be created using Helidon Pico. The
[Main.java](./src/main/java/io/helidon/examples/pico/application/Main.java) class shows:

* multi-module usage (i.e., this example extends [basics](../basics), [providers](../providers), and [configdriven](../configdriven) ).
* compile-time generation for the entire multi-module project using the _pico-maven-plugin_ (see [pom.xml](./pom.xml)).
* multi-module usage (i.e., this module amalgamates [basics](../basics), [providers](../providers), [configdriven](../configdriven), and [interceptors](../interceptors) ).
* compile-time generation of the DI model for the entire multi-module project using the _pico-maven-plugin_ (see [pom.xml](./pom.xml)).
* TestingSupport in [ApplicationTest](src/test/java/io/helidon/examples/pico/application/PicoApplicationTest.java)

## Build and run
Expand All @@ -17,7 +17,10 @@ java -jar target/helidon-examples-pico-application.jar
Expected Output:
```
Startup service providers (ranked according to weight, pre-activated): [ToolBox:INIT, CircularSaw:INIT, NailGun:INIT, TableSaw:INIT]
Highest weighted service provider: ToolBox:INIT
Highest weighted service provider: NailGun:INIT
-----
Nail Gun: (nail provider=NailProvider:INIT); initialized
Highest weighted service provider (after activation): io.helidon.examples.pico.providers.NailGun@7cbd9d24
-----
Preferred Big Tool: Big Hammer
Optional Little Hammer: Optional[Little Hammer]
Expand All @@ -30,17 +33,18 @@ Drill{root}:PENDING
AngleGrinderSaw:INIT
CircularSaw:INIT
HandSaw:INIT
NailGun:INIT
NailGun:ACTIVE
TableSaw:INIT
-----
Highest weighted service provider (after activation): ToolBox
-----
io.helidon.examples.pico.providers.CircularSaw::<init> will be injected with Optional.empty
Circular Saw: (blade=null); initialized
Nail Gun: (nail provider=NailProvider:INIT); initialized
io.helidon.examples.pico.providers.TableSaw::<init> will be injected with Optional[LARGE Blade]
Table Saw: (blade=LARGE Blade); initialized
All service providers (after all activations): [ToolBox:ACTIVE, CircularSaw:ACTIVE, NailGun:ACTIVE, TableSaw:ACTIVE]
-----
Service lookup count: 2
```

While the output of this provider may look similar to the one from the previous [providers](../providers) example, the implementation is different. This module builds [Application.java](target/generated-sources/annotations/io/helidon/examples/pico/application/Pico$$Application.java) at compile-time - establishing direct binding to every injection point in your application that is not dynamic in nature (i.e., config-driven services and _Provider_ types).
While the output of this example may look similar to the previous [providers](../providers) example, the implementation is different since this example builds (at compile time) [Application.java](target/generated-sources/annotations/io/helidon/examples/pico/application/Pico$$Application.java). This establishes direct bindings to each and every injection point in your application avoiding runtime resolution with the exception for truly dynamic runtime providers (i.e., anything that is config-driven services or _Provider_ type implementations).

Note that the lookup count is 2 based upon the direct lookup calls used in the delegated [Main](../basics/src/main/java/io/helidon/examples/pico/basics/Main.java).
2 changes: 1 addition & 1 deletion examples/pico/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<groupId>io.helidon.applications</groupId>
<artifactId>helidon-se</artifactId>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../../../applications/se/pom.xml</relativePath>
<relativePath>../../../applications/nima/pom.xml</relativePath>
</parent>
<groupId>io.helidon.examples.pico</groupId>
<artifactId>helidon-examples-pico-application</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.examples.pico.application;

import io.helidon.pico.api.Metrics;
import io.helidon.pico.api.PicoServices;

/**
* Application example. Uses the same {@code main()} as {@link io.helidon.examples.pico.basics.Main}.
*/
public class Main extends io.helidon.examples.pico.basics.Main {

/**
* Executes the example.
*
* @param args arguments
*/
public static void main(String... args) {
io.helidon.examples.pico.basics.Main.main(args);

Metrics metrics = PicoServices.picoServices().orElseThrow().metrics().get();
System.out.println("Service lookup count: " + metrics.lookupCount().get());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import io.helidon.config.Config;
import io.helidon.config.ConfigSources;
import io.helidon.examples.pico.basics.Main;
import io.helidon.pico.api.PicoServices;
import io.helidon.pico.api.Services;
import io.helidon.pico.testing.PicoTestingSupport;
Expand Down
2 changes: 1 addition & 1 deletion examples/pico/basics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<groupId>io.helidon.applications</groupId>
<artifactId>helidon-se</artifactId>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../../../applications/se/pom.xml</relativePath>
<relativePath>../../../applications/nima/pom.xml</relativePath>
</parent>
<groupId>io.helidon.examples.pico</groupId>
<artifactId>helidon-examples-pico-basics</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/pico/configdriven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<groupId>io.helidon.applications</groupId>
<artifactId>helidon-se</artifactId>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../../../applications/se/pom.xml</relativePath>
<relativePath>../../../applications/nima/pom.xml</relativePath>
</parent>
<groupId>io.helidon.examples.pico</groupId>
<artifactId>helidon-examples-pico-configdriven</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion examples/pico/interceptors/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<groupId>io.helidon.applications</groupId>
<artifactId>helidon-se</artifactId>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../../../applications/se/pom.xml</relativePath>
<relativePath>../../../applications/nima/pom.xml</relativePath>
</parent>
<groupId>io.helidon.examples.pico</groupId>
<artifactId>helidon-examples-pico-interceptors</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.helidon.pico.api.Services;

/**
* Providers example. Uses the same {@code main()} as {@link io.helidon.examples.pico.basics.Main}.
* Interceptors example. Uses the same {@code main()} as {@link io.helidon.examples.pico.basics.Main}.
*/
public class Main extends io.helidon.examples.pico.basics.Main {

Expand Down
2 changes: 1 addition & 1 deletion examples/pico/providers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<groupId>io.helidon.applications</groupId>
<artifactId>helidon-se</artifactId>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../../../applications/se/pom.xml</relativePath>
<relativePath>../../../applications/nima/pom.xml</relativePath>
</parent>
<groupId>io.helidon.examples.pico</groupId>
<artifactId>helidon-examples-pico-providers</artifactId>
Expand Down

0 comments on commit f1c07eb

Please sign in to comment.