Tabnine Logo
SimpUserRegistry.getUsers
Code IndexAdd Tabnine to your IDE (free)

How to use
getUsers
method
in
org.springframework.messaging.simp.user.SimpUserRegistry

Best Java code snippets using org.springframework.messaging.simp.user.SimpUserRegistry.getUsers (Showing top 17 results out of 315)

origin: spring-projects/spring-framework

@Override
public Set<SimpUser> getUsers() {
  // Prefer remote registries due to cross-server SessionLookup
  Set<SimpUser> result = new HashSet<>();
  for (UserRegistrySnapshot registry : this.remoteRegistries.values()) {
    result.addAll(registry.getUserMap().values());
  }
  result.addAll(this.localRegistry.getUsers());
  return result;
}
origin: spring-projects/spring-framework

/**
 * Constructor to create DTO from a local user registry.
 */
public UserRegistrySnapshot(String id, SimpUserRegistry registry) {
  this.id = id;
  Set<SimpUser> users = registry.getUsers();
  this.users = new HashMap<>(users.size());
  for (SimpUser user : users) {
    this.users.put(user.getName(), new TransferSimpUser(user));
  }
}
origin: spring-projects/spring-framework

@Test
public void getUserFromLocalRegistry() throws Exception {
  SimpUser user = Mockito.mock(SimpUser.class);
  Set<SimpUser> users = Collections.singleton(user);
  when(this.localRegistry.getUsers()).thenReturn(users);
  when(this.localRegistry.getUserCount()).thenReturn(1);
  when(this.localRegistry.getUser("joe")).thenReturn(user);
  assertEquals(1, this.registry.getUserCount());
  assertSame(user, this.registry.getUser("joe"));
}
origin: spring-projects/spring-framework

@Test
public void handleMessageFromOwnBroadcast() throws Exception {
  TestSimpUser simpUser = new TestSimpUser("joe");
  simpUser.addSessions(new TestSimpSession("123"));
  when(this.localRegistry.getUserCount()).thenReturn(1);
  when(this.localRegistry.getUsers()).thenReturn(Collections.singleton(simpUser));
  assertEquals(1, this.multiServerRegistry.getUserCount());
  Message<?> message = this.converter.toMessage(this.multiServerRegistry.getLocalRegistryDto(), null);
  this.multiServerRegistry.addRemoteRegistryDto(message, this.converter, 20000);
  assertEquals(1, this.multiServerRegistry.getUserCount());
}
origin: spring-projects/spring-framework

@Test
public void broadcastRegistry() throws Exception {
  TestSimpUser simpUser1 = new TestSimpUser("joe");
  TestSimpUser simpUser2 = new TestSimpUser("jane");
  simpUser1.addSessions(new TestSimpSession("123"));
  simpUser1.addSessions(new TestSimpSession("456"));
  HashSet<SimpUser> simpUsers = new HashSet<>(Arrays.asList(simpUser1, simpUser2));
  when(this.localRegistry.getUsers()).thenReturn(simpUsers);
  getUserRegistryTask().run();
  ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
  verify(this.brokerChannel).send(captor.capture());
  Message<?> message = captor.getValue();
  assertNotNull(message);
  MessageHeaders headers = message.getHeaders();
  assertEquals("/topic/simp-user-registry", SimpMessageHeaderAccessor.getDestination(headers));
  MultiServerUserRegistry remoteRegistry = new MultiServerUserRegistry(mock(SimpUserRegistry.class));
  remoteRegistry.addRemoteRegistryDto(message, this.converter, 20000);
  assertEquals(2, remoteRegistry.getUserCount());
  assertNotNull(remoteRegistry.getUser("joe"));
  assertNotNull(remoteRegistry.getUser("jane"));
}
origin: spring-projects/spring-framework

@Test
public void purgeExpiredRegistries() throws Exception {
  // Prepare broadcast message from remote server
  TestSimpUser testUser = new TestSimpUser("joe");
  testUser.addSessions(new TestSimpSession("remote-sub"));
  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, -1);
  assertEquals(1, this.registry.getUserCount());
  this.registry.purgeExpiredRegistries();
  assertEquals(0, this.registry.getUserCount());
}
origin: spring-projects/spring-framework

@Test
public void handleMessage() throws Exception {
  TestSimpUser simpUser1 = new TestSimpUser("joe");
  TestSimpUser simpUser2 = new TestSimpUser("jane");
  simpUser1.addSessions(new TestSimpSession("123"));
  simpUser2.addSessions(new TestSimpSession("456"));
  HashSet<SimpUser> simpUsers = new HashSet<>(Arrays.asList(simpUser1, simpUser2));
  SimpUserRegistry remoteUserRegistry = mock(SimpUserRegistry.class);
  when(remoteUserRegistry.getUserCount()).thenReturn(2);
  when(remoteUserRegistry.getUsers()).thenReturn(simpUsers);
  MultiServerUserRegistry remoteRegistry = new MultiServerUserRegistry(remoteUserRegistry);
  Message<?> message = this.converter.toMessage(remoteRegistry.getLocalRegistryDto(), null);
  this.handler.handleMessage(message);
  assertEquals(2, remoteRegistry.getUserCount());
  assertNotNull(this.multiServerRegistry.getUser("joe"));
  assertNotNull(this.multiServerRegistry.getUser("jane"));
}
origin: spring-projects/spring-framework

