RobotCore
1.0
WPILib port to raspberry Pi
Toggle main menu visibility
Loading...
Searching...
No Matches
EventLoop.java
1
// Copyright (c) FIRST and other WPILib contributors.
2
// Open Source Software; you can modify and/or share it under the terms of
3
// the WPILib BSD license file in the root directory of this project.
4
5
package
org.wpilib.event;
6
7
import
java.util.ConcurrentModificationException;
8
import
java.util.LinkedHashSet;
9
import
org.wpilib.util.container.WeakLinkedHashSet;
10
14
public
final
class
EventLoop
{
15
// Keep all bindings in one insertion-ordered collection for polling.
16
private
final
WeakLinkedHashSet<Runnable>
m_bindings =
new
WeakLinkedHashSet<>
();
17
// Keep strong references for strongly bound actions to prevent garbage collection.
18
private
final
LinkedHashSet<Runnable> m_strongBindings =
new
LinkedHashSet<>();
19
private
boolean
m_running;
20
22
public
EventLoop
() {}
23
31
public
void
bind
(Runnable action) {
32
if
(m_running) {
33
throw
new
ConcurrentModificationException(
"Cannot bind EventLoop while it is running"
);
34
}
35
m_bindings.add(action);
36
m_strongBindings.add(action);
37
}
38
45
public
void
bindWeak
(Runnable action) {
46
if
(m_running) {
47
throw
new
ConcurrentModificationException(
"Cannot bind EventLoop while it is running"
);
48
}
49
m_bindings.add(action);
50
}
51
58
public
boolean
isBound
(Runnable action) {
59
return
m_bindings.contains(action);
60
}
61
68
public
void
unbind
(Runnable action) {
69
if
(m_running) {
70
throw
new
ConcurrentModificationException(
"Cannot unbind EventLoop while it is running"
);
71
}
72
m_bindings.remove(action);
73
m_strongBindings.remove(action);
74
}
75
77
@SuppressWarnings(
"PMD.UnusedAssignment"
)
78
public
void
poll
() {
79
try
{
80
m_running =
true
;
81
m_bindings.forEach(Runnable::run);
82
}
finally
{
83
m_running =
false
;
84
}
85
}
86
88
public
void
clear
() {
89
if
(m_running) {
90
throw
new
ConcurrentModificationException(
"Cannot clear EventLoop while it is running"
);
91
}
92
m_bindings.clear();
93
m_strongBindings.clear();
94
}
95
}
org.wpilib.event.EventLoop.EventLoop
EventLoop()
Definition
EventLoop.java:22
org.wpilib.event.EventLoop.poll
void poll()
Definition
EventLoop.java:78
org.wpilib.event.EventLoop.bind
void bind(Runnable action)
Definition
EventLoop.java:31
org.wpilib.event.EventLoop.clear
void clear()
Definition
EventLoop.java:88
org.wpilib.event.EventLoop.bindWeak
void bindWeak(Runnable action)
Definition
EventLoop.java:45
org.wpilib.event.EventLoop.isBound
boolean isBound(Runnable action)
Definition
EventLoop.java:58
org.wpilib.event.EventLoop.unbind
void unbind(Runnable action)
Definition
EventLoop.java:68
org.wpilib.util.container.WeakLinkedHashSet
Definition
WeakLinkedHashSet.java:30
org.wpilib.util.container.WeakLinkedHashSet.WeakLinkedHashSet
WeakLinkedHashSet()
Definition
WeakLinkedHashSet.java:38
org
wpilib
event
EventLoop.java
Generated by
1.18.0