Package com.exonum.binding.core.runtime
Class ServiceRuntime
- java.lang.Object
-
- com.exonum.binding.core.runtime.ServiceRuntime
-
public final class ServiceRuntime extends Object
A service runtime. It manages the services required for operation of Exonum services (e.g., aServer
; allows the native code to load and unload artifacts (JAR archives with Exonum services), create and stop services defined in the loaded artifacts.This class is thread-safe and does not support client-side locking. The thread-safety is provided because the class is a singleton and may be provided to other objects. Currently, however, there is a single injection point where ServiceRuntime is instantiated (during bootstrap) and it is used by the native runtime only in a single-threaded context, hence thread-safety isn't strictly required, but rather provided to avoid possible errors if it is ever accessed by other objects.
-
-
Constructor Summary
Constructors Constructor Description ServiceRuntime(com.google.inject.Injector frameworkInjector, com.exonum.binding.core.runtime.ServiceLoader serviceLoader, Server server, int serverPort)
Creates a new runtime with the given framework injector.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description UserServiceAdapter
createService(String artifactId)
Creates a new service instance of the given type.String
loadArtifact(String serviceArtifactPath)
Loads an artifact from the specified location.
-
-
-
Constructor Detail
-
ServiceRuntime
@Inject public ServiceRuntime(com.google.inject.Injector frameworkInjector, com.exonum.binding.core.runtime.ServiceLoader serviceLoader, Server server, int serverPort)
Creates a new runtime with the given framework injector. Starts the server on instantiation; never stops it.- Parameters:
frameworkInjector
- the injector that has been configured with the Exonum framework bindings. It serves as a parent for service injectorsserviceLoader
- a loader of service artifactsserver
- a web server providing transport to Java servicesserverPort
- a port for the web server providing transport to Java services
-
-
Method Detail
-
loadArtifact
public String loadArtifact(String serviceArtifactPath) throws ServiceLoadingException
Loads an artifact from the specified location. The loading involves verification of the artifact (i.e., that it is a valid Exonum service; includes a valid service factory).- Parameters:
serviceArtifactPath
- a filesystem path from which to load the service artifact- Returns:
- a unique service artifact identifier that must be specified in subsequent operations with it
- Throws:
ServiceLoadingException
- if it failed to load an artifact; or if the given artifact is already loaded
-
createService
public UserServiceAdapter createService(String artifactId)
Creates a new service instance of the given type.- Parameters:
artifactId
- a unique identifier of the loaded artifact- Returns:
- a new service
- Throws:
IllegalArgumentException
- if the artifactId is unknownRuntimeException
- if it failed to instantiate the service
-
-