mx4j/src/core/mx4j/remote AbstractRemoteNotificationClientHandler.java,1.5,1.6
Simone Bordet <[email protected]>
| Newsgroups | gmane.comp.java.mx4j.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/mx4j/mx4j/src/core/mx4j/remote
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv922/src/core/mx4j/remote
Modified Files:
AbstractRemoteNotificationClientHandler.java
Log Message:
+ Fix for bug #1004412: now the notification queue can have a maximum
+ Fixed also a case where notifications lost event was sent, but notifications were not lost
Index: AbstractRemoteNotificationClientHandler.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/core/mx4j/remote/AbstractRemoteNotificationClientHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** AbstractRemoteNotificationClientHandler.java 25 Feb 2004 13:38:16 -0000 1.5
--- AbstractRemoteNotificationClientHandler.java 10 Aug 2004 09:33:30 -0000 1.6
***************
*** 17,24 ****
import java.util.List;
import java.util.Map;
-
import javax.management.Notification;
- import javax.management.NotificationListener;
import javax.management.NotificationFilter;
import javax.management.remote.NotificationResult;
import javax.management.remote.TargetedNotification;
--- 17,23 ----
import java.util.List;
import java.util.Map;
import javax.management.Notification;
import javax.management.NotificationFilter;
+ import javax.management.NotificationListener;
import javax.management.remote.NotificationResult;
import javax.management.remote.TargetedNotification;
***************
*** 29,32 ****
--- 28,32 ----
/**
* Base implementation of the RemoteNotificationClientHandler interface.
+ *
* @version $Revision$
*/
***************
*** 46,51 ****
* It uses an emitter, an heartbeat and an environment to perform the job.
* All 3 can be null, but the corrispondent methods must be overridden
! * @param emitter The NotificationEmitter that emits connection failures notifications
! * @param heartbeat The heart beat is used to get the retry parameters in case of connection failure
* @param environment Contains environment variables used to configure this handler
* @see MX4JRemoteConstants#FETCH_NOTIFICATIONS_MAX_NUMBER
--- 46,52 ----
* It uses an emitter, an heartbeat and an environment to perform the job.
* All 3 can be null, but the corrispondent methods must be overridden
! *
! * @param emitter The NotificationEmitter that emits connection failures notifications
! * @param heartbeat The heart beat is used to get the retry parameters in case of connection failure
* @param environment Contains environment variables used to configure this handler
* @see MX4JRemoteConstants#FETCH_NOTIFICATIONS_MAX_NUMBER
***************
*** 61,69 ****
this.heartbeat = heartbeat;
this.fetcherThread = new NotificationFetcherThread(environment);
! this.delivererThread = new NotificationDelivererThread();
}
/**
* Returns whether this client handler is fetching notifications or not.
* @see #start
* @see #stop
--- 62,71 ----
this.heartbeat = heartbeat;
this.fetcherThread = new NotificationFetcherThread(environment);
! this.delivererThread = new NotificationDelivererThread(environment);
}
/**
* Returns whether this client handler is fetching notifications or not.
+ *
* @see #start
* @see #stop
***************
*** 173,176 ****
--- 175,179 ----
* Returns the period between two retries if the connection with the server side fails.
* This implementation returns the heartbeat pulse period, but can be overridden.
+ *
* @see #getMaxRetries
* @see #AbstractRemoteNotificationClientHandler
***************
*** 185,188 ****
--- 188,192 ----
* failed.
* This implementation returns the heartbeat max retries, but can be overridden.
+ *
* @see #getRetryPeriod
* @see #AbstractRemoteNotificationClientHandler
***************
*** 202,208 ****
}
! private void deliverNotifications(TargetedNotification[] notifications)
{
! delivererThread.addNotifications(notifications);
}
--- 206,217 ----
}
! protected int getNotificationsCount()
{
! return delivererThread.getNotificationsCount();
! }
!
! private int deliverNotifications(TargetedNotification[] notifications)
! {
! return delivererThread.addNotifications(notifications);
}
***************
*** 355,359 ****
TargetedNotification[] targeted = result.getTargetedNotifications();
int targetedLength = targeted == null ? 0 : targeted.length;
! boolean notifsFilteredByServer = nextSequence - sequence != targetedLength;
boolean notifsLostByServer = sequence >= 0 && result.getEarliestSequenceNumber() > sequence;
if (notifsFilteredByServer)
--- 364,368 ----
TargetedNotification[] targeted = result.getTargetedNotifications();
int targetedLength = targeted == null ? 0 : targeted.length;
! boolean notifsFilteredByServer = sequence >= 0 ? nextSequence - sequence != targetedLength : false;
boolean notifsLostByServer = sequence >= 0 && result.getEarliestSequenceNumber() > sequence;
if (notifsFilteredByServer)
***************
*** 369,373 ****
setSequenceNumber(nextSequence);
! deliverNotifications(targeted);
// If we got a maxNumber of notifications, probably the server has more to send, don't sleep
--- 378,387 ----
setSequenceNumber(nextSequence);
! int delivered = deliverNotifications(targeted);
! if (delivered < targetedLength)
! {
! // We lost some notification
! sendConnectionNotificationLost(targetedLength - delivered);
! }
// If we got a maxNumber of notifications, probably the server has more to send, don't sleep
***************
*** 431,440 ****
{
private final List notificationQueue = new LinkedList();
private volatile boolean active;
private Thread thread;
! private void addNotifications(TargetedNotification[] notifications)
{
! if (notifications == null || notifications.length == 0) return;
List notifs = Arrays.asList(notifications);
--- 445,468 ----
{
private final List notificationQueue = new LinkedList();
+ private int capacity;
private volatile boolean active;
private Thread thread;
! private NotificationDelivererThread(Map environment)
{
! if (environment != null)
! {
! Object size = environment.get(MX4JRemoteConstants.NOTIFICATION_QUEUE_CAPACITY);
! if (size instanceof Integer)
! {
! capacity = ((Integer)size).intValue();
! if (capacity < 0) capacity = 0;
! }
! }
! }
!
! private int addNotifications(TargetedNotification[] notifications)
! {
! if (notifications == null || notifications.length == 0) return 0;
List notifs = Arrays.asList(notifications);
***************
*** 445,450 ****
synchronized (this)
{
! notificationQueue.addAll(notifs);
notifyAll();
}
}
--- 473,494 ----
synchronized (this)
{
! int size = notifs.size();
! int added = size;
! if (capacity > 0)
! {
! int room = capacity - notificationQueue.size();
! if (room < size)
! {
! added = room;
! if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Notification queue is full, enqueued " + room + " notifications out of " + size + ", exceeding will be lost");
! }
! notificationQueue.addAll(notifs.subList(0, added));
! }
! else
! {
! notificationQueue.addAll(notifs);
! }
notifyAll();
+ return added;
}
}
***************
*** 504,507 ****
--- 548,559 ----
}
}
+
+ private int getNotificationsCount()
+ {
+ synchronized (this)
+ {
+ return notificationQueue.size();
+ }
+ }
}
}
-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285