private void addSessions(Map<String, SimpSession> map) { for (SimpSession session : this.sessions) { map.put(session.getId(), session); } }
void addSession(SimpSession session) { this.userSessions.put(session.getId(), session); }
@Override public boolean equals(Object other) { return (this == other || (other instanceof SimpSession && getId().equals(((SimpSession) other).getId()))); }
@Override public boolean equals(Object other) { return (this == other || (other instanceof SimpSession && this.id.equals(((SimpSession) other).getId()))); }
/** * Constructor to create DTO from the local user session. */ public TransferSimpSession(SimpSession session) { this.id = session.getId(); this.user = new TransferSimpUser(); Set<SimpSubscription> subscriptions = session.getSubscriptions(); this.subscriptions = new HashSet<>(subscriptions.size()); for (SimpSubscription subscription : subscriptions) { this.subscriptions.add(new TransferSimpSubscription(subscription)); } }
private Set<String> getSessionIdsByUser(String userName, @Nullable String sessionId) { Set<String> sessionIds; SimpUser user = this.userRegistry.getUser(userName); if (user != null) { if (sessionId != null && user.getSession(sessionId) != null) { sessionIds = Collections.singleton(sessionId); } else { Set<SimpSession> sessions = user.getSessions(); sessionIds = new HashSet<>(sessions.size()); for (SimpSession session : sessions) { sessionIds.add(session.getId()); } } } else { sessionIds = Collections.emptySet(); } return sessionIds; }
public Map<String, SimpSession> findSessions(String userName) { Map<String, SimpSession> map = new HashMap<>(4); SimpUser user = localRegistry.getUser(userName); if (user != null) { for (SimpSession session : user.getSessions()) { map.put(session.getId(), session); } } for (UserRegistrySnapshot registry : remoteRegistries.values()) { TransferSimpUser transferUser = registry.getUserMap().get(userName); if (transferUser != null) { transferUser.addSessions(map); } } return map; }
@Override public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof SimpSubscription)) { return false; } SimpSubscription otherSubscription = (SimpSubscription) other; return (getId().equals(otherSubscription.getId()) && getSession().getId().equals(otherSubscription.getSession().getId())); }
@Test public void findSubscriptionsFromRemoteRegistry() throws Exception { // Prepare broadcast message from remote server TestSimpUser user1 = new TestSimpUser("joe"); TestSimpUser user2 = new TestSimpUser("jane"); TestSimpUser user3 = new TestSimpUser("jack"); TestSimpSession session1 = new TestSimpSession("sess1"); TestSimpSession session2 = new TestSimpSession("sess2"); TestSimpSession session3 = new TestSimpSession("sess3"); session1.addSubscriptions(new TestSimpSubscription("sub1", "/match")); session2.addSubscriptions(new TestSimpSubscription("sub1", "/match")); session3.addSubscriptions(new TestSimpSubscription("sub1", "/not-a-match")); user1.addSessions(session1); user2.addSessions(session2); user3.addSessions(session3); SimpUserRegistry userRegistry = mock(SimpUserRegistry.class); when(userRegistry.getUsers()).thenReturn(new HashSet<>(Arrays.asList(user1, user2, user3))); Object registryDto = new MultiServerUserRegistry(userRegistry).getLocalRegistryDto(); Message<?> message = this.converter.toMessage(registryDto, null); // Add remote registry this.registry.addRemoteRegistryDto(message, this.converter, 20000); assertEquals(3, this.registry.getUserCount()); Set<SimpSubscription> matches = this.registry.findSubscriptions(s -> s.getDestination().equals("/match")); assertEquals(2, matches.size()); Iterator<SimpSubscription> iterator = matches.iterator(); Set<String> sessionIds = new HashSet<>(2); sessionIds.add(iterator.next().getSession().getId()); sessionIds.add(iterator.next().getSession().getId()); assertEquals(new HashSet<>(Arrays.asList("sess1", "sess2")), sessionIds); }
@Test public void getUserFromRemoteRegistry() throws Exception { // Prepare broadcast message from remote server TestSimpUser testUser = new TestSimpUser("joe"); TestSimpSession testSession = new TestSimpSession("remote-sess"); testSession.addSubscriptions(new TestSimpSubscription("remote-sub", "/remote-dest")); testUser.addSessions(testSession); SimpUserRegistry testRegistry = mock(SimpUserRegistry.class); when(testRegistry.getUsers()).thenReturn(Collections.singleton(testUser)); Object registryDto = new MultiServerUserRegistry(testRegistry).getLocalRegistryDto(); Message<?> message = this.converter.toMessage(registryDto, null); // Add remote registry this.registry.addRemoteRegistryDto(message, this.converter, 20000); assertEquals(1, this.registry.getUserCount()); SimpUser user = this.registry.getUser("joe"); assertNotNull(user); assertTrue(user.hasSessions()); assertEquals(1, user.getSessions().size()); SimpSession session = user.getSession("remote-sess"); assertNotNull(session); assertEquals("remote-sess", session.getId()); assertSame(user, session.getUser()); assertEquals(1, session.getSubscriptions().size()); SimpSubscription subscription = session.getSubscriptions().iterator().next(); assertEquals("remote-sub", subscription.getId()); assertSame(session, subscription.getSession()); assertEquals("/remote-dest", subscription.getDestination()); }
private void addSessions(Map<String, SimpSession> map) { for (SimpSession session : this.sessions) { map.put(session.getId(), session); } }
@Override public boolean equals(Object other) { return (this == other || (other instanceof SimpSession && getId().equals(((SimpSession) other).getId()))); }
/** * Constructor to create DTO from the local user session. */ public TransferSimpSession(SimpSession session) { this.id = session.getId(); this.user = new TransferSimpUser(); Set<SimpSubscription> subscriptions = session.getSubscriptions(); this.subscriptions = new HashSet<>(subscriptions.size()); for (SimpSubscription subscription : subscriptions) { this.subscriptions.add(new TransferSimpSubscription(subscription)); } }
public Map<String, SimpSession> findSessions(String userName) { Map<String, SimpSession> map = new HashMap<>(4); SimpUser user = localRegistry.getUser(userName); if (user != null) { for (SimpSession session : user.getSessions()) { map.put(session.getId(), session); } } for (UserRegistrySnapshot registry : remoteRegistries.values()) { TransferSimpUser transferUser = registry.getUserMap().get(userName); if (transferUser != null) { transferUser.addSessions(map); } } return map; }
private Set<String> getSessionIdsByUser(String userName, @Nullable String sessionId) { Set<String> sessionIds; SimpUser user = this.userRegistry.getUser(userName); if (user != null) { if (sessionId != null && user.getSession(sessionId) != null) { sessionIds = Collections.singleton(sessionId); } else { Set<SimpSession> sessions = user.getSessions(); sessionIds = new HashSet<>(sessions.size()); for (SimpSession session : sessions) { sessionIds.add(session.getId()); } } } else { sessionIds = Collections.emptySet(); } return sessionIds; }
private void addSessions(Map<String, SimpSession> map) { for (SimpSession session : this.sessions) { map.put(session.getId(), session); } }
/** * Constructor to create DTO from the local user session. */ public TransferSimpSession(SimpSession session) { this.id = session.getId(); this.user = new TransferSimpUser(); Set<SimpSubscription> subscriptions = session.getSubscriptions(); this.subscriptions = new HashSet<>(subscriptions.size()); for (SimpSubscription subscription : subscriptions) { this.subscriptions.add(new TransferSimpSubscription(subscription)); } }
/** * Constructor to create DTO from the local user session. */ public TransferSimpSession(SimpSession session) { this.id = session.getId(); this.user = new TransferSimpUser(); Set<SimpSubscription> subscriptions = session.getSubscriptions(); this.subscriptions = new HashSet<>(subscriptions.size()); for (SimpSubscription subscription : subscriptions) { this.subscriptions.add(new TransferSimpSubscription(subscription)); } }
@Override public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof SimpSubscription)) { return false; } SimpSubscription otherSubscription = (SimpSubscription) other; return (getId().equals(otherSubscription.getId()) && getSession().getId().equals(otherSubscription.getSession().getId())); }
@Override public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof SimpSubscription)) { return false; } SimpSubscription otherSubscription = (SimpSubscription) other; return (getId().equals(otherSubscription.getId()) && getSession().getId().equals(otherSubscription.getSession().getId())); }