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 Production. For example:


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