asmuts 2005/06/06 07:10:27
Modified: src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery
UDPDiscoveryService.java
Log:
UDP connections were not getting closed in the UDP discovery process.
I fixed the problem.
The number of file handles stays constant on countless reconnects and
broadcasts.
Will do more long term testing.
Revision Changes Path
1.3 +35 -21
jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryService.java
Index: UDPDiscoveryService.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryService.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- UDPDiscoveryService.java 4 Jun 2005 02:01:53 -0000 1.2
+++ UDPDiscoveryService.java 6 Jun 2005 14:10:27 -0000 1.3
@@ -47,9 +47,9 @@
private LateralCacheAttributes lca = null;
private UDPDiscoverySenderThread sender = null;
-
+
private String hostAddress = "unknown";
-
+
/**
*
* @param facade
@@ -62,7 +62,7 @@
//this.facade = facade;
this.lca = lca;
-
+
try
{
// todo, you should be able to set this
@@ -83,8 +83,8 @@
//receiver = new UDPDiscoveryReceiver( facade,
// lca.getUdpDiscoveryAddr(), lca.getUdpDiscoveryPort() );
receiver = new UDPDiscoveryReceiver( this,
lca.getUdpDiscoveryAddr(), lca.getUdpDiscoveryPort() );
- Thread t = new Thread( receiver );
- t.setDaemon( true );
+ Thread t = new Thread(receiver);
+ t.setDaemon(true);
t.start();
}
catch ( Exception e )
@@ -99,11 +99,11 @@
daemon = new ClockDaemon();
daemon.setThreadFactory( new MyThreadFactory() );
}
-
+
// create a sender thread
- sender = new UDPDiscoverySenderThread( lca.getUdpDiscoveryAddr(),
lca.getUdpDiscoveryPort(), hostAddress, lca
- .getTcpListenerPort(), this.getCacheNames() );
-
+ sender = new UDPDiscoverySenderThread( lca.getUdpDiscoveryAddr(), lca
+ .getUdpDiscoveryPort(), hostAddress,
lca.getTcpListenerPort(), this.getCacheNames() );
+
daemon.executePeriodically( 30 * 1000, sender, false );
}
@@ -121,8 +121,8 @@
*/
public synchronized boolean addNoWaitFacade( LateralCacheNoWaitFacade
facade, String cacheName )
{
- boolean isNew = !facades.containsKey( cacheName );
-
+ boolean isNew = !facades.containsKey(cacheName);
+
// override or put anew, it doesn't matter
facades.put( cacheName, facade );
@@ -131,10 +131,10 @@
if ( sender != null )
{
// need to reset the cache names since we have a new one
- sender.setCacheNames( this.getCacheNames() );
+ sender.setCacheNames( this.getCacheNames() );
}
}
-
+
return isNew;
}
@@ -173,19 +173,19 @@
}
/**
- * Send a passive broadcast in response to a request broadcast. Never
send a
- * request for a request. We can respond to our own reques, since a
request
- * broadcast is not intended as a connection request. We might want to
only
- * send messages, so we would send a request, but never a passive
broadcast.
- *
+ * Send a passive broadcast in response to a request broadcast. Never
send a request for a request.
+ * We can respond to our own reques, since a request broadcast is not
intended as a connection request.
+ * We might want to only send messages, so we would send a request, but
never a passive broadcast.
+ *
*/
protected void serviceRequestBroadcast()
{
+ UDPDiscoverySender sender = null;
try
{
// create this connection each time.
// more robust
- UDPDiscoverySender sender = new UDPDiscoverySender(
lca.getUdpDiscoveryAddr(), lca.getUdpDiscoveryPort() );
+ sender = new UDPDiscoverySender( lca.getUdpDiscoveryAddr(),
lca.getUdpDiscoveryPort() );
sender.passiveBroadcast( hostAddress, lca.getTcpListenerPort(),
this.getCacheNames() );
@@ -201,9 +201,23 @@
catch ( Exception e )
{
log.error( "Problem calling the UDP Discovery Sender", e );
- }
+ }
+ finally
+ {
+ try
+ {
+ if ( sender != null )
+ {
+ sender.destroy();
+ }
+ }
+ catch ( Exception e )
+ {
+ log.error( "Problem closing Passive Broadcast sender, while
servicing a request broadcast.", e );
+ }
+ }
}
-
+
/**
* Get all the cache names we have facades for.
*
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]