@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);
}
origin: spring-projects/spring-framework

@Test  // SPR-13800
public void getSessionsWhenUserIsConnectedToMultipleServers() throws Exception {
  // Add user to local registry
  TestSimpUser localUser = new TestSimpUser("joe");
  TestSimpSession localSession = new TestSimpSession("sess123");
  localUser.addSessions(localSession);
  when(this.localRegistry.getUser("joe")).thenReturn(localUser);
  // Prepare broadcast message from remote server
  TestSimpUser remoteUser = new TestSimpUser("joe");
  TestSimpSession remoteSession = new TestSimpSession("sess456");
  remoteUser.addSessions(remoteSession);
  SimpUserRegistry remoteRegistry = mock(SimpUserRegistry.class);
  when(remoteRegistry.getUsers()).thenReturn(Collections.singleton(remoteUser));
  Object remoteRegistryDto = new MultiServerUserRegistry(remoteRegistry).getLocalRegistryDto();
  Message<?> message = this.converter.toMessage(remoteRegistryDto, null);
  // Add remote registry
  this.registry.addRemoteRegistryDto(message, this.converter, 20000);
  assertEquals(1, this.registry.getUserCount());
  SimpUser user = this.registry.getUsers().iterator().next();
  assertTrue(user.hasSessions());
  assertEquals(2, user.getSessions().size());
  assertThat(user.getSessions(), containsInAnyOrder(localSession, remoteSession));
  assertSame(localSession, user.getSession("sess123"));
  assertEquals(remoteSession, user.getSession("sess456"));
  user = this.registry.getUser("joe");
  assertEquals(2, user.getSessions().size());
  assertThat(user.getSessions(), containsInAnyOrder(localSession, remoteSession));
  assertSame(localSession, user.getSession("sess123"));
  assertEquals(remoteSession, user.getSession("sess456"));
}
origin: spring-projects/spring-framework

@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());
}
origin: org.springframework/spring-messaging

@Override
public Set<SimpUser> getUsers() {
  // Prefer remote registries due to cross-server SessionLookup
  Set<SimpUser> result = new HashSet<>();
  for (UserRegistrySnapshot registry : this.remoteRegistries.values()) {
    result.addAll(registry.getUserMap().values());
  }
  result.addAll(this.localRegistry.getUsers());
  return result;
}
origin: org.springframework/spring-messaging

/**
 * Constructor to create DTO from a local user registry.
 */
public UserRegistrySnapshot(String id, SimpUserRegistry registry) {
  this.id = id;
  Set<SimpUser> users = registry.getUsers();
  this.users = new HashMap<>(users.size());
  for (SimpUser user : users) {
    this.users.put(user.getName(), new TransferSimpUser(user));
  }
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-messaging

@Override
public Set<SimpUser> getUsers() {
  // Prefer remote registries due to cross-server SessionLookup
  Set<SimpUser> result = new HashSet<>();
  for (UserRegistrySnapshot registry : this.remoteRegistries.values()) {
    result.addAll(registry.getUserMap().values());
  }
  result.addAll(this.localRegistry.getUsers());
  return result;
}
origin: apache/servicemix-bundles

@Override
public Set<SimpUser> getUsers() {
  // Prefer remote registries due to cross-server SessionLookup
  Set<SimpUser> result = new HashSet<>();
  for (UserRegistrySnapshot registry : this.remoteRegistries.values()) {
    result.addAll(registry.getUserMap().values());
  }
  result.addAll(this.localRegistry.getUsers());
  return result;
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-messaging

/**
 * Constructor to create DTO from a local user registry.
 */
public UserRegistrySnapshot(String id, SimpUserRegistry registry) {
  this.id = id;
  Set<SimpUser> users = registry.getUsers();
  this.users = new HashMap<>(users.size());
  for (SimpUser user : users) {
    this.users.put(user.getName(), new TransferSimpUser(user));
  }
}
origin: apache/servicemix-bundles

/**
 * Constructor to create DTO from a local user registry.
 */
public UserRegistrySnapshot(String id, SimpUserRegistry registry) {
  this.id = id;
  Set<SimpUser> users = registry.getUsers();
  this.users = new HashMap<>(users.size());
  for (SimpUser user : users) {
    this.users.put(user.getName(), new TransferSimpUser(user));
  }
}
origin: metatron-app/metatron-discovery

for(SimpUser simpUser : userRegistry.getUsers()){
 for(SimpSession simpSession : simpUser.getSessions()){
  for(SimpSubscription simpSubscription : simpSession.getSubscriptions()){
org.springframework.messaging.simp.userSimpUserRegistrygetUsers

Javadoc

Return a snapshot of all connected users.

The returned set is a copy and will not reflect further changes.

Popular methods of SimpUserRegistry

  • getUser
    Get the user for the given name.
  • getUserCount
    Return the count of all connected users.
  • findSubscriptions
    Find subscriptions with the given matcher.

Popular in Java

  • Parsing JSON documents to java classes using gson
  • setScale (BigDecimal)
  • getResourceAsStream (ClassLoader)
  • onRequestPermissionsResult (Fragment)
  • PrintStream (java.io)
    Fake signature of an existing Java class.
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • Iterator (java.util)
    An iterator over a sequence of objects, such as a collection.If a collection has been changed since
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now