This is an automated email from the ASF dual-hosted git repository.

solomax pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openmeetings.git


The following commit(s) were added to refs/heads/master by this push:
     new 5f880a5  [OPENMEETINGS-2298] connection panel is refactored
5f880a5 is described below

commit 5f880a5a2e048f6208a56bebdf862a16b7c2dd43
Author: Maxim Solodovnik <[email protected]>
AuthorDate: Mon Apr 27 18:45:07 2020 +0700

    [OPENMEETINGS-2298] connection panel is refactored
---
 .../openmeetings/core/remote/StreamProcessor.java  |   4 +
 .../web/admin/connection/ConnectionsPanel.java     | 163 ++++++---------------
 ...nectionListKStreamItem.java => KStreamDto.java} |  39 +++--
 .../admin/connection/dto/ConnectionListItem.java   |  64 --------
 4 files changed, 70 insertions(+), 200 deletions(-)

diff --git 
a/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/StreamProcessor.java
 
b/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/StreamProcessor.java
index 374d485..32cda74 100644
--- 
a/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/StreamProcessor.java
+++ 
b/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/StreamProcessor.java
@@ -512,6 +512,10 @@ public class StreamProcessor implements IStreamProcessor {
                return cm.getBySid(sid);
        }
 
+       public boolean hasStream(String uid) {
+               return streamByUid.get(uid) != null;
+       }
+
        KStream getByUid(String uid) {
                return uid == null ? null : streamByUid.get(uid);
        }
diff --git 
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/connection/ConnectionsPanel.java
 
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/connection/ConnectionsPanel.java
index 55d4f6f..84cc14c 100644
--- 
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/connection/ConnectionsPanel.java
+++ 
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/connection/ConnectionsPanel.java
@@ -30,15 +30,13 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.stream.Collectors;
 
-import org.apache.openmeetings.core.remote.KRoom;
 import org.apache.openmeetings.core.remote.KurentoHandler;
 import org.apache.openmeetings.core.remote.StreamProcessor;
 import org.apache.openmeetings.db.dao.user.IUserManager;
+import org.apache.openmeetings.db.entity.IDataProviderEntity;
 import org.apache.openmeetings.db.entity.basic.Client;
 import org.apache.openmeetings.web.admin.AdminBasePanel;
 import org.apache.openmeetings.web.admin.SearchableDataView;
-import org.apache.openmeetings.web.admin.connection.dto.ConnectionListItem;
-import 
org.apache.openmeetings.web.admin.connection.dto.ConnectionListKStreamItem;
 import org.apache.openmeetings.web.app.ClientManager;
 import org.apache.openmeetings.web.common.PagedEntityListPanel;
 import org.apache.openmeetings.web.data.SearchableDataProvider;
