programming-the-iot / book-exercise-tasks

This repo is for issues / tasks ONLY. All programming and related exercises for each chapter of 'Programming the Internet of Things' are listed here.
Other
11 stars 12 forks source link

PIOT-GDA-02-003: Connect SystemPerformanceManager to GatewayDeviceApp #45

Open labbenchstudios opened 4 years ago

labbenchstudios commented 4 years ago

Description

Review the README

Estimated effort may vary greatly

Actions

NOTE: The implementation examples depicted here are only one way to implement the requirements listed. Your own implementation may vary of course.

public GatewayDeviceApp(String[] args) { super();

_Logger.info("Initializing GDA...");

this.sysPerfMgr = new SystemPerformanceManager();

}


- Edit the `startApp()` method: Add a call to `sysPerfManager.startManager()`.
- Edit the `stopApp()` method: Add a call to `sysPerfManager.stopManager()`.
```java
public void startApp()
{
    _Logger.info("Starting GDA...");

    try {
        if (this.sysPerfMgr.startManager()) {
            _Logger.info("GDA started successfully.");
        } else {
            _Logger.warning("Failed to start system performance manager!");

            stopApp(-1);
        }
    } catch (Exception e) {
        _Logger.log(Level.SEVERE, "Failed to start GDA. Exiting.", e);

        stopApp(-1);
    }
}

public void stopApp(int code)
{
    _Logger.info("Stopping GDA...");

    try {
        if (this.sysPerfMgr.stopManager()) {
            _Logger.log(Level.INFO, "GDA stopped successfully with exit code {0}.", code);
        } else {
            _Logger.warning("Failed to stop system performance manager!");
        }
    } catch (Exception e) {
        _Logger.log(Level.SEVERE, "Failed to cleanly stop GDA. Exiting.", e);
    }

    System.exit(code);
}

NOTE: Additional functionality will be added in a later chapter.

Estimate

Tests

dbeavers commented 1 year ago

Added: import programmingtheiot.gda.system.SystemPerformanceManager;

labbenchstudios commented 1 year ago

Added clarification.

htayyar commented 1 month ago

Parsing of argument is missing. Should be as follows

public GatewayDeviceApp(String[] args) { super();

    _Logger.info("Initializing GDA...");

    parseArgs(args);

    this.sysPerfMgr = new SystemPerformanceManager();
}
labbenchstudios commented 1 month ago

Correct. Currently, command line arg parsing is an optional activity and not implemented as part of the Lab Module exercises. For those who'd like to incorporate this, please feel free to do so in your repo!