Best practices question

To get things started, I am re-writing an application that I originally wrote in perl. So I am some what sticking with the same concept as I did for the perl version. This application uses multithreading in order to handle multiple configurations and data streams.

At this point, I have my base framework working well and the only thing left for me to do is to write the threading for the multiple configurations. Which is where my question comes into play.

In order to load a configuration/launch a new thread I need to connect to a sql database and use the information provided to create a configuration/thread. So my question is what would be the best way to globally store/handle the configuration data I receive back from my sql query.

I have a bit of pesudo code that shows the flow order of my application

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
start >
    loadConfig(); // load .ini file for initial db config
    
    queryConfig();  // query config/instance table for datasources/file paths/rets auth info
		   // store this data 

    loop over query {
	startDaemon{
	    re-initDb()	    // if db exists do nothing, else create database
	    re-initTables()    // if tables exist do nothing, else create tables for instance
	    re-initFields()    // if field mapping exists do nothing, else create new maps
	    startThreads{
		createRETSSession()    // create new rets session
		parseMetaData()    // parse meta data return vector array
		parseRETSData()    // parse retreived rets data
		parseGetObject(key_field)    // parse objects from rets server (image, video)
	    } // join threads blah blah blah		
	} 
    }

Last edited on
it's a little hard to tell exactly what you need to do with the data, but based on what I think is you're looking for; I would write a class that would contain all the configuration data, then declare a global class object. If only your main thread is going to need direct access to this variable, don't declare it globally, declare it in your 'Main'. Then, you can change/access that data as necessary.
There are two sets of data that I will need to work with. The first is the database connection information (username, hostname, password). The second is thread specific data (database name, file storage path, webservice auth info, etc..., )

So the first set of data would need to be declared globally (already have this part done), but the second set of data needs to be declared to the thread only.
i would still do it using object oriented design. I would think you could accomplish what you need by creating a class for each (i.e. a 'Connection' class and a 'Specific' class or something ) then declaring instantiations of each with whatever scope you desire.
Topic archived. No new replies allowed.