sebawagner commented on a change in pull request #67: URL: https://github.com/apache/openmeetings/pull/67#discussion_r415143023
########## File path: openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/connection/ConnectionsPanel.java ########## @@ -45,75 +51,203 @@ import org.apache.wicket.markup.repeater.RepeatingView; import org.apache.wicket.model.ResourceModel; import org.apache.wicket.spring.injection.annot.SpringBean; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import de.agilecoders.wicket.core.markup.html.bootstrap.button.BootstrapAjaxLink; import de.agilecoders.wicket.core.markup.html.bootstrap.button.Buttons; public class ConnectionsPanel extends AdminBasePanel { + + private static final Logger log = LoggerFactory.getLogger(ConnectionsPanel.class); + private static final long serialVersionUID = 1L; @SpringBean private ClientManager cm; @SpringBean private KurentoHandler scm; @SpringBean + private StreamProcessor streamProcessor; + @SpringBean private IUserManager userManager; + + /** + * This needs to combine two lists as we currently hold a reference to the KStream in two places: + * <ul> + * <li>{@link StreamProcessor#getStreams()}}</li> + * <li>{@link KRoom#getParticipants()}</li> + * </ul> + * Both are singletons and hold a reference to a stream list and can get out of sync or leak. + * + * TODO: Investigate if we can have 1 source of truth. + * + * @return list of KStreams registered + */ + public Collection<ConnectionListKStreamItem> getAllStreams() { + Collection<ConnectionListKStreamItem> allStreams = new ArrayList<>(); + + allStreams.addAll( + streamProcessor.getStreams().stream() + .map(stream -> new ConnectionListKStreamItem( + streamProcessor.getClass().getSimpleName(), + stream.getSid(), + stream.getUid(), + (stream.getRoom() == null) ? null : stream.getRoom().getRoomId(), + stream.getConnectedSince(), + stream.getStreamType(), + stream.getProfile().toString(), + (stream.getRecorder() == null) ? null : stream.getRecorder().toString(), + stream.getChunkId(), + stream.getType() + )) + .collect(Collectors.toList()) + ); + + log.info("Retrieve all Streams, StreamProcessor has {} of streams", allStreams.size()); + + // Add any streams from the KRoom that are not in the StreamProcessor + scm.getRooms().forEach( + room -> { + log.info("Retrieve room {}, participants {}", room, room.getParticipants().size()); + room.getParticipants().forEach( + participant -> { + if (!streamProcessor.getStreams().contains(participant)) { + log.warn("Stream was in KRoom but not in StreamProcessor, stream {}", participant); + allStreams.add(new ConnectionListKStreamItem( + scm.getClass().getSimpleName(), + participant.getSid(), + participant.getUid(), + (participant.getRoom() == null) ? null : participant.getRoom().getRoomId(), + participant.getConnectedSince(), + participant.getStreamType(), + participant.getProfile().toString(), + (participant.getRecorder() == null) ? null : participant.getRecorder().toString(), + participant.getChunkId(), + participant.getType() + )); + } + } + ); + } + ); + + return allStreams; + } + + /** + * Combine lists for Client and KStream + * + * @return + */ + protected List<ConnectionListItem> getConnections() { + + List<ConnectionListItem> connections = new ArrayList<>(); + List<Client> clients = cm.list(); + Collection<ConnectionListKStreamItem> streams = getAllStreams(); + + connections.addAll( + clients.stream() + .map(client -> new ConnectionListItem(client, null)) + .collect(Collectors.toList()) + ); + connections.addAll( + streams.stream() + .map(stream -> new ConnectionListItem(null, stream)) + .collect(Collectors.toList()) + ); + return connections; + } public ConnectionsPanel(String id) { super(id); - SearchableDataProvider<Client> sdp = new SearchableDataProvider<>(null) { + SearchableDataProvider<ConnectionListItem> sdp = new SearchableDataProvider<>(null) { private static final long serialVersionUID = 1L; - private List<Client> list() { - List<Client> l = new ArrayList<>(); - l.addAll(cm.list()); - return l; - } - @Override - public Iterator<? extends Client> iterator(long first, long count) { - List<Client> l = list(); + public Iterator<? extends ConnectionListItem> iterator(long first, long count) { + List<ConnectionListItem> l = getConnections(); return l.subList((int)Math.max(0, first), (int)Math.min(first + count, l.size())).iterator(); } @Override public long size() { - return list().size(); + return getConnections().size(); } }; final WebMarkupContainer container = new WebMarkupContainer("container"); final WebMarkupContainer details = new WebMarkupContainer("details"); - SearchableDataView<Client> dataView = new SearchableDataView<>("clientList", sdp) { + SearchableDataView<ConnectionListItem> dataView = new SearchableDataView<>("clientList", sdp) { private static final long serialVersionUID = 1L; @Override - protected void populateItem(final Item<Client> item) { - Client c = item.getModelObject(); - item.add(new Label("type", "html5")); - item.add(new Label("login", c.getUser().getLogin())); - item.add(new Label("since", getDateFormat().format(c.getConnectedSince()))); - item.add(new Label("scope", c.getRoom() == null ? "html5" : "" + c.getRoom().getId())); - item.add(new Label("server", c.getServerId())); - item.add(new BootstrapAjaxLink<String>("kick", null, Buttons.Type.Outline_Danger, new ResourceModel("603")) { - private static final long serialVersionUID = 1L; - { - setSize(Buttons.Size.Small); - } - - @Override - public void onClick(AjaxRequestTarget target) { - cm.invalidate(c.getUserId(), c.getSessionId()); - target.add(container, details.setVisible(false)); - } - }.add(newOkCancelConfirm(this, getString("605")))); + protected void populateItem(final Item<ConnectionListItem> item) { + ConnectionListItem connection = item.getModelObject(); + + if (connection.getStream() != null) { + ConnectionListKStreamItem kStream = connection.getStream(); + item.add(new Label("type", kStream.getType())); + item.add(new Label("login", kStream.getUid())); + item.add(new Label("since", getDateFormat().format(kStream.getConnectedSince()))); + item.add(new Label("scope", kStream.getStreamType())); + item.add(new Label("server", kStream.getSource())); + item.add(new BootstrapAjaxLink<String>("kick", null, Buttons.Type.Outline_Danger, new ResourceModel("603")) { + private static final long serialVersionUID = 1L; + { + setSize(Buttons.Size.Small); + } + + @Override + public void onClick(AjaxRequestTarget target) { + // TODO come up with method to kick off this KStream Review comment: Need to still fix how to kick off this stream. But I'm thinking maybe to add an another PR/Jira for it. Maybe not show this button until functionality is there. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org