Skip to content

Commit

Permalink
Helidon main class.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-langer committed Jun 29, 2023
1 parent f57b450 commit 629819a
Show file tree
Hide file tree
Showing 49 changed files with 899 additions and 174 deletions.
5 changes: 5 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,11 @@
<artifactId>helidon-nima</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.nima.common</groupId>
<artifactId>helidon-nima-common-api</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.nima.common</groupId>
<artifactId>helidon-nima-common-tls</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2022 Oracle and/or its affiliates.
* Copyright (c) 2017, 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.
Expand Down Expand Up @@ -81,6 +81,7 @@ private ConfigMappers() {
private static Map<Class<?>, Function<Config, ?>> initEssentialMappers() {

return Map.of(Config.class, (node) -> node,
io.helidon.common.config.Config.class, (node) -> node,
String.class, wrap(value -> value),
OptionalInt.class, ConfigMappers::optionalIntEssential,
OptionalLong.class, ConfigMappers::optionalLongEssential,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@

package io.helidon.examples.nima.faulttolerance;

import io.helidon.config.Config;
import io.helidon.config.ConfigSources;
import io.helidon.logging.common.LogConfig;
import io.helidon.pico.api.Bootstrap;
import io.helidon.pico.api.PicoServices;
import io.helidon.nima.Helidon;

/**
* Main class of the example, starts Helidon with injection support.
Expand All @@ -35,25 +31,6 @@ private FtMain() {
* @param args ignored
*/
public static void main(String[] args) {
// TODO move to a helidon-inject-runtime module (or similar) to set everything up
LogConfig.configureRuntime();

Config config = Config.builder()
.addSource(ConfigSources.classpath("application.yaml"))
.disableSystemPropertiesSource()
.disableEnvironmentVariablesSource()
.build();

ConfigService.config(config);

Bootstrap bootstrap = Bootstrap.builder()
.config(config)
.build();

PicoServices.globalBootstrap(bootstrap);

PicoServices picoServices = PicoServices.picoServices().get();
// this line is needed!
picoServices.services();
Helidon.start();
}
}
16 changes: 0 additions & 16 deletions examples/nima/imperative/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,10 @@
</properties>

<dependencies>
<dependency>
<groupId>io.helidon.nima</groupId>
<artifactId>helidon-nima</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.nima.webserver</groupId>
<artifactId>helidon-nima-webserver</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.pico</groupId>
<artifactId>helidon-pico-api</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.pico</groupId>
<artifactId>helidon-pico-runtime</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.pico.configdriven</groupId>
<artifactId>helidon-pico-configdriven-runtime</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-yaml</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package io.helidon.examples.nima.imperative;

import io.helidon.common.config.Config;
import io.helidon.common.config.GlobalConfig;
import io.helidon.common.http.Http;
import io.helidon.nima.Nima;
import io.helidon.nima.webserver.WebServer;
import io.helidon.nima.webserver.http.HttpRouting;

Expand All @@ -35,7 +35,7 @@ private ImperativeMain() {
* @param args ignored
*/
public static void main(String[] args) {
Config config = Nima.config();
Config config = GlobalConfig.config();

WebServer server = WebServer.create(ws -> ws.config(config.get("server"))
.routing(ImperativeMain::routing))
Expand Down
39 changes: 39 additions & 0 deletions helidon/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.helidon</groupId>
<artifactId>helidon-project</artifactId>
<version>4.0.0-SNAPSHOT</version>
</parent>

<artifactId>helidon</artifactId>
<name>Helidon</name>

<description>Helidon main entry point</description>

<dependencies>
<dependency>
<groupId>io.helidon.common</groupId>
<artifactId>helidon-common</artifactId>
</dependency>
</dependencies>
</project>
15 changes: 15 additions & 0 deletions helidon/src/main/java/io/helidon/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.helidon;

/**
* Main entry point for any Helidon application that is discovering services.
*/
public class Main {
/**
* Start Helidon.
*
* @param args arguments of the application
*/
public static void main(String[] args) {

}
}
15 changes: 15 additions & 0 deletions helidon/src/main/java/io/helidon/spi/HelidonStartupProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.helidon.spi;

/**
* {@link java.util.ServiceLoader} provider interface to discover the correct startup type.
* Only the first provider (with the highest {@link io.helidon.common.Weight}) will be used.
* The default startup will create Helidon Injection service registry, and start all services that should be started.
*/
public interface HelidonStartupProvider {
/**
* Start the runtime.
*
* @param arguments command line arguments
*/
void start(String[] arguments);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.integrations.micrometer;

import java.util.ArrayList;
Expand All @@ -27,6 +28,7 @@
import java.util.logging.LogRecord;
import java.util.logging.Logger;

import io.helidon.common.config.Config;
import io.helidon.common.http.Http;
import io.helidon.config.Config;
import io.helidon.nima.webserver.http.Handler;
Expand Down Expand Up @@ -266,7 +268,8 @@ public MeterRegistryFactory build() {
public Builder config(Config config) {

config.get(BUILTIN_REGISTRIES_CONFIG_KEY)
.ifExists(this::enrollBuiltInRegistries);
.as(Config.class)
.ifPresent(this::enrollBuiltInRegistries);

return this;
}
Expand Down Expand Up @@ -357,7 +360,7 @@ private void enrollBuiltInRegistries(Config registriesConfig) {
BuiltInRegistryType.valueByName(registryType);

MicrometerBuiltInRegistrySupport builtInRegistrySupport =
MicrometerBuiltInRegistrySupport.create(type, registryConfig.asNode());
MicrometerBuiltInRegistrySupport.create(type, registryConfig.as(Config.class));

candidateBuiltInRegistryTypes.put(type, builtInRegistrySupport);
} catch (BuiltInRegistryType.UnrecognizedBuiltInRegistryTypeException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.integrations.micrometer;

import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

import io.helidon.config.Config;
import io.helidon.config.ConfigValue;
import io.helidon.common.config.Config;
import io.helidon.common.config.ConfigValue;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.config.MeterRegistryConfig;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates.
* Copyright (c) 2022, 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.
Expand All @@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.integrations.micrometer;

import java.util.function.Supplier;

import io.helidon.common.config.Config;
import io.helidon.common.context.Contexts;
import io.helidon.config.Config;
import io.helidon.config.metadata.Configured;
import io.helidon.nima.servicecommon.HelidonFeatureSupport;
import io.helidon.nima.webserver.http.HttpRouting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.integrations.micrometer;

import java.io.IOException;
Expand All @@ -21,9 +22,9 @@
import java.util.Optional;
import java.util.function.Function;

import io.helidon.common.config.Config;
import io.helidon.common.config.ConfigValue;
import io.helidon.common.media.type.MediaTypes;
import io.helidon.config.Config;
import io.helidon.config.ConfigValue;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.config.MeterRegistryConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.util.Optional;

import io.helidon.config.Config;
import io.helidon.nima.servicecommon.HelidonFeatureSupport;
import io.helidon.nima.webserver.http.HttpService;

Expand Down Expand Up @@ -69,7 +68,7 @@ public ConfiguredTestSupport build() {
}

@Override
public Builder config(Config config) {
public Builder config(io.helidon.common.config.Config config) {
super.config(config);
config.get("importance").asInt().ifPresent(this::importance);
return this;
Expand Down
43 changes: 43 additions & 0 deletions nima/common/api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2022, 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.
-->

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.helidon.nima.common</groupId>
<artifactId>helidon-nima-common-project</artifactId>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>helidon-nima-common-api</artifactId>
<name>Helidon Níma Common API</name>
<description>APIs need for any Níma feature, independent on WebServer</description>

<dependencies>
<dependency>
<groupId>io.helidon.pico</groupId>
<artifactId>helidon-pico-api</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,19 @@
* limitations under the License.
*/

package io.helidon.examples.nima.faulttolerance;
package io.helidon.nima.common.api;

import io.helidon.config.Config;

import jakarta.inject.Provider;
import jakarta.inject.Singleton;
import io.helidon.pico.api.Contract;

/**
* This service will be part of Níma on Pico module.
* It may use pico to get config sources exposed through pico.
* Some components may require start when Helidon is bootstrapped, such as WebServer (to open server sockets).
* This interface is a Helidon Injection contract, that allows us to discover all startable services and start them
* on boot when desired.
*/
@Singleton
class ConfigService implements Provider<Config> {
private static volatile Config config;
static void config(Config config) {
ConfigService.config = config;
}

@Override
public Config get() {
return config;
}
@Contract
public interface Startable {
/**
* Start this service.
*/
void startService();
}
Loading

0 comments on commit 629819a

Please sign in to comment.