mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-11-05 09:36:19 +00:00
Add a discarding MetricsObserver
This is useful for test code where we don't care about the metrics gathered.
This commit is contained in:
parent
0ff58cdc3e
commit
ae5a661a47
@ -0,0 +1,23 @@
|
||||
// SPDX-FileCopyrightText: 2023 The CC: Tweaked Developers
|
||||
//
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
package dan200.computercraft.core.metrics;
|
||||
|
||||
/**
|
||||
* A {@link MetricsObserver} implementation which discards all metrics it receives.
|
||||
*/
|
||||
final class DiscardingMetricsObserver implements MetricsObserver {
|
||||
static final MetricsObserver INSTANCE = new DiscardingMetricsObserver();
|
||||
|
||||
private DiscardingMetricsObserver() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void observe(Metric.Counter counter) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void observe(Metric.Event event, long value) {
|
||||
}
|
||||
}
|
@ -31,4 +31,13 @@ public interface MetricsObserver {
|
||||
* @param value The value corresponding to this event.
|
||||
*/
|
||||
void observe(Metric.Event event, long value);
|
||||
|
||||
/**
|
||||
* Get a {@link MetricsObserver} which discards all metrics.
|
||||
*
|
||||
* @return An observer which discards all metrics.
|
||||
*/
|
||||
static MetricsObserver discard() {
|
||||
return DiscardingMetricsObserver.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import dan200.computercraft.core.computer.GlobalEnvironment;
|
||||
import dan200.computercraft.core.filesystem.FileMount;
|
||||
import dan200.computercraft.core.filesystem.JarMount;
|
||||
import dan200.computercraft.core.filesystem.MemoryMount;
|
||||
import dan200.computercraft.core.metrics.Metric;
|
||||
import dan200.computercraft.core.metrics.MetricsObserver;
|
||||
|
||||
import java.io.File;
|
||||
@ -27,7 +26,7 @@ import java.net.URL;
|
||||
* A basic implementation of {@link ComputerEnvironment} and {@link GlobalEnvironment}, suitable for a context which
|
||||
* will only run a single computer.
|
||||
*/
|
||||
public class BasicEnvironment implements ComputerEnvironment, GlobalEnvironment, MetricsObserver {
|
||||
public class BasicEnvironment implements ComputerEnvironment, GlobalEnvironment {
|
||||
private final WritableMount mount;
|
||||
|
||||
public BasicEnvironment() {
|
||||
@ -55,7 +54,7 @@ public class BasicEnvironment implements ComputerEnvironment, GlobalEnvironment,
|
||||
|
||||
@Override
|
||||
public MetricsObserver getMetrics() {
|
||||
return this;
|
||||
return MetricsObserver.discard();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -124,12 +123,4 @@ public class BasicEnvironment implements ComputerEnvironment, GlobalEnvironment,
|
||||
return new File(url.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void observe(Metric.Counter counter) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void observe(Metric.Event event, long value) {
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ import dan200.computercraft.core.computer.Computer;
|
||||
import dan200.computercraft.core.computer.ComputerEnvironment;
|
||||
import dan200.computercraft.core.computer.ComputerSide;
|
||||
import dan200.computercraft.core.filesystem.MemoryMount;
|
||||
import dan200.computercraft.core.metrics.Metric;
|
||||
import dan200.computercraft.core.metrics.MetricsObserver;
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import org.slf4j.Logger;
|
||||
@ -37,7 +36,7 @@ import java.util.Arrays;
|
||||
* <p>
|
||||
* This is exposed to Javascript via the {@link ComputerHandle} interface.
|
||||
*/
|
||||
class EmulatedComputer implements ComputerEnvironment, ComputerHandle, MetricsObserver {
|
||||
class EmulatedComputer implements ComputerEnvironment, ComputerHandle {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(EmulatedComputer.class);
|
||||
|
||||
private static final ComputerSide[] SIDES = ComputerSide.values();
|
||||
@ -124,15 +123,7 @@ class EmulatedComputer implements ComputerEnvironment, ComputerHandle, MetricsOb
|
||||
|
||||
@Override
|
||||
public MetricsObserver getMetrics() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void observe(Metric.Counter counter) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void observe(Metric.Event event, long value) {
|
||||
return MetricsObserver.discard();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user