Instance

class Instance(configuration: GlobalConfiguration, meterSources: Collection<MeterSource> = listOf(), subsystems: Collection<Subsystem> = meterSources, simulated: SimulatedMeterSource? = null, launchTime: <Error class: unknown class> = LocalDateTime.now(), val nodeManager: NodeManager = NodeManager()) : HTTPAPI, TelnetAPI, SessionContext

Handler for the application instance. Coordinates much of the application's functionality. Significant functionality is also delegated to meters' handlers, session handlers, and the server objects.

Constructors

Link copied to clipboard
constructor(configuration: GlobalConfiguration, meterSources: Collection<MeterSource> = listOf(), subsystems: Collection<Subsystem> = meterSources, simulated: SimulatedMeterSource? = null, launchTime: <Error class: unknown class> = LocalDateTime.now(), nodeManager: NodeManager = NodeManager())

Properties

Link copied to clipboard
open override val executor: TaskExecutor
Link copied to clipboard
open override val logManager: LogManager
Link copied to clipboard
open override val nodeManager: NodeManager
Link copied to clipboard
open override val staticContentPath: <Error class: unknown class>
Link copied to clipboard
open override val webServer: Webserver

Functions

Link copied to clipboard
open fun activeMeasurement(session: Int? = null): ActiveMeasurement?

Returns the active measurement in the session. If session == null, it is the latest session.

Link copied to clipboard
open fun activeRun(session: Int? = null): ActiveRun?

Returns the active run id in the session. If session == null, it is the latest session.

Link copied to clipboard
open fun apiCallsV2(): <Error class: unknown class>
Link copied to clipboard
open override fun busy(): <Error class: unknown class>

Does this instance still have active asynchronous tasks or active sessions planning to write on disk?

Link copied to clipboard
open override fun busyLogCount(): Int

Tells how many sessions are still writing / planning to serialize their state on disk.

Link copied to clipboard
open fun close()

Only used when closing the whole application.

Link copied to clipboard
fun debug(msg: String)
Link copied to clipboard
open fun finishedMeasurements(session: Int? = null, measurement: Int? = null): List<MeasurementSummary>

Return a summary of a past measurement.

Link copied to clipboard
open fun finishedRuns(session: Int? = null, run: Int? = null): List<RunSummary>

Returns a past run id in the session. If session == null, it is the latest session.

Link copied to clipboard
open override fun freePool(): MeterHandlerPool

The pool of all the free meters associated with the instance.

Link copied to clipboard
open override fun getMqttMessages(): <Error class: unknown class>

Return a list of received MQTT messages.

Link copied to clipboard

Global configuration for this instance.

Link copied to clipboard
open override fun handleCommand(cmd: Command): JsonResponse<*>

Supports the following SystemAppCommands:

Link copied to clipboard
open fun handleGetApiV1(uri: String, parts: List<String>): <Error class: unknown class>?
Link copied to clipboard
open fun handleGetApiV2(uri: String, parts: List<String>): <Error class: unknown class>?
Link copied to clipboard
open fun handleGetRequest(uri: String): <Error class: unknown class>?

Handler for HTTP GET requests.

Link copied to clipboard
open fun handlePostApiV1(uri: String, parts: List<String>, inputStream: <Error class: unknown class>): <Error class: unknown class>?
Link copied to clipboard
open fun handlePostApiV2(uri: String, parts: List<String>, inputStream: <Error class: unknown class>): <Error class: unknown class>?
Link copied to clipboard
open fun handlePostRequest(uri: String, inputStream: <Error class: unknown class>): <Error class: unknown class>?

Handler for HTTP POST requests.

Link copied to clipboard
open override fun handleSessionEvent(event: SessionEvent, sessionId: Int?): JsonResponse<*>

Handle an event. If sessionId == null, it is the latest session.

Link copied to clipboard
open override fun handleSessionResourceEvents(events: List<ResourceConsumptionEvent>, sessionId: Int?)

A faster routine for aggregate events (collectd stream)

Link copied to clipboard
open fun handleTelnet(msg: String): String?

Handler for Telnet commands. The API is documented at https://tech.utugit.fi/soft/tools/power/doc/manual/usage/api/#telnet

Link copied to clipboard
open fun handleTriggerEvent(triggerType: TriggerType, sessionId: Int? = null): JsonResponse<*>

Handle a trigger event. If session == null, it is the latest session.

Link copied to clipboard
open override fun instance(): String

Instance id.

Link copied to clipboard

Shorter summary of the instance status. Faster to compute, for the web UI.

Link copied to clipboard
open override fun instanceSummary(): InstanceSummary

Summary data structure for the whole app setup.

Link copied to clipboard
open override fun logEntries(): List<SessionLogEntry>

Up-to-date snapshot of the log entries of the past sessions.

Link copied to clipboard
open override fun logFileCount(): Long

Tells how many ordinary files in located in the log directory. This can be an estimate and only needs to grow when a log has been serialized on disk.

Link copied to clipboard
open override fun nodeImage(resource: String): <Error class: unknown class><String, ByteArray>?

Data for displaying the images of the nodes

Link copied to clipboard
open override fun nodes(): List<NodeSummary>

Summary of external nodes associated with this instance.

Link copied to clipboard
open fun <T> ok(result: T?): JsonResponse<T>

Return a result packages in JsonResponse

Link copied to clipboard
open override fun pool(): MeterHandlerPool

The pool of all meters associated with the instance. Does not include dummy copies of the meters.

Link copied to clipboard
open override fun qrImage(resource: String): ByteArray?

Data for displaying the QR codes of the server's addresses.

Link copied to clipboard
fun restoreSession(sessionDirectory: String): Session
Link copied to clipboard
fun run()

Run the main functionality. In interactive mode, block until the user enters a new line (enter), otherwise sleep. We can't return because that will close the application.

Link copied to clipboard
open fun sendMqttMessage(topic: String, content: String): JsonResponse<*>

Send a MQTT message with the given topic and content.

Link copied to clipboard
open override fun session(id: Int?): Session

Returns the session with the given id OR latest session OR throws an exception

Link copied to clipboard
open override fun sessions(): Collection<Session>

A snapshot of currently active & inactive sessions.

Link copied to clipboard
fun shutdownHook(timeOut: Long): <Error class: unknown class>
Link copied to clipboard
open fun staticPage(uri: String): <Error class: unknown class>?
Link copied to clipboard
open fun unsupportedCommand(name: String?, type: String, uri: String? = null): JsonResponse<*>