Skip to content

Commit

Permalink
Dev UI Fix Reactive messaging screen
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <[email protected]>
  • Loading branch information
phillip-kruger committed Nov 9, 2023
1 parent 8646114 commit 5be91d9
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class QwcSmallryeReactiveMessagingChannels extends LitElement {
</vaadin-grid-column>
<vaadin-grid-column auto-width
header="Publisher"
header="Publisher(s)"
${columnBodyRenderer(this._channelPublisherRenderer, [])}>>
</vaadin-grid-column>
Expand Down Expand Up @@ -95,9 +95,19 @@ export class QwcSmallryeReactiveMessagingChannels extends LitElement {
}

_channelPublisherRenderer(channel) {
const publisher = channel.publisher;
if (publisher) {
return this._renderComponent(publisher);
const publishers = channel.publishers;
if (publishers) {
if (publishers.length === 1) {
return this._renderComponent(publishers[0]);
} else if (publishers.length > 1) {
return html`
<ul class="smaller">
${publishers.map(item => html`<li>${this._renderComponent(item)}</li>`)}
</ul>
`;
} else {
return html`<em>No publishers</em>`
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,24 @@ public List<DevChannelInfo> get() {
.get();

// collect all channels
Map<String, Component> publishers = new HashMap<>();
Map<String, List<Component>> publishers = new HashMap<>();
Map<String, List<Component>> consumers = new HashMap<>();
Function<String, List<Component>> fun = e -> new ArrayList<>();

// Unfortunately, there is no easy way to obtain the connectors metadata
Connectors connectors = container.instance(Connectors.class).get();
publishers.putAll(connectors.outgoingConnectors);
for (Entry<String, Component> entry : connectors.outgoingConnectors.entrySet()) {
publishers.computeIfAbsent(entry.getKey(), fun)
.add(entry.getValue());
}
for (Entry<String, Component> entry : connectors.incomingConnectors.entrySet()) {
consumers.computeIfAbsent(entry.getKey(), fun)
.add(entry.getValue());
}

for (EmitterConfiguration emitter : context.getEmitterConfigurations()) {
publishers.put(emitter.name(),
new Component(ComponentType.EMITTER,
publishers.computeIfAbsent(emitter.name(), fun)
.add(new Component(ComponentType.EMITTER,
emitter.broadcast() ? "<span class=\"annotation\">&#64;Broadcast</span> "
: "" + asCode(DevConsoleRecorder.EMITTERS.get(emitter.name()))));
}
Expand All @@ -58,23 +61,27 @@ public List<DevChannelInfo> get() {
asCode(DevConsoleRecorder.CHANNELS.get(channel.channelName))));
}
for (MediatorConfiguration mediator : context.getMediatorConfigurations()) {
boolean isProcessor = !mediator.getIncoming().isEmpty() && mediator.getOutgoing() != null;
boolean isProcessor = !mediator.getIncoming().isEmpty() && !mediator.getOutgoings().isEmpty();
if (isProcessor) {
publishers.put(mediator.getOutgoing(),
new Component(ComponentType.PROCESSOR, asMethod(mediator.methodAsString())));
for (String outgoing : mediator.getOutgoings()) {
publishers.computeIfAbsent(outgoing, fun)
.add(new Component(ComponentType.PROCESSOR, asMethod(mediator.methodAsString())));
}
for (String incoming : mediator.getIncoming()) {
consumers.computeIfAbsent(incoming, fun)
.add(new Component(ComponentType.PROCESSOR,
asMethod(mediator.methodAsString())));
}
} else if (mediator.getOutgoing() != null) {
StringBuilder builder = new StringBuilder();
builder.append(asMethod(mediator.methodAsString()));
if (mediator.getBroadcast()) {
builder.append("[broadcast: true]");
} else if (!mediator.getOutgoings().isEmpty()) {
for (String outgoing : mediator.getOutgoings()) {
StringBuilder builder = new StringBuilder();
builder.append(asMethod(mediator.methodAsString()));
if (mediator.getBroadcast()) {
builder.append("[broadcast: true]");
}
publishers.computeIfAbsent(outgoing, fun)
.add(new Component(ComponentType.PUBLISHER, builder.toString()));
}
publishers.put(mediator.getOutgoing(),
new Component(ComponentType.PUBLISHER, builder.toString()));
} else if (!mediator.getIncoming().isEmpty()) {
for (String incoming : mediator.getIncoming()) {
consumers.computeIfAbsent(incoming, fun)
Expand Down Expand Up @@ -113,21 +120,21 @@ public List<DevChannelInfo> getChannels() {
public static class DevChannelInfo implements Comparable<DevChannelInfo> {

private final String name;
private final Component publisher;
private final List<Component> publishers;
private final List<Component> consumers;

public DevChannelInfo(String name, Component publisher, List<Component> consumers) {
public DevChannelInfo(String name, List<Component> publishers, List<Component> consumers) {
this.name = name;
this.publisher = publisher;
this.publishers = publishers != null ? publishers : Collections.emptyList();
this.consumers = consumers != null ? consumers : Collections.emptyList();
}

public String getName() {
return name;
}

public Component getPublisher() {
return publisher;
public List<Component> getPublishers() {
return publishers;
}

public List<Component> getConsumers() {
Expand All @@ -136,28 +143,18 @@ public List<Component> getConsumers() {

@Override
public int compareTo(DevChannelInfo other) {
if (publisher != other.publisher) {
if (other.publisher == null) {
return -1;
}
if (publisher == null) {
return 1;
}
// publisher connectors first
if (publisher.type != other.publisher.type) {
return publisher.type == ComponentType.CONNECTOR ? -1 : 1;
}
// publisher connectors last
long publisherConnectors = publishers.stream().filter(Component::isConnector).count();
long otherPublisherConnectors = other.publishers.stream().filter(Component::isConnector).count();
if (publisherConnectors != otherPublisherConnectors) {
return Long.compare(otherPublisherConnectors, publisherConnectors);
}
// consumer connectors last
long consumerConnectors = consumers.stream().filter(Component::isConnector).count();
long otherConsumersConnectors = other.consumers.stream().filter(Component::isConnector).count();
if (consumerConnectors != otherConsumersConnectors) {
return Long.compare(otherConsumersConnectors, consumerConnectors);
}
if (publisher != other.publisher && publisher.type == ComponentType.CONNECTOR
&& other.publisher.type != ComponentType.CONNECTOR) {
return 1;
}
// alphabetically
return name.compareTo(other.name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public JsonArray getInfo() {
private JsonObject toJson(DevReactiveMessagingInfos.DevChannelInfo channel) {
JsonObject json = new JsonObject();
json.put("name", channel.getName());
json.put("publisher", toJson(channel.getPublisher()));
json.put("publishers", toJson(channel.getPublishers()));
json.put("consumers", toJson(channel.getConsumers()));
return json;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public void testProcessor() throws Exception {
consumerExists = typeAndDescriptionExist(consumers, "CHANNEL",
"<code>io.quarkus.test.devui.MyProcessor#channel</code>");
}
JsonNode publisher = channel.get("publisher");
if (publisher != null) {
publisherExists = typeAndDescriptionExist(publisher, "PROCESSOR",
JsonNode publishers = channel.get("publishers");
if (publishers != null) {
publisherExists = typeAndDescriptionExist(publishers, "PROCESSOR",
"<code>io.quarkus.test.devui.MyProcessor#process()</code>");
}
}
Expand Down

0 comments on commit 5be91d9

Please sign in to comment.