use of org.apache.cayenne.util.Invocation in project cayenne by apache.
the class DefaultEventManager method addListener.
protected void addListener(Object listener, String methodName, Class<?> eventParameterClass, EventSubject subject, Object sender, boolean blocking) {
if (listener == null) {
throw new IllegalArgumentException("Listener must not be null.");
}
if (eventParameterClass == null) {
throw new IllegalArgumentException("Event class must not be null.");
}
if (subject == null) {
throw new IllegalArgumentException("Subject must not be null.");
}
try {
Invocation invocation = (blocking) ? new Invocation(listener, methodName, eventParameterClass) : new NonBlockingInvocation(listener, methodName, eventParameterClass);
dispatchQueueForSubject(subject, true).addInvocation(invocation, sender);
} catch (NoSuchMethodException nsm) {
throw new CayenneRuntimeException("Error adding listener, method name: " + methodName, nsm);
}
}
use of org.apache.cayenne.util.Invocation in project cayenne by apache.
the class DispatchQueue method addInvocation.
void addInvocation(Invocation invocation, Object sender) {
ConcurrentMap<Invocation, Object> invocations;
if (sender == null) {
invocations = subjectInvocations;
} else {
invocations = invocationsForSender(sender, true);
}
// perform maintenance of the given invocations set, as failure to do that can
// result in a memory leak per CAY-770. This seemed to happen when lots of
// invocations got registered, but no events were dispatched (hence the stale
// invocation removal during dispatch did not happen)
Iterator<Invocation> it = invocations.keySet().iterator();
while (it.hasNext()) {
Invocation i = it.next();
if (i.getTarget() == null) {
it.remove();
}
}
invocations.putIfAbsent(invocation, Boolean.TRUE);
}
use of org.apache.cayenne.util.Invocation in project cayenne by apache.
the class DispatchQueue method removeInvocations.
// removes all invocations for a given listener
private boolean removeInvocations(ConcurrentMap<Invocation, Object> invocations, Object listener) {
if (invocations == null || invocations.isEmpty()) {
return false;
}
boolean didRemove = false;
Iterator<Invocation> invocationsIt = invocations.keySet().iterator();
while (invocationsIt.hasNext()) {
Invocation invocation = invocationsIt.next();
if (invocation.getTarget() == listener) {
invocationsIt.remove();
didRemove = true;
}
}
return didRemove;
}
Aggregations