Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIOT-GDA-02-002: Create module - SystemPerformanceManager #48

Open
labbenchstudios opened this issue Jul 15, 2020 · 4 comments
Open

PIOT-GDA-02-002: Create module - SystemPerformanceManager #48

labbenchstudios opened this issue Jul 15, 2020 · 4 comments
Labels
exercise New feature to implement as an exercise
Milestone

Comments

@labbenchstudios
Copy link
Contributor

labbenchstudios commented Jul 15, 2020

Description

  • Create the SystemPerformanceManager module.
    • NOTE: The downloaded code repository will contain a shell implementation of this module for you to work with, or you can create your own if you'd prefer.

Review the README

  • Please see README.md for further information on, and use of, this content.
  • License for embedded documentation and source codes: PIOT-DOC-LIC

Estimated effort may vary greatly

  • The estimated level of effort for this exercise shown in the 'Estimate' section below is a very rough approximation. The actual level of effort may vary greatly depending on your development and test environment, experience with the requisite technologies, and many other factors.

Actions

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

  • Create a new Java package in the programmingtheiot\gda source folder named system and navigate to that folder.
  • Import the java.util.logging logging framework. You can import all, or just Level and Logger. For example:
import java.util.logging.Logger;
import java.util.logging.Level;
  • Declare a class-scoped static logging instance:
private static final Logger _Logger = Logger.getLogger(SystemPerformanceManager.class.getName());
  • Define the following class-scoped variable (you'll add more later):
private int pollRate = ConfigConst.DEFAULT_POLL_CYCLES;
  • Create a public default constructor: public SystemPerformanceManager()
  • Within the constructor, set the following class-scoped variable value(s):
    • this.pollRate: use ConfigUtil to retrieve the integer property ConfigConst.POLL_CYCLES_KEY from the ConfigConst.GATEWAY_DEVICE config file section, with ConfigConst.DEFAULT_POLL_CYCLES as the default value.
public SystemPerformanceManager()
{
	this.pollRate =
		ConfigUtil.getInstance().getInteger(
			ConfigConst.GATEWAY_DEVICE, ConfigConst.POLL_CYCLES_KEY, ConfigConst.DEFAULT_POLL_CYCLES);
	
	if (this.pollRate <= 0) {
		this.pollRate = ConfigConst.DEFAULT_POLL_CYCLES;
	}
}
  • Add the startManager() method, and log an info message indicating manager was started.
  • Add the stopManager() method, and log an info message indicating manager was stopped.
public boolean startManager()
{
	_Logger.info("SystemPerformanceManager is starting...");
	
	return true;
}

public boolean stopManager()
{
	_Logger.info("SystemPerformanceManager is stopped.");
	
	return true;
}

Estimate

  • Small

Tests

  • Integration tests (in ./src/test/java/programmingtheiot/part01/integration)
    • Run ./system/SystemPerformanceManagerTest. Integration test should pass and generate output similar to the following:
Jul 19, 2020 12:58:42 PM programmingtheiot.gda.system.SystemPerformanceManager startManager
INFO: SystemPerformanceManager is starting...
Jul 19, 2020 12:58:42 PM programmingtheiot.gda.system.SystemPerformanceManager stopManager
INFO: SystemPerformanceManager is stopped.
@labbenchstudios labbenchstudios changed the title PIOT-GDA-02-002 PIOT-GDA-02-002: Create module - SystemPerformanceManager Jul 15, 2020
@labbenchstudios labbenchstudios self-assigned this Jul 15, 2020
@labbenchstudios labbenchstudios removed their assignment Aug 17, 2020
@labbenchstudios labbenchstudios transferred this issue from programming-the-iot/java-components Sep 7, 2020
@labbenchstudios labbenchstudios added the exercise New feature to implement as an exercise label Sep 7, 2020
@labbenchstudios labbenchstudios added this to the Chapter 02 milestone Sep 7, 2020
@dbeavers
Copy link

dbeavers commented Mar 26, 2023

Added:
import java.util.logging.Logger;
import java.util.logging.Level;
and:
private static final Logger _Logger = Logger.getLogger(SystemPerformanceManager.class.getName());

This will not resolve:
import programmingtheiot.part01.integration.system.SystemPerformanceManagerTest;

When I comment it out the test import and run the tests PyUnit just says Runs 1/1 and Finished in 60.46 secs. There is no log output printed in the console. How do I get some log output?

I am using Eclipse IDE Version: 2023-03 (4.27.0) Build id: 20230309-1520

@labbenchstudios
Copy link
Contributor Author

Added an example to the Action 'Import the java.util.logging logging framework. You can import all, or just Level and Logger.'

As the reader works through each exercise, and moves into the following lab modules, the minor detail will become less specific (e.g., an action may simply indicate 'Import the requisite module(s) / class(es)', and the focus will center on the logic details.

To run tests within the GDA project, you'll need to execute them using JUnit, not PyUnit. Once this is done, I would expect to see log output similar to the example shown within the Console tab of Eclipse (other IDE's may have a different mechanism for displaying console output of course).

@dbeavers
Copy link

I should have said that I was using JUnit. So any suggestions on why I don't get any output from the test run.

Did you want to add private static final Logger _Logger = Logger.getLogger(SystemPerformanceManager.class.getName()); also?

@labbenchstudios
Copy link
Contributor Author

Added logger declaration into sample code.

As for logging within the console, there could be a number of reasons why log messages aren't showing up. Here are a few things to consider:

  • Check if the console buffer size is sufficient (in Eclipse Preferences, review check Run/Debug -> Console).
  • Check if the logging infrastructure's configuration file is setup to log to console.
  • Check the default level. If you're getting some log messages, but not others, the logging level may be too restrictive - if so, check the java.util.logging.Logger documentation (last I checked, you can use the setLevel(Level someLevel) method to change the level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exercise New feature to implement as an exercise
Projects
Status: Lab Module 02 - Edge Tier Apps
Status: Lab Module 02 - System Performance
Development

No branches or pull requests

2 participants