Warning

 

Close
Confirm Action

Are you sure you wish to do this?

Cancel Confirm
AR15.COM
9/7/2008 7:45:12 PM EDT
Have any of you done something like this and do you have sample code (i don't need c or java source, but pseudo code. though, java code would be fine)

Suppose I have an application that is running, that has
been initialized and is going about its business executing control
logic etc... Suppose I wish to change the application configuration,
say change some timing parameters or have it not accept new work and finish existing work.

anyone written anything like that?  use telnet to connect to the process and administer it?

9/7/2008 7:49:28 PM EDT
[#1]
Are these config details parameterized into variables?

So you change a value and (optional) rewrite a config file if you want the config change permanent.  What am I missing about your question?
9/7/2008 7:54:46 PM EDT
[#2]
I have never written anything like that, but I thought of two things off the top of my head:

1. Have a file that your software reads from periodically, and you change parameters in the file. Things could get weird if you change the file while the program is reading from it. So this might be a better way....

2. Add a process that monitors STDIN for commands to change the parameters. This way you can just type stuff in telnet rather than having to use a text file and all that stuff.
9/7/2008 8:11:38 PM EDT
[#3]
So, not sure what you're really asking, but

Maybe you're asking about IPC (interprocess communication)?  Gonna vary by platform.

If you're going to use a separate file to read/write from, don't forget flock(), and do the background reading for it on your platform, so that you have something atomic or very solid, and not prone to race conditions.

Poking configs via telnet is a good way to get sniffed/screwed.  Of course, you know the environment where this will run; I don't and assume an insecure network.

If it's REALLY just about changing a config value that's sitting in a file somewhere,
- You read them in initially at runtime and I'm going to assume they're modifiable in the running process.
- If you want to write a new config, just do it, but use file locking.
- If you want to detect a new config, you can always just check the timestamp of the config file against the time your process started.  A newer value indicates an updated config.
9/7/2008 8:23:49 PM EDT
[#4]
If this is a unix program, this is typically done with the HUP (hangup) signal.  You'll want to include the signal.h header in your code.  There are examples on the net for catching unix signals, just google.  
9/7/2008 8:24:17 PM EDT
[#5]
Lots of ways to do that.

Do you want this to happen at startup time or some time after the process has been running?  Both have similarities.

You probably would want to setup a property file.  Lots of good utility code from apache and other places to look for.  The question is how do you know to access it.  Some of the utility code monitors the file (like in Tomcat) looking for a change in the file last saved time and then re-reads it.  You have to deal with it programatically.  

The other way is to use some sort of middleware to send an event to the process either telling it to re-read its properties or actually send the property in the message event itself.  
9/7/2008 8:31:16 PM EDT
[#6]
Changing control logic for machinery can be tricky and even deadly.  You need to get a lot more detail before even thinking about changing anything.
9/7/2008 8:32:47 PM EDT
[#7]
I believe the observer pattern could be of use.

Here is a bit of Ruby from Oreilley.com using the 'Observer' module
#######################################
require 'observer'
class MyObservableClass
 include Observable

 def blah
   changed  # note that our state has changed
   notify_observers( 5 )
 end
end

class MyObserverClass
 def update(new_data)  # Key step 3
   puts "The new data is #{new_data}"
 end
end

watcher = MyObservableClass.new
watcher.add_observer(MyObserverClass.new)
#######################################

For this example you would do something like
a = MyObservableClass.new
a.blah

and you should see
The new data is 5


I'm not sure exactly what your trying to do so GL.
9/7/2008 8:33:07 PM EDT
[#8]
Learned about config files and variables yet?
9/7/2008 9:00:40 PM EDT
[#9]
what i'm trying to do is something like what one finds when configuring a cisco router.
one telnets into the device, change it's config while the thing is doing work, but the device does not need restarting for the changes to become effective.

something modeled on the observer pattern is probably what i'll use, but i was hoping for sample code so I don't have to reinvent the wheel.
9/8/2008 9:12:42 PM EDT
[#10]
Want to change things remotely?

Protocol?  HTTP?  Something else?

You running an app server or pojo?
9/8/2008 9:35:19 PM EDT
[#11]
If you want to home roll it, have a server socket listening on a port that you've opened through the host firewall. It accepts TCP connections. The rock-simple thing to do is have it accept text commands. If you're doing Java, the ServerSocket returns a Socket object, which has Input and Output streams.

Set up the input stream to accept text commands. The socket code runs in its own thread. Gets a text command, interprets it, and changes the config parameter. On the client side you can simply telnet in and send the text command. The simplest and most robust thing to do is to accept one command and close down the socket. Done right this should be less than 100 lines of code.

If you're running it on the Big Internet this is a Bad Idea since there is no security.

JMX if you want to get fancy. If you're really stylin' you can put a web interface on it with an embedded servlet container and web server.