Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

Check warning on line 18 in app/display/representation/src/main/java/org/csstudio/display/builder/representation/RepresentationUpdateThrottle.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import 'java.util.concurrent.atomic.AtomicInteger'.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AZ3OPG_t7vWMl7n6WBV9&open=AZ3OPG_t7vWMl7n6WBV9&pullRequest=3792
import java.util.logging.Level;

/** Handle throttled updates on UI thread.
Expand All @@ -38,9 +38,6 @@
@SuppressWarnings("nls")
public class RepresentationUpdateThrottle
{
/** Instance counter to aid in debugging the throttle start/shutdown */
private static final AtomicInteger instance = new AtomicInteger();

/** Period in seconds for logging update performance */
private static final int performance_log_period_secs = Preferences.performance_log_period_secs;

Expand All @@ -53,6 +50,9 @@
/** Pause between updates to prevent flooding the UI thread */
private static final long update_delay = Preferences.update_delay;

/** Singleton instance of this class */
private static RepresentationUpdateThrottle instance;

/** Executor for UI thread */
private final Executor gui_executor;

Expand All @@ -73,10 +73,23 @@
*/
private final Set<WidgetRepresentation<?, ?, ?>> updateable = new LinkedHashSet<>();

/** Get instance of this class to perform updates on the UI thread. This class
* is a singleton to ensure that only one thread is scheduling jobs on the UI
* thread.
*
* @param gui_executor Executor for UI thread
*/
public static RepresentationUpdateThrottle getInstance(final Executor gui_executor) {

Check warning on line 82 in app/display/representation/src/main/java/org/csstudio/display/builder/representation/RepresentationUpdateThrottle.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AZ3OLG8273P_lm5xqSEm&open=AZ3OLG8273P_lm5xqSEm&pullRequest=3792
if(instance == null) {
instance = new RepresentationUpdateThrottle(gui_executor);
}
return instance;
}

/** @param gui_executor Executor for UI thread */
public RepresentationUpdateThrottle(final Executor gui_executor)
private RepresentationUpdateThrottle(final Executor gui_executor)

Check warning on line 90 in app/display/representation/src/main/java/org/csstudio/display/builder/representation/RepresentationUpdateThrottle.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AZ3OLG8273P_lm5xqSEn&open=AZ3OLG8273P_lm5xqSEn&pullRequest=3792
{
final String name = "RepresentationUpdateThrottle" + instance.incrementAndGet();
final String name = "RepresentationUpdateThrottle";
logger.log(Level.FINE, "Create " + name);
this.gui_executor = gui_executor;
throttle_thread = new Thread(this::doRun);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ abstract public class ToolkitRepresentation<TWP extends Object, TW> implements E

private final boolean edit_mode;

private final RepresentationUpdateThrottle throttle = new RepresentationUpdateThrottle(this);
private final RepresentationUpdateThrottle throttle = RepresentationUpdateThrottle.getInstance(this);

/**
* Listener list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@SuppressWarnings("nls")
public class UpdateThrottleTest
{
private final RepresentationUpdateThrottle throttle = new RepresentationUpdateThrottle(Executors.newSingleThreadExecutor());
private final RepresentationUpdateThrottle throttle = RepresentationUpdateThrottle.getInstance(Executors.newSingleThreadExecutor());

private class TestWidgetRepresentation extends WidgetRepresentation<Object, Object, Widget>
{
Expand Down
Loading