@@ -65,108 +63,47 @@ public class ConnectionsPanel extends AdminBasePanel {
        @SpringBean
        private ClientManager cm;
        @SpringBean
-       private KurentoHandler scm;
+       private KurentoHandler kHandler;
        @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<ConnectionListItem> sdp = new 
SearchableDataProvider<>(null) {
+       @Override
+       protected void onInitialize() {
+               super.onInitialize();
+
+               SearchableDataProvider<IDataProviderEntity> sdp = new 
SearchableDataProvider<>(null) {
                        private static final long serialVersionUID = 1L;
 
+                       private List<IDataProviderEntity> getConnections() {
+                               List<IDataProviderEntity> l = new ArrayList<>();
+                               l.addAll(cm.list());
+                               Collection<KStreamDto> streams = 
streamProcessor.getStreams()
+                                               .stream()
+                                               .map(kStream -> new 
KStreamDto("processor", kStream))
+                                               .collect(Collectors.toList());
+                               l.addAll(streams);
+                               log.info("Retrieve all Streams, StreamProcessor 
has {} of streams", streams.size());
+
+                               List<KStreamDto> missing = kHandler.getRooms()
+                                               .stream()
+                                               .flatMap(room -> 
room.getParticipants().stream())
+                                               .filter(stream -> 
!streamProcessor.hasStream(stream.getUid()))
+                                               .map(kStream -> new 
KStreamDto("KRoom", kStream))
+                                               .collect(Collectors.toList());
+                               l.addAll(missing);
+                               log.warn("Following streams were in KRoom but 
not in StreamProcessor: {}", missing);
+                               return l;
+                       }
+
                        @Override
-                       public Iterator<? extends ConnectionListItem> 
iterator(long first, long count) {
-                               List<ConnectionListItem> l = getConnections();
+                       public Iterator<? extends IDataProviderEntity> 
iterator(long first, long count) {
+                               List<IDataProviderEntity> l = getConnections();
                                return l.subList((int)Math.max(0, first), 
(int)Math.min(first + count, l.size())).iterator();
                        }
 
@@ -177,24 +114,22 @@ public class ConnectionsPanel extends AdminBasePanel {
                };
                final WebMarkupContainer container = new 
WebMarkupContainer("container");
                final WebMarkupContainer details = new 
WebMarkupContainer("details");
-               SearchableDataView<ConnectionListItem> dataView = new 
SearchableDataView<>("clientList", sdp) {
+               SearchableDataView<IDataProviderEntity> dataView = new 
SearchableDataView<>("clientList", sdp) {
                        private static final long serialVersionUID = 1L;
 
                        @Override
-                       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()));
+                       protected void populateItem(final 
Item<IDataProviderEntity> item) {
+                               if (item.getModelObject() instanceof 
KStreamDto) {
+                                       KStreamDto kStream = 
(KStreamDto)item.getModelObject();
+                                       item.add(new Label("type", 
kStream.getType() + " " + kStream.getStreamType()));
                                        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 Label("scope", 
kStream.getRoomId()));
+                                       item.add(new Label("server", ""));
                                        item.add(new Label("kick", ""));
                                }
-                               if (connection.getClient() != null) {
-                                       Client c = connection.getClient();
+                               if (item.getModelObject() instanceof Client) {
+                                       Client c = 
(Client)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())));
@@ -219,23 +154,9 @@ public class ConnectionsPanel extends AdminBasePanel {
 
                                        @Override
                                        protected void 
onEvent(AjaxRequestTarget target) {
-
+                                               Field[] ff = 
(item.getModelObject() instanceof KStreamDto ? KStreamDto.class : 
Client.class).getDeclaredFields();
                                                RepeatingView lines = new 
RepeatingView("line");
-                                               ConnectionListItem connection = 
item.getModelObject();
-
-                                               Field[] ff;
-                                               Object c;
-
-                                               if (connection.getStream() != 
null) {
-                                                       ff = 
connection.getStream().getClass().getDeclaredFields();
-                                                       c = 
connection.getStream();
-                                               } else if 
(connection.getClient() != null) {
-                                                       ff = 
connection.getClient().getClass().getDeclaredFields();
-                                                       c = 
connection.getClient();
-                                               } else {
-                                                       log.warn("Should be 
either Client or ConnectionListItem, modelObject {}", item.getModelObject());
-                                                       return;
-                                               }
+                                               Object c = 
item.getModelObject();
 
                                                for (Field f : ff) {
                                                        int mod = 
f.getModifiers();
diff --git 
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/connection/dto/ConnectionListKStreamItem.java
 
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/connection/KStreamDto.java
similarity index 71%
rename from 
openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/connection/dto/ConnectionListKStreamItem.java
rename to 
openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/connection/KStreamDto.java
index d1ac5a9..cc6521d 100644
--- 
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/connection/dto/ConnectionListKStreamItem.java
+++ 
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/connection/KStreamDto.java
@@ -16,11 +16,12 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.openmeetings.web.admin.connection.dto;
+package org.apache.openmeetings.web.admin.connection;
 
-import java.io.Serializable;
 import java.util.Date;
 
+import org.apache.openmeetings.core.remote.KStream;
+import org.apache.openmeetings.db.entity.IDataProviderEntity;
 import org.apache.openmeetings.db.entity.basic.Client.StreamType;
 import org.apache.openmeetings.db.entity.record.RecordingChunk.Type;
 
@@ -33,7 +34,7 @@ import 
org.apache.openmeetings.db.entity.record.RecordingChunk.Type;
  * @author sebawagner
  *
  */
-public class ConnectionListKStreamItem implements Serializable {
+public class KStreamDto implements IDataProviderEntity {
        private static final long serialVersionUID = 1L;
        /** StreamProcessor or KurentoHandler list */
        private String source;
@@ -48,19 +49,17 @@ public class ConnectionListKStreamItem implements 
Serializable {
        private Long chunkId;
        private Type type;
 
-       public ConnectionListKStreamItem(String source, String sid, String uid, 
Long roomId, Date connectedSince,
-                       StreamType streamType, String profile, String recorder, 
Long chunkId, Type type) {
-               super();
+       public KStreamDto(String source, KStream kStream) {
                this.source = source;
-               this.sid = sid;
-               this.uid = uid;
-               this.roomId = roomId;
-               this.connectedSince = connectedSince;
-               this.streamType = streamType;
-               this.profile = profile;
-               this.recorder = recorder;
-               this.chunkId = chunkId;
-               this.type = type;
+               this.sid = kStream.getSid();
+               this.uid = kStream.getUid();
+               this.roomId = (kStream.getRoom() == null) ? null : 
kStream.getRoom().getRoomId();
+               this.connectedSince = kStream.getConnectedSince();
+               this.streamType = kStream.getStreamType();
+               this.profile = kStream.getProfile().toString();
+               this.recorder = (kStream.getRecorder() == null) ? null : 
kStream.getRecorder().toString();
+               this.chunkId = kStream.getChunkId();
+               this.type = kStream.getType();
        }
 
        public static long getSerialversionuid() {
@@ -106,4 +105,14 @@ public class ConnectionListKStreamItem implements 
Serializable {
        public Type getType() {
                return type;
        }
+
+       @Override
+       public Long getId() {
+               return null;
+       }
+
+       @Override
+       public void setId(Long id) {
+               // no-op
+       }
 }
diff --git 
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/connection/dto/ConnectionListItem.java
 
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/connection/dto/ConnectionListItem.java
deleted file mode 100644
index 1820ce8..0000000
--- 
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/connection/dto/ConnectionListItem.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License") +  you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.openmeetings.web.admin.connection.dto;
-
-import org.apache.openmeetings.db.entity.IDataProviderEntity;
-import org.apache.openmeetings.db.entity.basic.Client;
-
-/**
- * Wrapper object for the UI display as the list item might be a client (that
- * may have also has ConnectionListKStreamItem(KStream) referenced).<br>
- * Or<br>
- * A single ConnectionListKStreamItem(KStream).<br>
- *
- * We want to see a total list of connections, a client represents a WebSocket 
and session.
- * A ConnectionListKStreamItem is a wrapper of KStream (which is a 
MediaStream).
- *
- * @author sebawagner
- *
- */
-public class ConnectionListItem implements IDataProviderEntity {
-       private static final long serialVersionUID = 1L;
-
-       private Client client;
-       private ConnectionListKStreamItem stream;
-
-       public ConnectionListItem(Client client, ConnectionListKStreamItem 
stream) {
-               super();
-               this.client = client;
-               this.stream = stream;
-       }
-       public Client getClient() {
-               return client;
-       }
-       public ConnectionListKStreamItem getStream() {
-               return stream;
-       }
-       @Override
-       public Long getId() {
-               if (client != null) {
-                       return client.getId();
-               }
-               return null;
-       }
-       @Override
-       public void setId(Long id) {
-               // no-op
-       }
-}

Reply via email to