Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Tarun - 12 May 2006 17:41 GMT
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.
Oliver Wong - 12 May 2006 19:43 GMT
> Hi there,
> I have a query regarding xml and java:
[quoted text clipped - 10 lines]
>    timeout="30"
> </FTP>

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

<FTP ftpDir="\somepath" timeout="30"/>

> 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
[quoted text clipped - 9 lines]
> ############
> 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."
>
[quoted text clipped - 10 lines]
> 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
Tarun - 13 May 2006 01:14 GMT
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 ...
Oliver Wong - 13 May 2006 14:28 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.