Update of /cvsroot/mx4j/mx4j/src/core/mx4j/remote
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21341/core/mx4j/remote
Modified Files:
DefaultRemoteNotificationServerHandler.java
Log Message:
+ Improvement when the connection is closed: the RMI call fetchNotifications(), sleeping for a timeout, was not woken up on close().
+ Improved logging
+ Renamed a data member to avoid confusion with another one with the same name
Index: DefaultRemoteNotificationServerHandler.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/core/mx4j/remote/DefaultRemoteNotificationServerHandler.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** DefaultRemoteNotificationServerHandler.java 24 Feb 2004 14:06:50 -0000 1.6
--- DefaultRemoteNotificationServerHandler.java 25 Feb 2004 13:41:17 -0000 1.7
***************
*** 88,95 ****
public NotificationTuple[] close()
{
synchronized (tuples)
{
! closed = true;
! NotificationTuple[] result = (NotificationTuple[])tuples.values().toArray(new NotificationTuple[0]);
tuples.clear();
return result;
--- 88,96 ----
public NotificationTuple[] close()
{
+ closed = true;
+ stopWaitingForNotifications(buffer);
synchronized (tuples)
{
! NotificationTuple[] result = (NotificationTuple[])tuples.values().toArray(new NotificationTuple[tuples.size()]);
tuples.clear();
return result;
***************
*** 98,101 ****
--- 99,116 ----
/**
+ * When a connection is closed, it may be possible that a client RMI call is waiting in
+ * {@link #waitForNotifications}, so here we wake it up, letting the thread return to the
+ * client and free resources on client's side.
+ * @param lock The object on which {@link #notifyAll} should be called
+ */
+ private void stopWaitingForNotifications(Object lock)
+ {
+ synchronized (lock)
+ {
+ lock.notifyAll();
+ }
+ }
+
+ /**
* Called when there are no notifications to send to the client.
* It is guaranteed that no notification can be added before this method waits on the given lock.
***************
*** 109,112 ****
--- 124,135 ----
protected boolean waitForNotifications(Object lock, long timeout)
{
+ Logger logger = getLogger();
+ long start = 0;
+ if (logger.isEnabledFor(Logger.DEBUG))
+ {
+ logger.debug("Waiting for notifications " + timeout + " ms");
+ start = System.currentTimeMillis();
+ }
+
synchronized (lock)
{
***************
*** 120,123 ****
--- 143,153 ----
}
}
+
+ if (logger.isEnabledFor(Logger.DEBUG))
+ {
+ long elapsed = System.currentTimeMillis() - start;
+ logger.debug("Waited for notifications " + elapsed + " ms");
+ }
+
return true;
}
***************
*** 156,160 ****
private class NotificationBuffer
{
! private final List buffer = new LinkedList();
private int maxCapacity;
private int purgeDistance;
--- 186,190 ----
private class NotificationBuffer
{
! private final List notifications = new LinkedList();
private int maxCapacity;
private int purgeDistance;
***************
*** 189,195 ****
private int getSize()
{
! synchronized (buffer)
{
! return buffer.size();
}
}
--- 219,225 ----
private int getSize()
{
! synchronized (this)
{
! return notifications.size();
}
}
***************
*** 198,212 ****
{
Logger logger = getLogger();
! synchronized (buffer)
{
! if (buffer.size() == maxCapacity)
{
if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Notification buffer full: " + this);
removeRange(0, 1);
}
! buffer.add(notification);
++lastSequence;
if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Notification added to buffer: " + this);
! buffer.notifyAll();
}
}
--- 228,242 ----
{
Logger logger = getLogger();
! synchronized (this)
{
! if (notifications.size() == maxCapacity)
{
if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Notification buffer full: " + this);
removeRange(0, 1);
}
! notifications.add(notification);
++lastSequence;
if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Notification added to buffer: " + this);
! notifications.notifyAll();
}
}
***************
*** 214,220 ****
private void removeRange(int start, int end)
{
! synchronized (buffer)
{
! buffer.subList(start, end).clear();
firstSequence += end - start;
}
--- 244,250 ----
private void removeRange(int start, int end)
{
! synchronized (this)
{
! notifications.subList(start, end).clear();
firstSequence += end - start;
}
***************
*** 223,227 ****
private long getFirstSequenceNumber()
{
! synchronized (buffer)
{
return firstSequence;
--- 253,257 ----
private long getFirstSequenceNumber()
{
! synchronized (this)
{
return firstSequence;
***************
*** 231,235 ****
private long getLastSequenceNumber()
{
! synchronized (buffer)
{
return lastSequence;
--- 261,265 ----
private long getLastSequenceNumber()
{
! synchronized (this)
{
return lastSequence;
***************
*** 240,244 ****
{
Logger logger = getLogger();
! synchronized (buffer)
{
NotificationResult result = null;
--- 270,274 ----
{
Logger logger = getLogger();
! synchronized (this)
{
NotificationResult result = null;
***************
*** 272,282 ****
while (size == 0)
{
! int end = buffer.size();
if (end - start > maxNotifications) end = start + maxNotifications;
! sublist = buffer.subList(start, end);
size = sublist.size();
! if (send) break;
if (size == 0)
--- 302,312 ----
while (size == 0)
{
! int end = notifications.size();
if (end - start > maxNotifications) end = start + maxNotifications;
! sublist = notifications.subList(start, end);
size = sublist.size();
! if (closed || send) break;
if (size == 0)
***************
*** 287,292 ****
// We wait for notifications to arrive. Since we release the lock on the buffer
// other threads can modify it. To avoid ConcurrentModificationException we compute
! // again the sublist
! send = waitForNotifications(buffer, timeout);
}
}
--- 317,322 ----
// We wait for notifications to arrive. Since we release the lock on the buffer
// other threads can modify it. To avoid ConcurrentModificationException we compute
! // again the sublist by coming up back to the while statement
! send = waitForNotifications(this, timeout);
}
}
***************
*** 322,326 ****
int result = 0;
! synchronized (buffer)
{
if (sequenceNumber <= lowestExpectedSequence)
--- 352,356 ----
int result = 0;
! synchronized (this)
{
if (sequenceNumber <= lowestExpectedSequence)
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.