PDA

View Full Version : Tomcat - Binding to an IP address dynamically


ranjit
24-12-2008, 10:42
Hi,

I am using Tomcat version 5.5.23.
I have a requirement which says that Tomcat should bind to a particular IP
when it is accessible.

The IP will not be available when Tomcat starts up but still configured in server.xml.

Currently I do a stop/start of Tomcat to bind to the IP when it becomes accessible.

But Is there any way by which I can bind tomcat to the partcular IP without stop/start of tomcat.

Is it possible to bind tomcat to this IP dynamically.

Could you please help me out, my server.xml looks like,

<Connector port="4085" address="test1.logical" acceptCount="10"
connectionTimeout="30000" debug="0"
disableUploadTimeout="true" enableLookups="false"
maxSpareThreads="75" maxThreads="150" minSpareThreads="25"
/>

test1.logical is the ip address which will not be available all the time.

Please suggest your thoughts.

kjkoster
24-12-2008, 11:14
Dear ranjit,

Have you considered altering Tomcat's start script so that it waits for the address to become available?

Could you tell us a little more about how and when the address is created? Is that scripted?

If the address goes away, what is Tomcat expected to do?

Kees Jan

ranjit
24-12-2008, 13:27
Hi Jan,

Thanks a lot for replying.
We have a platform layer which actually gives access to this IP.
This IP might come up at any time, so we wont be able to put any wait in tomcat start script.

Actually certain applications of mine are expected to be running on the system(IP and Port) when IP becomes accessible.

There is a task which indicates the webserver when this ip comes up(we call it active).
So if i receive this update, I do a stop/start of the webserver.

But can this binding be done without stop/start of tomcat.
I want my application to run on this IP and Port without stop/start.

Really appreciate your effort.
Thanks once again.

kjkoster
24-12-2008, 14:30
Dear ranjit,

Hmm. There is a JMX mbean for each connector. They can easily be controlled from (for example) jconsole.

If they can be manipulated through JConsole to be started and stopped at the right moment, you can most certainly control them programmatically.

Are you familiar with JMX and JConsole?

Kees Jan

PS It does sound to me that you guys have created a very complicated architecture. There must be a more standard way to achieve what you guys want to achieve.

ranjit
05-01-2009, 11:17
Hi Jan,

I am not familiar with JMX and JConsole.
Can we write a program using JMX so that we can make tomcat to bind to the IP whenever IP is accessible without stop/start.

could you please provide me an example?

consider the port 4085 and IP test1.logical

How would i use JMX?

Thanks a lot for ur help.

-Ranjit.

kjkoster
05-01-2009, 13:12
Dear Ranjit,

Have a look at http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html

Kees Jan

kjkoster
13-01-2009, 21:49
Dear Ranjit,

I wrote some sample code to show how easy it is to restart a Tomcat connector from code (http://java-monitor.com/forum/showthread.php?t=169). Perhaps you can adapt this code to solve your problem too?

Kees Jan

ranjit
20-01-2009, 14:27
Hi Jan,

Thanks a lot...
I will try this out...

Thanks,
Ranjit.