-
Notifications
You must be signed in to change notification settings - Fork 4
Improve environment #594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Improve environment #594
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a310a55
Hide static constant
alexander-yevsyukov 4e9bbd5
Update config
alexander-yevsyukov bc08f36
Bump version
alexander-yevsyukov 9d884ac
Section headers markup
alexander-yevsyukov 902ec4d
Turn of HTML lint warning
alexander-yevsyukov 3375891
Expose list of test f/w packages via method
alexander-yevsyukov 4519d53
Remove deprecated API
alexander-yevsyukov 33e4c66
Auto-updated
alexander-yevsyukov 075fc52
Migrate calls to class-based API
alexander-yevsyukov cdc6dda
Fix Javadoc link
alexander-yevsyukov 6a584a2
Improve names
alexander-yevsyukov 58e2912
Introduce custom env. types
alexander-yevsyukov b06bf60
Introduce standard env. types
alexander-yevsyukov c9161ed
Make package-private
alexander-yevsyukov fea182f
Update dependencies
alexander-yevsyukov dc9c7f1
Improve Javadoc
alexander-yevsyukov 4877762
Remove extra line
alexander-yevsyukov fbbd49b
Fix Javadoc example
alexander-yevsyukov c0193f4
Use default Kotlin style
alexander-yevsyukov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
76 changes: 76 additions & 0 deletions
76
base/src/main/java/io/spine/base/CustomEnvironmentType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * Copyright 2020, TeamDev. All rights reserved. | ||
| * | ||
| * Redistribution and use in source and/or binary forms, with or without | ||
| * modification, must retain the above copyright notice and the following | ||
| * disclaimer. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
|
|
||
| package io.spine.base; | ||
|
|
||
| /** | ||
| * Abstract base for custom environment types. | ||
| ** | ||
| * <p>{@code Environment} allows to {@link Environment#register(Class) register custom types}. | ||
| * In this case the environment detection functionality iterates over all known types, starting | ||
| * with those registered by the framework user: | ||
| * | ||
| * <pre> | ||
| * | ||
| * public final class Application { | ||
| * | ||
| * static { | ||
| * Environment.instance() | ||
| * .register(new Staging()) | ||
| * .register(new LoadTesting()); | ||
| * } | ||
| * | ||
| * private final ConnectionPool pool; | ||
| * | ||
| * private Application() { | ||
| * Environment environment = Environment.instance(); | ||
| * if (environment.is(Tests.class) { | ||
| * // Single connection is enough for tests. | ||
| * this.pool = new ConnectionPoolImpl(PoolCapacity.of(1)); | ||
| * } else { | ||
| * if(environment.is(LoadTesting.class) { | ||
| * this.pool = | ||
| * new ConnectionPoolImpl(PoolCapacity.fromConfig("load_tests.yml")); | ||
| * } else { | ||
| * this.pool = | ||
| * new ConnectionPoolImpl(PoolCapacity.fromConfig("cloud_deployment.yml")); | ||
| * } | ||
| * } | ||
| * //... | ||
| * } | ||
| * } | ||
| * </pre> | ||
| * | ||
| * <p><b>When registering custom types, please ensure</b> their mutual exclusivity. | ||
| * If two or more environment types {@linkplain EnvironmentType#enabled() consider themselves | ||
| * enabled} at the same time, the behaviour of {@link Environment#is(Class)} is undefined. | ||
| */ | ||
| public abstract class CustomEnvironmentType extends EnvironmentType { | ||
|
|
||
| /** | ||
| * Custom environment types must have a public no-arg constructor. | ||
| * | ||
| * <p>This constructor is used by {@link Environment} upon | ||
| * the {@linkplain Environment#register(Class) registration}. | ||
| */ | ||
| protected CustomEnvironmentType() { | ||
| super(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.