You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by st...@apache.org on 2004/07/02 18:24:37 UTC
cvs commit: jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation EventConsumer.java EventFilter.java EventImpl.java EventListenerIteratorImpl.java EventState.java EventStateCollection.java ObservationManagerFactory.java
stefan 2004/07/02 09:24:37
Modified: proposals/jcrri/src/org/apache/slide/jcr/core/observation
EventConsumer.java EventFilter.java EventImpl.java
EventListenerIteratorImpl.java EventState.java
EventStateCollection.java
ObservationManagerFactory.java
Log:
jcrri
Revision Changes Path
1.2 +31 -31 jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/EventConsumer.java
Index: EventConsumer.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/EventConsumer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EventConsumer.java 1 Jul 2004 18:29:57 -0000 1.1
+++ EventConsumer.java 2 Jul 2004 16:24:36 -0000 1.2
@@ -26,6 +26,7 @@
import javax.jcr.observation.EventListener;
import javax.jcr.observation.EventIterator;
+import javax.jcr.Ticket;
/**
* The <code>EventConsumer</code> class combines the {@link
@@ -40,8 +41,8 @@
*/
class EventConsumer {
- /** The userId part of this <code>EventConsumer</code>. */
- private final String userId;
+ /** The <code>Ticket</code> associated with this <code>EventConsumer</code>. */
+ private final Ticket ticket;
/** The listener part of this <code>EventConsumer</code>. */
private final EventListener listener;
@@ -53,35 +54,34 @@
private int hashCode;
/**
- * An <code>EventConsumer</code> consists of a <code>userId</code> which
- * refers to the user id of the <code>Ticket</code>, the attached
- * <code>EventListener</code> and an <code>EventFilter</code>.
+ * An <code>EventConsumer</code> consists of a <code>Ticket</code>, the
+ * attached <code>EventListener</code> and an <code>EventFilter</code>.
*
- * @param userId the user id taken from the <code>Ticket</code>.
+ * @param ticket the <code>Ticket</code> that created this
+ * <code>EventConsumer</code>.
* @param listener the actual <code>EventListener</code> to call back.
- * @param filter only pass an <code>Event</code> to the listener
- * if the <code>EventFilter</code> allows the <code>Event</code>.
- *
- * @exception NullPointerException if <code>userId</code>,
- * <code>listener</code> or <code>filter</code> is<code>null</code>.
+ * @param filter only pass an <code>Event</code> to the listener if the
+ * <code>EventFilter</code> allows the <code>Event</code>.
+ * @throws NullPointerException if <code>ticket</code>, <code>listener</code>
+ * or <code>filter</code> is<code>null</code>.
*/
- EventConsumer(String userId, EventListener listener, EventFilter filter) {
- if (userId == null) throw new NullPointerException("userId");
+ EventConsumer(Ticket ticket, EventListener listener, EventFilter filter) {
+ if (ticket == null) throw new NullPointerException("ticket");
if (listener == null) throw new NullPointerException("listener");
if (filter == null) throw new NullPointerException("filter");
- this.userId = userId;
+ this.ticket = ticket;
this.listener = listener;
this.filter = filter;
}
/**
- * Returns the userId of the <code>Ticket</code> that is associated
+ * Returns the <code>Ticket</code> that is associated
* with this <code>EventConsumer</code>.
- * @return the userId of this <code>EventConsumer</code>.
+ * @return the <code>Ticket</code> of this <code>EventConsumer</code>.
*/
- String getUserId() {
- return userId;
+ Ticket getTicket() {
+ return getTicket();
}
/**
@@ -110,17 +110,17 @@
}
/**
- * Returns <code>true</code> if this <code>EventConsumer</code>
- * is equal to some other object, <code>false</code> otherwise.
- * <p>
- * Two <code>EventConsumer</code>s are considered equal if
- * they refer to the same user id and the <code>EventListener</code>s
- * they reference are equal. Note that the <code>EventFilter</code> is
- * ignored in this check.
+ * Returns <code>true</code> if this <code>EventConsumer</code> is equal to
+ * some other object, <code>false</code> otherwise.
+ * <p/>
+ * Two <code>EventConsumer</code>s are considered equal if they refer to the
+ * same <code>Ticket</code> and the <code>EventListener</code>s they
+ * reference are equal. Note that the <code>EventFilter</code> is ignored in
+ * this check.
*
* @param obj the reference object with which to compare.
- * @return <code>true</code> if this <code>EventConsumer</code>
- * is equal the other <code>EventConsumer</code>.
+ * @return <code>true</code> if this <code>EventConsumer</code> is equal the
+ * other <code>EventConsumer</code>.
*/
public boolean equals(Object obj) {
if (this == obj) {
@@ -128,7 +128,7 @@
}
if (obj instanceof EventConsumer) {
EventConsumer other = (EventConsumer)obj;
- return userId.equals(other.userId)
+ return ticket.equals(other.ticket)
&& listener.equals(other.listener);
}
return false;
@@ -140,7 +140,7 @@
*/
public int hashCode() {
if (hashCode == 0) {
- hashCode = userId.hashCode() ^ listener.hashCode();
+ hashCode = ticket.hashCode() ^ listener.hashCode();
}
return hashCode;
}
1.2 +3 -3 jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/EventFilter.java
Index: EventFilter.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/EventFilter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EventFilter.java 1 Jul 2004 18:29:57 -0000 1.1
+++ EventFilter.java 2 Jul 2004 16:24:36 -0000 1.2
@@ -162,7 +162,7 @@
}
// check for ticket local changes
- if (noLocal && ticket.getUserId().equals(eventState.getUserId())) {
+ if (noLocal && ticket.equals(eventState.getTicket())) {
// listener does not wish to get local events
return true;
}
1.2 +4 -5 jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/EventImpl.java
Index: EventImpl.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/EventImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EventImpl.java 1 Jul 2004 18:29:57 -0000 1.1
+++ EventImpl.java 2 Jul 2004 16:24:37 -0000 1.2
@@ -137,7 +137,7 @@
* @see Object#hashCode()
*/
public int hashCode() {
- return eventState.hashCode() ^ ticket.getUserId().hashCode();
+ return eventState.hashCode() ^ ticket.hashCode();
}
/**
@@ -160,8 +160,7 @@
if (obj instanceof EventImpl) {
EventImpl other = (EventImpl)obj;
return this.eventState.equals(other.eventState)
- // FIXME rather use ticket.equals(other.ticket) ?
- && this.ticket.getUserId().equals(other.ticket.getUserId());
+ && this.ticket.equals(other.ticket);
}
return false;
}
1.2 +4 -3 jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/EventListenerIteratorImpl.java
Index: EventListenerIteratorImpl.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/EventListenerIteratorImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EventListenerIteratorImpl.java 1 Jul 2004 18:30:08 -0000 1.1
+++ EventListenerIteratorImpl.java 2 Jul 2004 16:24:37 -0000 1.2
@@ -143,7 +143,8 @@
next = null;
while (next == null && consumers.hasNext()) {
consumer = (EventConsumer)consumers.next();
- if (consumer.getUserId().equals(ticket.getUserId())) {
+ // only return EventConsumers that belong to our ticket
+ if (consumer.getTicket().equals(ticket)) {
next = consumer.getEventListener();
}
1.2 +38 -26 jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/EventState.java
Index: EventState.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/EventState.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EventState.java 1 Jul 2004 18:30:08 -0000 1.1
+++ EventState.java 2 Jul 2004 16:24:37 -0000 1.2
@@ -27,6 +27,7 @@
import org.apache.slide.jcr.core.QName;
import javax.jcr.observation.EventType;
+import javax.jcr.Ticket;
/**
* The <code>EventState</code> class encapsulates the ticket
@@ -46,8 +47,8 @@
/** The qualified name of the child item associated with this event. */
private final QName childName;
- /** The userId of the ticket that caused this event. */
- private final String userId;
+ /** The the ticket that caused this event. */
+ private final Ticket ticket;
/** Cached String representation of this <code>EventState</code>. */
private String stringValue;
@@ -63,14 +64,14 @@
* @param parentUUID the uuid of the parent node associated with this event.
* @param childName the qualified name of the child item associated with
* this event.
- * @param userId the userId of the {@link javax.jcr.Ticket} that
+ * @param ticket the {@link javax.jcr.Ticket} that
* caused this event.
*/
- private EventState(long type, String parentUUID, QName childName, String userId) {
+ private EventState(long type, String parentUUID, QName childName, Ticket ticket) {
this.type = type;
this.parentUUID = parentUUID;
this.childName = childName;
- this.userId = userId;
+ this.ticket = ticket;
}
//-----------------< factory methods >--------------------------------------
@@ -82,16 +83,16 @@
* @param parentUUID the uuid of the parent node associated with
* this <code>EventState</code>.
* @param childName the qualified name of the child node that was added.
- * @param userId the userId of the ticket that added the node.
+ * @param ticket the ticket that added the node.
* @return an <code>EventState</code> instance.
*/
public static EventState ChildNodeAdded(String parentUUID,
QName childName,
- String userId) {
+ Ticket ticket) {
return new EventState(EventType.CHILD_NODE_ADDED,
parentUUID,
childName,
- userId);
+ ticket);
}
/**
@@ -101,16 +102,16 @@
* @param parentUUID the uuid of the parent node associated with
* this <code>EventState</code>.
* @param childName the qualified name of the child node that was removed.
- * @param userId the userId of the ticket that removed the node.
+ * @param ticket the ticket that removed the node.
* @return an <code>EventState</code> instance.
*/
public static EventState ChildNodeRemoved(String parentUUID,
QName childName,
- String userId) {
+ Ticket ticket) {
return new EventState(EventType.CHILD_NODE_REMOVED,
parentUUID,
childName,
- userId);
+ ticket);
}
/**
@@ -120,16 +121,16 @@
* @param parentUUID the uuid of the parent node associated with
* this <code>EventState</code>.
* @param childName the qualified name of the property that was added.
- * @param userId the userId of the ticket that added the property.
+ * @param ticket the ticket that added the property.
* @return an <code>EventState</code> instance.
*/
public static EventState PropertyAdded(String parentUUID,
QName childName,
- String userId) {
+ Ticket ticket) {
return new EventState(EventType.PROPERTY_ADDED,
parentUUID,
childName,
- userId);
+ ticket);
}
/**
@@ -139,16 +140,16 @@
* @param parentUUID the uuid of the parent node associated with
* this <code>EventState</code>.
* @param childName the qualified name of the property that was removed.
- * @param userId the userId of the ticket that removed the property.
+ * @param ticket the ticket that removed the property.
* @return an <code>EventState</code> instance.
*/
public static EventState PropertyRemoved(String parentUUID,
QName childName,
- String userId) {
+ Ticket ticket) {
return new EventState(EventType.PROPERTY_REMOVED,
parentUUID,
childName,
- userId);
+ ticket);
}
/**
@@ -158,16 +159,16 @@
* @param parentUUID the uuid of the parent node associated with
* this <code>EventState</code>.
* @param childName the qualified name of the property that changed.
- * @param userId the userId of the ticket that changed the property.
+ * @param ticket the ticket that changed the property.
* @return an <code>EventState</code> instance.
*/
public static EventState PropertyChanged(String parentUUID,
QName childName,
- String userId) {
+ Ticket ticket) {
return new EventState(EventType.PROPERTY_CHANGED,
parentUUID,
childName,
- userId);
+ ticket);
}
/**
@@ -198,7 +199,18 @@
* @see javax.jcr.observation.Event#getUserId()
*/
public String getUserId() {
- return userId;
+ return ticket.getUserId();
+ }
+
+ /**
+ * Returns the <code>Ticket</code> that caused / created this
+ * <code>EventState</code>.
+ *
+ * @return the <code>Ticket</code> that caused / created this
+ * <code>EventState</code>.
+ */
+ Ticket getTicket() {
+ return ticket;
}
/**
@@ -211,7 +223,7 @@
sb.append("EventState: ").append(valueOf(type));
sb.append(", Parent: ").append(parentUUID);
sb.append(", Child: ").append(childName);
- sb.append(", UserId: ").append(userId);
+ sb.append(", UserId: ").append(ticket.getUserId());
stringValue = sb.toString();
}
return stringValue;
@@ -228,7 +240,7 @@
h = 37*h + (int)type;
h = 37*h + parentUUID.hashCode();
h = 37*h + childName.hashCode();
- h = 37*h + userId.hashCode();
+ h = 37*h + ticket.hashCode();
hashCode = h;
}
return hashCode;
@@ -251,7 +263,7 @@
return this.type == other.type
&& this.parentUUID.equals(other.parentUUID)
&& this.childName.equals(other.childName)
- && this.userId.equals(other.userId);
+ && this.ticket.equals(other.ticket);
}
return false;
}
1.2 +14 -15 jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/EventStateCollection.java
Index: EventStateCollection.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/EventStateCollection.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EventStateCollection.java 1 Jul 2004 18:30:08 -0000 1.1
+++ EventStateCollection.java 2 Jul 2004 16:24:37 -0000 1.2
@@ -28,6 +28,7 @@
import org.apache.log4j.Logger;
import javax.jcr.RepositoryException;
+import javax.jcr.Ticket;
import java.util.*;
/**
@@ -46,18 +47,16 @@
/** List of events */
private final List events = new ArrayList();
- /** UserId of the ticket that created these events */
- private final String userId;
+ /** The ticket that created these events */
+ private final Ticket ticket;
/**
- * Creates a new empty <code>EventStateCollection</code>. The <code>userId</code>
- * indicates that events in this collection are created by a ticket
- * associated to the user with id <code>userId</code>.
+ * Creates a new empty <code>EventStateCollection</code>.
*
- * @param userId the user id of the ticket that created these events.
+ * @param ticket the ticket that created these events.
*/
- public EventStateCollection(String userId) {
- this.userId = userId;
+ public EventStateCollection(Ticket ticket) {
+ this.ticket = ticket;
}
/**
@@ -84,7 +83,7 @@
NodeState.PropertyEntry prop = (NodeState.PropertyEntry)it.next();
events.add(EventState.PropertyAdded(currentNode.getUUID(),
prop.getName(),
- userId));
+ ticket));
}
// 2) check removed properties
@@ -93,7 +92,7 @@
NodeState.PropertyEntry prop = (NodeState.PropertyEntry)it.next();
events.add(EventState.PropertyRemoved(currentNode.getUUID(),
prop.getName(),
- userId));
+ ticket));
}
// 3) check for added nodes
@@ -102,7 +101,7 @@
NodeState.ChildNodeEntry child = (NodeState.ChildNodeEntry)it.next();
events.add(EventState.ChildNodeAdded(currentNode.getUUID(),
child.getName(),
- userId));
+ ticket));
}
// 4) check for removed nodes
@@ -111,14 +110,14 @@
NodeState.ChildNodeEntry child = (NodeState.ChildNodeEntry)it.next();
events.add(EventState.ChildNodeRemoved(currentNode.getUUID(),
child.getName(),
- userId));
+ ticket));
}
} else {
// only add property changed event if property is existing
if (state.getStatus() == ItemState.STATUS_EXISTING_MODIFIED) {
events.add(EventState.PropertyChanged(state.getParentUUID(),
((PropertyState)state).getName(),
- userId));
+ ticket));
}
}
}
1.2 +3 -3 jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/ObservationManagerFactory.java
Index: ObservationManagerFactory.java
===================================================================
RCS file: /home/cvs/jakarta-slide/proposals/jcrri/src/org/apache/slide/jcr/core/observation/ObservationManagerFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ObservationManagerFactory.java 1 Jul 2004 18:30:08 -0000 1.1
+++ ObservationManagerFactory.java 2 Jul 2004 16:24:37 -0000 1.2
@@ -232,7 +232,7 @@
noLocal);
EventConsumer consumer =
- new EventConsumer(ticket.getUserId(), listener, filter);
+ new EventConsumer(ticket, listener, filter);
synchronized (consumerChange) {
// remove existing if any
@@ -250,7 +250,7 @@
public void removeEventListener(EventListener listener)
throws RepositoryException {
EventConsumer consumer =
- new EventConsumer(ticket.getUserId(), listener, EventFilter.BLOCK_ALL);
+ new EventConsumer(ticket, listener, EventFilter.BLOCK_ALL);
synchronized (consumerChange) {
activeConsumers.remove(consumer);
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org