-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
248 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 8 additions & 4 deletions
12
extensions/arc/deployment/src/main/resources/dev-templates/embedded.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
<a href="{urlbase}/beans" class="badge badge-light"> | ||
<i class="fa fa-egg fa-fw"></i> | ||
Beans <span class="badge badge-light">{info:devBeanInfos.beans.size()}</span></a> | ||
Beans <span class="badge badge-light">{info:devBeanInfos.beans.size}</span></a> | ||
<br> | ||
<a href="{urlbase}/observers" class="badge badge-light"> | ||
<i class="fa fa-eye fa-fw"></i> | ||
Observers <span class="badge badge-light">{info:arcContainer.observers.size()}</span></a> | ||
Observers <span class="badge badge-light">{info:arcContainer.observers.size}</span></a> | ||
<br> | ||
<a href="{urlbase}/events" class="badge badge-light"> | ||
<i class="far fa-eye"></i> | ||
Fired Events</a> | ||
<br> | ||
<a href="{urlbase}/removed-beans" class="badge badge-light"> | ||
<i class="fa fa-trash-alt fa-fw"></i> | ||
Removed Beans <span class="badge badge-light">{info:arcContainer.removedBeans.size()}</span></a> | ||
Removed Beans <span class="badge badge-light">{info:arcContainer.removedBeans.size}</span></a> | ||
<br> | ||
<span class="badge badge-light"> | ||
<i class="fa fa-traffic-light fa-fw"></i> | ||
Interceptors <span class="badge badge-light">{info:arcContainer.interceptors.size()}</span></span> | ||
Interceptors <span class="badge badge-light">{info:arcContainer.interceptors.size}</span></span> |
65 changes: 65 additions & 0 deletions
65
extensions/arc/deployment/src/main/resources/dev-templates/events.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{#include main fluid=true} | ||
{#style} | ||
.nav-item { | ||
padding: .5rem .3rem; | ||
} | ||
{/style} | ||
{#title}Fired Events{/title} | ||
{#body} | ||
<ul class="nav"> | ||
<li class="nav-item"> | ||
<input id="clear" type="submit" class="btn btn-primary btn-sm" value="Refresh" | ||
onClick="window.location.reload();"> | ||
</li> | ||
<li class="nav-item"> | ||
<form method="post" enctype="application/x-www-form-urlencoded" class="form-inline"> | ||
<input id="clear" type="submit" class="btn btn-primary btn-sm" value="Clear"> | ||
</form> | ||
</li> | ||
<li class="nav-item"> | ||
<form method="post" enctype="application/x-www-form-urlencoded" class="form-inline"> | ||
<input id="skipContextsCheck" type="checkbox" class="form-check-input" disabled{#if info:eventsMonitor.skipContextEvents} checked{/if}> | ||
<label for="skipContextsCheck">Skip context lifecycle events</label> | ||
<input type="hidden" name="action" value="skipContext"> | ||
| ||
<input id="toggle" type="submit" class="btn btn-primary btn-sm" value="Toggle"> | ||
</form> | ||
</li> | ||
</ul> | ||
<table class="table table-striped"> | ||
<thead class="thead-dark"> | ||
<tr> | ||
<th scope="col">#</th> | ||
<th scope="col">Event Type</th> | ||
<th scope="col">Qualifiers</th> | ||
<th scope="col">Timestamp</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{#for event in info:eventsMonitor.lastEvents} | ||
<tr> | ||
<td>{count}.</td> | ||
<td> | ||
<code>{event.type}</code> | ||
</td> | ||
<td> | ||
{#when event.qualifiers.size} | ||
{#is 1} | ||
<code>{event.qualifiers.iterator.next}</code> | ||
{#is > 1} | ||
<ul> | ||
{#for q in event.qualifiers} | ||
<li>{q}</li> | ||
{/for} | ||
</ul> | ||
{/when} | ||
</td> | ||
<td> | ||
{event.timestamp} | ||
</td> | ||
</tr> | ||
{/for} | ||
</tbody> | ||
</table> | ||
{/body} | ||
{/include} |
129 changes: 129 additions & 0 deletions
129
extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/devconsole/EventsMonitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package io.quarkus.arc.runtime.devconsole; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Type; | ||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.ListIterator; | ||
|
||
import javax.enterprise.context.BeforeDestroyed; | ||
import javax.enterprise.context.Destroyed; | ||
import javax.enterprise.context.Initialized; | ||
import javax.enterprise.event.Observes; | ||
import javax.enterprise.inject.Any; | ||
import javax.enterprise.inject.Default; | ||
import javax.enterprise.inject.spi.EventMetadata; | ||
import javax.inject.Singleton; | ||
|
||
// This bean is only registered in the dev mode | ||
@Singleton | ||
public class EventsMonitor { | ||
|
||
private static final int DEFAULT_EVENTS_LIMIT = 500; | ||
|
||
private volatile boolean skipContextEvents = true; | ||
private final List<EventInfo> events = Collections.synchronizedList(new ArrayList<EventInfo>(DEFAULT_EVENTS_LIMIT)); | ||
|
||
void notify(@Observes Object payload, EventMetadata eventMetadata) { | ||
if (skipContextEvents && isContextEvent(eventMetadata)) { | ||
return; | ||
} | ||
if (events.size() > DEFAULT_EVENTS_LIMIT) { | ||
// Remove some old data if the limit is exceeded | ||
synchronized (events) { | ||
if (events.size() > DEFAULT_EVENTS_LIMIT) { | ||
events.subList(0, DEFAULT_EVENTS_LIMIT / 2).clear(); | ||
} | ||
} | ||
} | ||
events.add(EventInfo.from(eventMetadata)); | ||
} | ||
|
||
public void clear() { | ||
events.clear(); | ||
} | ||
|
||
/** | ||
* @return mutable copy of the captured event information in reverse order | ||
*/ | ||
public List<EventInfo> getLastEvents() { | ||
synchronized (events) { | ||
List<EventInfo> result = new ArrayList<>(events.size()); | ||
for (ListIterator<EventInfo> iterator = events.listIterator(events.size()); iterator.hasPrevious();) { | ||
result.add(iterator.previous()); | ||
} | ||
return result; | ||
} | ||
} | ||
|
||
public boolean isSkipContextEvents() { | ||
return skipContextEvents; | ||
} | ||
|
||
public void toggleSkipContextEvents() { | ||
// This is not thread-safe but we don't expect concurrent actions from dev ui | ||
skipContextEvents = !skipContextEvents; | ||
} | ||
|
||
boolean isContextEvent(EventMetadata eventMetadata) { | ||
if (!eventMetadata.getType().equals(Object.class) || eventMetadata.getQualifiers().size() != 2) { | ||
return false; | ||
} | ||
for (Annotation qualifier : eventMetadata.getQualifiers()) { | ||
Type qualifierType = qualifier.annotationType(); | ||
// @Any, @Initialized, @BeforeDestroyed or @Destroyed | ||
if (!qualifierType.equals(Any.class) && !qualifierType.equals(Initialized.class) | ||
&& !qualifierType.equals(BeforeDestroyed.class) && !qualifierType.equals(Destroyed.class)) { | ||
|
||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
static class EventInfo { | ||
|
||
static EventInfo from(EventMetadata eventMetadata) { | ||
List<Annotation> qualifiers; | ||
if (eventMetadata.getQualifiers().size() == 1) { | ||
// Just @Any | ||
qualifiers = Collections.emptyList(); | ||
} else { | ||
qualifiers = new ArrayList<>(1); | ||
for (Annotation qualifier : eventMetadata.getQualifiers()) { | ||
// Skip @Any and @Default | ||
if (!qualifier.annotationType().equals(Any.class) && !qualifier.annotationType().equals(Default.class)) { | ||
qualifiers.add(qualifier); | ||
} | ||
} | ||
} | ||
return new EventInfo(eventMetadata.getType(), qualifiers); | ||
} | ||
|
||
private final LocalDateTime timestamp; | ||
private final Type type; | ||
private final List<Annotation> qualifiers; | ||
|
||
EventInfo(Type type, List<Annotation> qualifiers) { | ||
this.timestamp = LocalDateTime.now(); | ||
this.type = type; | ||
this.qualifiers = qualifiers; | ||
} | ||
|
||
public LocalDateTime getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
public String getType() { | ||
return type.getTypeName(); | ||
} | ||
|
||
public List<Annotation> getQualifiers() { | ||
return qualifiers; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters