This is a concept related question.
I'm writing a program polling for alerts on various devices, there are two different type of alerts i need to poll, reds and oranges.
My approach is to create two threads, each polling their type of alerts independently. I thought about using threads because both polling functions have to be designed to be completely independent and have different time intervals for execution, for example:
- Red: query API 3 times, waits at least 30 seconds between polls ( try to avoid false positive by letting them time to clear out before doing stuff with the alerts )
- Orange: Very passive, poll once, wait 10 minutes, then poll again, compare and do stuff ( same principle as reds )
Here comes the question:
Each step of alert processing is handled via multiple classes and various methods, ie: APIQUERYCLASS class calls DATAPROCESSINGCLASS (do stuff with alerts) -> DATAPARSINGCLASS (do stuff with alerts) -> ANALYSISCLASS (do stuff with alerts) -> ESCALATIONCLASS and so on...
Each thread is going to have an object APIQUERYCLASS which will create other objects from the chain of classes and use methods.
Is that a "sane" approach ? Will threads be truly independent ? Is there a better way to make this if so how ?
EDIT:
Thanks for the answers guys To add a bit more of clarity:
######Worker.h #######
// Worker.h is the top file where i'm thinking about creating the threads
#include "ToolName.h"
class Worker
{
RedHandler()
{
Tool t_red;
t_red.GetRedAlerts();
}
OrangeHandler() // exact same thing as RedHandler()
{
Tool t_orange;
t_orange......
}
}
##### ToolName.h #####
#include "Dataprocessing.h"
class Tool
{
GetRedAlerts()
{
// query API , if query result is OK
DataProcessing d;
d.ProcessData();
}
}
##### DataProcessing.h ######
#include "DataParser.h"
class DataProcessing
{
DoStuff()
{
....
}
}
The chain is working pretty much that way all the way to escalation where it breaks ( unless exception ) and goes back to the polling in Worker.h The exact same exists for Orange alerts given that the API query returns the exact same json structure.
And i'd like to put RedHandler() and OrangeHandler() in their own threads
I hope this clarifies a bit my question