valueFor(Class extends EnvironmentType> type) {
checkNotNull(type);
V result = this.environmentValues.get(type);
diff --git a/server/src/main/java/io/spine/server/ServerEnvironment.java b/server/src/main/java/io/spine/server/ServerEnvironment.java
index 00d9ae771af..16589e0ada0 100644
--- a/server/src/main/java/io/spine/server/ServerEnvironment.java
+++ b/server/src/main/java/io/spine/server/ServerEnvironment.java
@@ -23,12 +23,12 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.spine.annotation.Internal;
+import io.spine.base.CustomEnvironmentType;
import io.spine.base.Environment;
import io.spine.base.EnvironmentType;
import io.spine.base.Identifier;
import io.spine.base.Production;
import io.spine.base.Tests;
-import io.spine.reflect.Invokables;
import io.spine.server.commandbus.CommandScheduler;
import io.spine.server.commandbus.ExecutorCommandScheduler;
import io.spine.server.delivery.Delivery;
@@ -78,7 +78,6 @@
* If {@code Staging} is {@link Environment#type() enabled}, the specified value is going to be
* returned on {@link #storageFactory()}.
*/
-@SuppressWarnings("ClassWithTooManyMethods" /* deprecated methods to be eliminated later. */)
public final class ServerEnvironment implements AutoCloseable {
private static final ServerEnvironment INSTANCE = new ServerEnvironment();
@@ -104,7 +103,7 @@ public final class ServerEnvironment implements AutoCloseable {
* The strategy of delivering the messages received by entity repositories
* to the entity instances.
*
- * If not {@linkplain #use(Delivery, EnvironmentType)}) configured by the end-user},
+ *
If not {@linkplain TypeConfigurator#use(Delivery) configured by the end-user},
* initialized with the {@linkplain Delivery#local() local} delivery by default.
*
*
Differs between {@linkplain EnvironmentType environment types}.
@@ -151,6 +150,16 @@ public static ServerEnvironment instance() {
return INSTANCE;
}
+ /**
+ * Obtains the type of the current server environment.
+ *
+ * @apiNote This is a convenience method for server-side configuration code, which
+ * simply delegates to {@link Environment#type()}.
+ */
+ public Class extends EnvironmentType> type() {
+ return Environment.instance().type();
+ }
+
/**
* The type of the environment application is deployed to.
*/
@@ -161,7 +170,7 @@ public DeploymentType deploymentType() {
/**
* Returns the delivery mechanism specific to this environment.
*
- *
Unless {@linkplain #use(Delivery, EnvironmentType) updated manually}, returns
+ *
Unless {@linkplain TypeConfigurator#use(Delivery) updated manually}, returns
* a {@linkplain Delivery#local() local implementation} of {@code Delivery}.
*/
public synchronized Delivery delivery() {
@@ -224,122 +233,6 @@ public void configureDeployment(Supplier supplier) {
deploymentDetector = supplier;
}
- /**
- * Assigns the specified {@code TransportFactory} for the specified application environment.
- *
- * @return this instance of {@code ServerEnvironment}
- * @deprecated please use {@link #when(Class) when(Class extends EnvironmentType>)}
- * followed by {@link TypeConfigurator#use(StorageFactory) use(StorageFactory)}
- */
- @Deprecated
- @CanIgnoreReturnValue
- public ServerEnvironment use(StorageFactory factory, EnvironmentType envType) {
- checkNotNull(factory);
- SystemAwareStorageFactory wrapped = wrap(factory);
- storageFactory.registerTypeAndUse(envType, wrapped);
- return this;
- }
-
- /**
- * Assigns the specified {@code TransportFactory} for the specified application environment.
- *
- * @return this instance of {@code ServerEnvironment}
- * @deprecated please use {@link #when(Class) when(Class extends EnvironmentType>)}
- * followed by {@link TypeConfigurator#use(StorageFactory) use(StorageFactory)}
- */
- @Deprecated
- @CanIgnoreReturnValue
- public ServerEnvironment use(StorageFactory factory, Class extends EnvironmentType> type) {
- checkNotNull(factory);
- SystemAwareStorageFactory wrapped = wrap(factory);
- storageFactory.use(wrapped, type);
- return this;
- }
-
- /**
- * Assigns the specified {@code Delivery} for the selected environment.
- *
- * @return this instance of {@code ServerEnvironment}
- * @deprecated please use {@link #when(Class) when(Class extends EnvironmentType>)}
- * followed by {@link TypeConfigurator#use(Delivery) use(Delivery)}
- */
- @Deprecated
- @CanIgnoreReturnValue
- public ServerEnvironment use(Delivery delivery, EnvironmentType envType) {
- this.delivery.registerTypeAndUse(envType, delivery);
- return this;
- }
-
- /**
- * Assigns the specified {@code Delivery} for the selected environment.
- *
- * @return this instance of {@code ServerEnvironment}
- * @deprecated please use {@link #when(Class) when(Class extends EnvironmentType>)}
- * followed by {@link TypeConfigurator#use(Delivery) use(Delivery)}
- */
- @Deprecated
- @CanIgnoreReturnValue
- public ServerEnvironment use(Delivery delivery, Class extends EnvironmentType> envType) {
- this.delivery.use(delivery, envType);
- return this;
- }
-
- /**
- * Assigns {@code TracerFactory} for the specified application environment.
- *
- * @return this instance of {@code ServerEnvironment}
- * @deprecated please use {@link #when(Class) when(Class extends EnvironmentType>)}
- * followed by {@link TypeConfigurator#use(TracerFactory) use(TracerFactory)}
- */
- @Deprecated
- @CanIgnoreReturnValue
- public ServerEnvironment use(TracerFactory factory, EnvironmentType envType) {
- tracerFactory.registerTypeAndUse(envType, factory);
- return this;
- }
-
- /**
- * Assigns {@code TracerFactory} for the specified application environment.
- *
- * @return this instance of {@code ServerEnvironment}
- * @deprecated please use {@link #when(Class) when(Class extends EnvironmentType>)}
- * followed by {@link TypeConfigurator#use(TracerFactory) use(TracerFactory)}
- */
- @Deprecated
- @CanIgnoreReturnValue
- public ServerEnvironment use(TracerFactory factory, Class extends EnvironmentType> envType) {
- tracerFactory.use(factory, envType);
- return this;
- }
-
- /**
- * Configures the specified transport factory for the selected type of environment.
- *
- * @return this instance of {@code ServerEnvironment}
- * @deprecated please use {@link #when(Class) when(Class extends EnvironmentType>)}
- * followed by {@link TypeConfigurator#use(TransportFactory) use(TransportFactory)}
- */
- @Deprecated
- @CanIgnoreReturnValue
- public ServerEnvironment use(TransportFactory factory, EnvironmentType envType) {
- transportFactory.registerTypeAndUse(envType, factory);
- return this;
- }
-
- /**
- * Configures the specified transport factory for the selected type of environment.
- *
- * @return this instance of {@code ServerEnvironment}
- * @deprecated please use {@link #when(Class) when(Class extends EnvironmentType>)}
- * followed by {@link TypeConfigurator#use(TransportFactory) use(TransportFactory)}
- */
- @Deprecated
- @CanIgnoreReturnValue
- public ServerEnvironment use(TransportFactory factory, Class extends EnvironmentType> type) {
- transportFactory.use(factory, type);
- return this;
- }
-
/**
* Obtains the {@link TracerFactory} associated with the current environment, if it was set.
*/
@@ -442,21 +335,29 @@ public static class TypeConfigurator {
private TypeConfigurator(Class extends EnvironmentType> type) {
this.se = instance();
- EnvironmentType et = Invokables.callParameterlessCtor(type);
- Environment.instance()
- .register(et);
+ if (CustomEnvironmentType.class.isAssignableFrom(type)) {
+ registerCustomType(type);
+ }
this.type = checkNotNull(type);
}
+ private static void registerCustomType(Class extends EnvironmentType> type) {
+ @SuppressWarnings("unchecked") // checked by calling site.
+ Class extends CustomEnvironmentType> customType =
+ (Class extends CustomEnvironmentType>) type;
+ Environment.instance()
+ .register(customType);
+ }
+
/**
* Assigns the specified {@code Delivery} for the selected environment.
*
- * @see #useDelivery(Fn)
+ * @see #useDelivery(ServerEnvironment.Fn)
*/
@CanIgnoreReturnValue
public TypeConfigurator use(Delivery delivery) {
checkNotNull(delivery);
- se.use(delivery, type);
+ se.delivery.use(delivery, type);
return this;
}
@@ -478,7 +379,7 @@ public TypeConfigurator useDelivery(Fn fn) {
/**
* Assigns {@code TracerFactory} for the selected environment.
*
- * @see #useTracerFactory(Fn)
+ * @see #useTracerFactory(ServerEnvironment.Fn)
*/
@CanIgnoreReturnValue
public TypeConfigurator use(TracerFactory factory) {
@@ -505,7 +406,7 @@ public TypeConfigurator useTracerFactory(Fn fn) {
/**
* Assigns the specified transport factory for the selected environment.
*
- * @see #useTransportFactory(Fn)
+ * @see #useTransportFactory(ServerEnvironment.Fn)
*/
@CanIgnoreReturnValue
public TypeConfigurator use(TransportFactory factory) {
@@ -530,9 +431,9 @@ public TypeConfigurator useTransportFactory(Fn fn) {
}
/**
- * Assigns the specified {@code TransportFactory} for the selected environment.
+ * Assigns the specified {@code StorageFactory} for the selected environment.
*
- * @see #useStorageFactory(Fn)
+ * @see #useStorageFactory(ServerEnvironment.Fn)
*/
@CanIgnoreReturnValue
public TypeConfigurator use(StorageFactory factory) {
diff --git a/server/src/test/java/io/spine/server/ServerEnvironmentTest.java b/server/src/test/java/io/spine/server/ServerEnvironmentTest.java
index 2ee740d9f69..f47c746721b 100644
--- a/server/src/test/java/io/spine/server/ServerEnvironmentTest.java
+++ b/server/src/test/java/io/spine/server/ServerEnvironmentTest.java
@@ -20,6 +20,7 @@
package io.spine.server;
+import io.spine.base.Environment;
import io.spine.base.EnvironmentType;
import io.spine.base.Production;
import io.spine.base.Tests;
@@ -195,11 +196,18 @@ private void testClosesEnv(Class extends EnvironmentType> envType) throws Exce
}
}
+ @Test
+ @DisplayName("obtain the current environment type")
+ void gettingType() {
+ assertThat(serverEnvironment.type())
+ .isSameInstanceAs(Environment.instance()
+ .type());
+ }
+
@SuppressWarnings({
"AccessOfSystemProperties" /* Testing the configuration loaded from System properties. */,
"AbstractClassWithoutAbstractMethods" /* A test base with setUp and tearDown. */
})
-
abstract class WithAppEngineEnvironment {
private final String targetEnvironment;
diff --git a/version.gradle.kts b/version.gradle.kts
index 54dbca33cf2..08530a76e34 100644
--- a/version.gradle.kts
+++ b/version.gradle.kts
@@ -34,12 +34,12 @@
/**
* Version of this library.
*/
-val coreJava = "1.6.15"
+val coreJava = "1.6.16"
/**
* Versions of the Spine libraries that `core-java` depends on.
*/
-val base = "1.6.13"
+val base = "1.6.14"
val time = "1.6.13"
project.extra.apply {