/*
 * Copyright 2017-2020 original authors
 *
 * 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
 *
 * https://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.micronaut.runtime;

import io.micronaut.context.annotation.BootstrapContextCompatible;
import io.micronaut.context.annotation.ConfigurationProperties;
import io.micronaut.context.annotation.Primary;
import io.micronaut.core.naming.NameUtils;
import io.micronaut.discovery.ServiceInstance;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;

Common application configuration.
Author:Graeme Rocher
Since:1.0
/** * Common application configuration. * * @author Graeme Rocher * @since 1.0 */
@ConfigurationProperties(ApplicationConfiguration.PREFIX) @Primary @BootstrapContextCompatible public class ApplicationConfiguration {
Prefix for Micronaut application settings.
/** * Prefix for Micronaut application settings. */
public static final String PREFIX = "micronaut.application";
Property name for Micronaut default charset.
/** * Property name for Micronaut default charset. */
public static final String DEFAULT_CHARSET = PREFIX + ".default-charset";
Property name for Micronaut application name.
/** * Property name for Micronaut application name. */
public static final String APPLICATION_NAME = PREFIX + ".name"; private Charset defaultCharset = StandardCharsets.UTF_8; private String name; private InstanceConfiguration instance = new InstanceConfiguration();
Returns:The default charset to use.
/** * @return The default charset to use. */
@SuppressWarnings("unchecked") public Charset getDefaultCharset() { return defaultCharset; }
Default value (UTF-8).
Params:
  • defaultCharset – Set the default charset to use.
/** * Default value (UTF-8). * @param defaultCharset Set the default charset to use. */
public void setDefaultCharset(Charset defaultCharset) { this.defaultCharset = defaultCharset; }
The application name. Used to identify the application for purposes of reporting, tracing, service discovery etc. Should be unique.
Returns:The application name
/** * The application name. Used to identify the application for purposes of reporting, tracing, service discovery etc. * Should be unique. * * @return The application name */
public Optional<String> getName() { return Optional.ofNullable(name); }
Params:
  • name – Set the application name
/** * @param name Set the application name */
public void setName(String name) { if (name != null) { this.name = NameUtils.hyphenate(name); } }
Returns:Configuration for the application instance
/** * @return Configuration for the application instance */
public InstanceConfiguration getInstance() { return instance; }
Params:
  • instance – The instance configuration
/** * @param instance The instance configuration */
public void setInstance(InstanceConfiguration instance) { if (instance != null) { this.instance = instance; } }
Configuration for instance settings.
/** * Configuration for instance settings. */
@ConfigurationProperties(InstanceConfiguration.PREFIX) @BootstrapContextCompatible public static class InstanceConfiguration {
Prefix for Micronaut instance settings.
/** * Prefix for Micronaut instance settings. */
public static final String PREFIX = "instance";
Property name for Micronaut instance id.
/** * Property name for Micronaut instance id. */
public static final String INSTANCE_ID = ApplicationConfiguration.PREFIX + '.' + PREFIX + ".id"; private String id; private String group; private String zone; private Map<String, String> metadata = Collections.emptyMap();
Returns:An optional instance identifier
/** * @return An optional instance identifier */
public Optional<String> getId() { return Optional.ofNullable(id); }
Params:
  • id – The instance identifier
/** * @param id The instance identifier */
public void setId(String id) { this.id = id; }
Returns:Any metadata to associate with the instance
/** * @return Any metadata to associate with the instance */
public Map<String, String> getMetadata() { return metadata; }
Params:
  • metadata – The metadata to associate with the instance
/** * @param metadata The metadata to associate with the instance */
public void setMetadata(Map<String, String> metadata) { this.metadata = metadata; }
Returns:The instance auto scaling group
/** * @return The instance auto scaling group */
public Optional<String> getGroup() { return Optional.ofNullable(group); }
Params:
  • group – The instance auto scaling group
/** * @param group The instance auto scaling group */
public void setGroup(String group) { this.group = group; }
Returns:The instance availability zone. For example it's possible to configure Nexflix Ribbon to load balance between servers only in a particular zone
/** * @return The instance availability zone. For example it's possible to configure Nexflix Ribbon to load balance between servers only in a particular zone */
public Optional<String> getZone() { if (zone != null) { return Optional.of(zone); } return Optional.ofNullable(getMetadata().get(ServiceInstance.ZONE)); }
Params:
  • zone – The instance availability zone
/** * @param zone The instance availability zone */
public void setZone(String zone) { this.zone = zone; } } }