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-001: Create or just review the GDA application wrapper - GatewayDeviceApp #49

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

Comments

@labbenchstudios
Copy link
Contributor

labbenchstudios commented Jul 15, 2020

Description

  • Create a new Java class named GatewayDeviceApp.
    • NOTE: The downloaded code repository will include much of the implementation for this module. You can simply use it as is, or can create your own. If you're using the sample code, you can ignore this requirement; however, please do review the content to ensure your current implementation aligns with the functionality referenced below.

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 app and navigate to that folder.
  • Import the java.util.logging logging framework. You can import all, or just Level and Logger.
  • Create a package-scoped constructor that accepts a single parameter as follows: public GatewayDeviceApp(String[] args)
  • Add the public stopApp(int code) method, and log an info message indicating the app was stopped. Include a try / catch block to handle the stop code. On exception, log an error message along with the stack trace. Outside of the try / catch block, and as the last line of code, log an informational message with the code included.
  • Add the public startApp() method, and log an info message indicating the app was started. Include a try / catch block to handle the start code. On exception, log an error message along with the stack trace, then call stopApp(-1).
  • Add the private initConfig(String fileName) method, and log an info message indicating the method was called. It will mostly remain empty for now.
  • Add the private parseArgs(String[] args) method, and log an info message indicating the method was called. For now, the args can be ignored. Before the method exits, call initConfig(null).
  • Update the constructor to include a call to parseArgs(args).
  • Add the public static void main(String[] args) method to enable running as an application. It will create an instance of GatewayDeviceApp, call startApp(), wait 65 seconds, then call stopApp(0), as follows:
public static void main(String[] args)
{
	GatewayDeviceApp gwApp = new GatewayDeviceApp(args);
	
	gwApp.startApp();
	
	try {
		Thread.sleep(65000L);
	} catch (InterruptedException e) {
		// ignore
	}
	
	gwApp.stopApp(0);
}
  • Run all tests in the next section and ensure they work correctly. Add new tests as appropriate.

Estimate

  • Small

Tests

  • Unit tests (in ./src/test/java/programmingtheiot/part01/unit)
    • Run ./common/ConfigUtilTest. All unit tests should pass.
      Integration tests (in ./src/test/java/programmingtheiot/part01/integration)
    • Run ./app/GatewayDeviceAppTest. Integration test should pass and generate output similar to the following:
Sep 05, 2020 5:48:10 PM programmingtheiot.gda.app.GatewayDeviceApp <init>
INFO: Initializing GDA...
Sep 05, 2020 5:48:10 PM programmingtheiot.gda.app.GatewayDeviceApp parseArgs
INFO: No command line args to parse.
Sep 05, 2020 5:48:10 PM programmingtheiot.gda.app.GatewayDeviceApp initConfig
INFO: Attempting to load configuration: Default.
Sep 05, 2020 5:48:10 PM programmingtheiot.gda.app.GatewayDeviceApp startApp
INFO: Starting GDA...
Sep 05, 2020 5:48:10 PM programmingtheiot.gda.app.GatewayDeviceApp startApp
INFO: GDA started successfully.
Sep 05, 2020 5:49:15 PM programmingtheiot.gda.app.GatewayDeviceApp stopApp
INFO: Stopping GDA...
Sep 05, 2020 5:49:15 PM programmingtheiot.gda.app.GatewayDeviceApp stopApp
INFO: GDA stopped successfully with exit code 0.
@labbenchstudios labbenchstudios changed the title PIOT-GDA-02-001 PIOT-GDA-02-001: Create the GDA application wrapper - GatewayDeviceApp 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
@labbenchstudios labbenchstudios changed the title PIOT-GDA-02-001: Create the GDA application wrapper - GatewayDeviceApp PIOT-GDA-02-001: Create or just review the GDA application wrapper - GatewayDeviceApp Feb 1, 2021
@dbeavers
Copy link

"ntegration tests (in ./src/test/python/programmingtheiot/part01/integration)"
Should be java, not python!

@labbenchstudios
Copy link
Contributor Author

Good catch - fixed.

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
Programming the IoT - Exercises Kanba...
  
Lab Module 02 - Edge Tier Apps
Development

No branches or pull requests

2 participants