How to change the configuration parameters of a java application at runtime

T

Tarun

Hi there,
I have a query regarding xml and java:
Please guide.
Scenario is like this:
I have a few configuration parameters in an xml file that I need to
read when I am starting my java application(RMI server application).
So, I read xml parameters using DOM APIs and I am creating a java
object per element.
that is, lets say I have an element called FTP in xml file with
attributes say ftp directory and time out interval.
<FTP>
ftpDir="\somepath"
timeout="30"
</FTP>
So, I read them and put them into an object of type FTPSetting.java
where I have these 2 attributes as instance variables and setter and
getter methods for them.
something like
############
private String ftpDir;
private int ftpTimeOut;
getFtpDir()
getTimeOut()
setFtpDir()
setTimeOut()
############
Is this approach fine?
Info: "The application is an RMI application."

2. Next, I have to have a utility to change these parameters at
runtime.
For that, I am creating a simple client class that looks up for the
sever class in RMI registry (a simple lookup call) and then depending
upon the parameter name and value provided to this class thru command
line, I call the modify function of server class that in turn calls the
setter function of the FTPSetting class for that particular attribute.
i.e.,
if "ftpDir" and "<some path>" are provided as command line arguments, I
call the modifyConfigParam(paramName, paramValue) function of server
class that in turn calls the setFtpDir() of FtpSettings.java.
Will this suffice to change the parameter value at runtime?

A quick response will be highly acknowledged.
 
O

Oliver Wong

Tarun said:
Hi there,
I have a query regarding xml and java:
Please guide.
Scenario is like this:
I have a few configuration parameters in an xml file that I need to
read when I am starting my java application(RMI server application).
So, I read xml parameters using DOM APIs and I am creating a java
object per element.
that is, lets say I have an element called FTP in xml file with
attributes say ftp directory and time out interval.
<FTP>
ftpDir="\somepath"
timeout="30"
</FTP>

Just FYI, these are not attributes in the XML sense. You'd rather need
something like:

So, I read them and put them into an object of type FTPSetting.java
where I have these 2 attributes as instance variables and setter and
getter methods for them.
something like
############
private String ftpDir;
private int ftpTimeOut;
getFtpDir()
getTimeOut()
setFtpDir()
setTimeOut()
############
Is this approach fine?

You'd probably want to add parameters to the setFtpDir and setTimeOut
methods, to accept the new values for the ftpdir and the timeout.

Info: "The application is an RMI application."

2. Next, I have to have a utility to change these parameters at
runtime.
For that, I am creating a simple client class that looks up for the
sever class in RMI registry (a simple lookup call) and then depending
upon the parameter name and value provided to this class thru command
line, I call the modify function of server class that in turn calls the
setter function of the FTPSetting class for that particular attribute.
i.e.,
if "ftpDir" and "<some path>" are provided as command line arguments, I
call the modifyConfigParam(paramName, paramValue) function of server
class that in turn calls the setFtpDir() of FtpSettings.java.
Will this suffice to change the parameter value at runtime?

I don't see why not.

- Oliver
 
T

Tarun

hey Oliver,
thanks a lot for the response ...and yes, I realise the change I need
make to the xml file .. thanks a lot for pointing that out ....
well while this approach works fine I have another query ...
Is there any other way I can read these xml parameters to my
application .... i mean rather then storing them in java objects like
FtpSettings.java thru setter and getter methods ... is there any other
way that I can have these parameters read from the xml file into my
application .... some sort of properties !!!! well i am just guessing
this and I do not have any idea about the properties ... but i want to
know if i can have these parameters accessible in my server and that i
should be able to change them thru a client without having to restart
the server ....
thanks for the reply again ...
 
O

Oliver Wong

Tarun said:
Is there any other way I can read these xml parameters to my
application .... i mean rather then storing them in java objects like
FtpSettings.java thru setter and getter methods ... is there any other
way that I can have these parameters read from the xml file into my
application

For your application to actually act on the settings, they have to be in
memory somewhere. Whether the in-memory representation is a custom Java
object with setters and getters, or a hashmap or some other datastructure is
up to you.

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top