use of org.eclipse.scout.rt.shared.notification.INotificationListener in project scout.rt by eclipse.
the class AbstractObservableNotificationHandler method getListeners.
/**
* Returns the {@link INotificationListener}s for a given session.
*
* @param session
* {@link IClientSession}
* @return {@link INotificationListener}s
*/
public List<INotificationListener<T>> getListeners(IClientSession session) {
synchronized (m_listeners) {
List<INotificationListener<T>> res = new ArrayList<>();
EventListenerList listeners = m_listeners.get(session);
if (listeners != null) {
@SuppressWarnings("unchecked") INotificationListener<T>[] notificationListeners = listeners.getListeners(INotificationListener.class);
if (notificationListeners != null) {
for (INotificationListener<T> notificationListener : notificationListeners) {
res.add(notificationListener);
}
}
}
return res;
}
}
use of org.eclipse.scout.rt.shared.notification.INotificationListener in project scout.rt by eclipse.
the class AbstractObservableNotificationHandler method removeListener.
/**
* Removes the given listener for the given session.
*
* @see #addListener(IClientSession, INotificationListener)
*/
public void removeListener(IClientSession session, INotificationListener<T> listener) {
Assertions.assertNotNull(session, "client session can not be null");
Assertions.assertNotNull(listener, "listener can not be null");
synchronized (m_listeners) {
EventListenerList listeners = m_listeners.get(session);
if (listeners != null) {
listeners.remove(INotificationListener.class, listener);
if (listeners.getListenerCount(INotificationListener.class) == 0) {
m_listeners.remove(session);
}
}
}
}
use of org.eclipse.scout.rt.shared.notification.INotificationListener in project scout.rt by eclipse.
the class AbstractObservableNotificationHandlerTest method testRemoveListeners.
@SuppressWarnings("unchecked")
@Test
public void testRemoveListeners() {
final AbstractObservableNotificationHandler<Serializable> testHandler = createGlobalHandler();
INotificationListener l1 = mock(INotificationListener.class);
INotificationListener l2 = mock(INotificationListener.class);
testHandler.addListener(m_testSession1, l1);
testHandler.addListener(m_testSession1, l2);
testHandler.addListener(m_testSession2, l1);
testHandler.removeListener(m_testSession1, l1);
assertEquals(1, testHandler.getListeners(m_testSession1).size());
assertEquals(1, testHandler.getListeners(m_testSession2).size());
}
Aggregations