ServerEnvironment

public final class ServerEnvironment implements AutoCloseable

The server conditions and configuration under which the application operates.

Configuration

Some parts of the ServerEnvironment can be customized based on the EnvironmentType. To do so, one of the overloads of the use method can be called. Two environment types exist out of the box: Tests and DefaultMode. For example:


    ServerEnvironment.when(DefaultMode.class)
                     .use(productionStorageFactory)
                     .use(memoizingTracerFactory);
    ServerEnvironment.when(Tests.class)
                     .use(testingStorageFactory);

A custom environment type may also be used:


    final class StagingEnvironment extends EnvironmentType {
        ...
    }

    ServerEnvironment.when(Staging.class)
                     .use(inMemoryStorageFactory);
If Staging is enabled, the specified value is going to be returned on storageFactory.

Types

Link copied to clipboard
public interface Fn<R> implements Function<T, R>
A function which accepts a class of EnvironmentType and returns a value configured in a ServerEnvironment.
Link copied to clipboard
public class TypeConfigurator
Allows to configure values used by the ServerEnvironment for the given type.

Functions

Link copied to clipboard
public void close()
Releases resources associated with this instance.
Link copied to clipboard
public void configureDeployment(Supplier<DeploymentType> supplier)
Makes the deploymentType return the values from the provided supplier.
Link copied to clipboard
public synchronized Delivery delivery()
Returns the delivery mechanism specific to this environment.
Link copied to clipboard
public DeploymentType deploymentType()
The type of the environment application is deployed to.
Link copied to clipboard
public static ServerEnvironment instance()
Returns a singleton instance.
Link copied to clipboard
Obtains command scheduling mechanism used by CommandBus in this environment.
Link copied to clipboard
public NodeId nodeId()
Obtains the identifier of the server node, on which this code is running at the moment.
Link copied to clipboard
Returns a storage factory for the current environment, or an empty Optional if it was not configured.
Link copied to clipboard
public void reset()
This is test-only method required for cleaning of the server environment instance in tests.
Link copied to clipboard
public void scheduleCommandsUsing(Supplier<CommandScheduler> commandScheduler)
Assigns command scheduling mechanism used at this environment by all CommandBus instances.
Link copied to clipboard
Obtains the storage factory for the current environment.
Link copied to clipboard
Obtains the TracerFactory associated with the current environment, if it was set.
Link copied to clipboard
Obtains the transport factory for the current environment.
Link copied to clipboard
public Class<? extends EnvironmentType<?>> type()
Obtains the type of the current server environment.
Link copied to clipboard
public static ServerEnvironment.TypeConfigurator when(Class<? extends EnvironmentType<?>> type)
Starts flowing API chain for configuring ServerEnvironment for the passed type.