From d0019c4e063ad42cfffca2ca847cf31051930dc6 Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Fri, 28 Jun 2019 16:11:16 +0200 Subject: [PATCH] Use generic types for Context classes in metric timers Signed-off-by: Edwin Kempin Change-Id: Ia28988a916ae67f7508bfebdff4b495e3762055d --- java/com/google/gerrit/metrics/Timer1.java | 15 +++++++-------- java/com/google/gerrit/metrics/Timer2.java | 17 ++++++++--------- java/com/google/gerrit/metrics/Timer3.java | 19 +++++++++---------- .../server/extensions/webui/UiActions.java | 2 +- .../server/notedb/AbstractChangeNotes.java | 2 +- .../server/notedb/ChangeNotesParser.java | 2 +- .../server/notedb/NoteDbUpdateManager.java | 4 ++-- .../gerrit/server/notedb/Sequences.java | 12 ++++++++---- .../server/plugincontext/PluginContext.java | 18 +++++++++--------- .../gerrit/server/project/ProjectState.java | 5 +++-- plugins/hooks | 2 +- plugins/replication | 2 +- 12 files changed, 51 insertions(+), 49 deletions(-) diff --git a/java/com/google/gerrit/metrics/Timer1.java b/java/com/google/gerrit/metrics/Timer1.java index 133b1f4dcf..c420e9ade4 100644 --- a/java/com/google/gerrit/metrics/Timer1.java +++ b/java/com/google/gerrit/metrics/Timer1.java @@ -37,13 +37,12 @@ import java.util.concurrent.TimeUnit; public abstract class Timer1 implements RegistrationHandle { private static final FluentLogger logger = FluentLogger.forEnclosingClass(); - public static class Context extends TimerContext { - private final Timer1 timer; - private final Object fieldValue; + public static class Context extends TimerContext { + private final Timer1 timer; + private final F1 fieldValue; - @SuppressWarnings("unchecked") - Context(Timer1 timer, F1 fieldValue) { - this.timer = (Timer1) timer; + Context(Timer1 timer, F1 fieldValue) { + this.timer = timer; this.fieldValue = fieldValue; } @@ -67,8 +66,8 @@ public abstract class Timer1 implements RegistrationHandle { * @param fieldValue bucket to record the timer * @return timer context */ - public Context start(F1 fieldValue) { - return new Context(this, fieldValue); + public Context start(F1 fieldValue) { + return new Context<>(this, fieldValue); } /** diff --git a/java/com/google/gerrit/metrics/Timer2.java b/java/com/google/gerrit/metrics/Timer2.java index 7c47e28ea1..fef2d9ac36 100644 --- a/java/com/google/gerrit/metrics/Timer2.java +++ b/java/com/google/gerrit/metrics/Timer2.java @@ -38,14 +38,13 @@ import java.util.concurrent.TimeUnit; public abstract class Timer2 implements RegistrationHandle { private static final FluentLogger logger = FluentLogger.forEnclosingClass(); - public static class Context extends TimerContext { - private final Timer2 timer; - private final Object fieldValue1; - private final Object fieldValue2; + public static class Context extends TimerContext { + private final Timer2 timer; + private final F1 fieldValue1; + private final F2 fieldValue2; - @SuppressWarnings("unchecked") - Context(Timer2 timer, F1 fieldValue1, F2 fieldValue2) { - this.timer = (Timer2) timer; + Context(Timer2 timer, F1 fieldValue1, F2 fieldValue2) { + this.timer = timer; this.fieldValue1 = fieldValue1; this.fieldValue2 = fieldValue2; } @@ -73,8 +72,8 @@ public abstract class Timer2 implements RegistrationHandle { * @param fieldValue2 bucket to record the timer * @return timer context */ - public Context start(F1 fieldValue1, F2 fieldValue2) { - return new Context(this, fieldValue1, fieldValue2); + public Context start(F1 fieldValue1, F2 fieldValue2) { + return new Context<>(this, fieldValue1, fieldValue2); } /** diff --git a/java/com/google/gerrit/metrics/Timer3.java b/java/com/google/gerrit/metrics/Timer3.java index 64e778750c..40c4882297 100644 --- a/java/com/google/gerrit/metrics/Timer3.java +++ b/java/com/google/gerrit/metrics/Timer3.java @@ -39,15 +39,14 @@ import java.util.concurrent.TimeUnit; public abstract class Timer3 implements RegistrationHandle { private static final FluentLogger logger = FluentLogger.forEnclosingClass(); - public static class Context extends TimerContext { - private final Timer3 timer; - private final Object fieldValue1; - private final Object fieldValue2; - private final Object fieldValue3; + public static class Context extends TimerContext { + private final Timer3 timer; + private final F1 fieldValue1; + private final F2 fieldValue2; + private final F3 fieldValue3; - @SuppressWarnings("unchecked") - Context(Timer3 timer, F1 f1, F2 f2, F3 f3) { - this.timer = (Timer3) timer; + Context(Timer3 timer, F1 f1, F2 f2, F3 f3) { + this.timer = timer; this.fieldValue1 = f1; this.fieldValue2 = f2; this.fieldValue3 = f3; @@ -79,8 +78,8 @@ public abstract class Timer3 implements RegistrationHandle { * @param fieldValue3 bucket to record the timer * @return timer context */ - public Context start(F1 fieldValue1, F2 fieldValue2, F3 fieldValue3) { - return new Context(this, fieldValue1, fieldValue2, fieldValue3); + public Context start(F1 fieldValue1, F2 fieldValue2, F3 fieldValue3) { + return new Context<>(this, fieldValue1, fieldValue2, fieldValue3); } /** diff --git a/java/com/google/gerrit/server/extensions/webui/UiActions.java b/java/com/google/gerrit/server/extensions/webui/UiActions.java index 947bec1732..41fcd9595a 100644 --- a/java/com/google/gerrit/server/extensions/webui/UiActions.java +++ b/java/com/google/gerrit/server/extensions/webui/UiActions.java @@ -143,7 +143,7 @@ public class UiActions { String name = e.getExportName().substring(d + 1); UiAction.Description dsc; - try (Timer1.Context ignored = uiActionLatency.start(name)) { + try (Timer1.Context ignored = uiActionLatency.start(name)) { dsc = ((UiAction) view).getDescription(resource); } diff --git a/java/com/google/gerrit/server/notedb/AbstractChangeNotes.java b/java/com/google/gerrit/server/notedb/AbstractChangeNotes.java index 1c6057d6ff..9c8bc1bda3 100644 --- a/java/com/google/gerrit/server/notedb/AbstractChangeNotes.java +++ b/java/com/google/gerrit/server/notedb/AbstractChangeNotes.java @@ -139,7 +139,7 @@ public abstract class AbstractChangeNotes { if (args.failOnLoadForTest.get()) { throw new StorageException("Reading from NoteDb is disabled"); } - try (Timer1.Context timer = args.metrics.readLatency.start(CHANGES); + try (Timer1.Context timer = args.metrics.readLatency.start(CHANGES); Repository repo = args.repoManager.openRepository(getProjectName()); // Call openHandle even if reading is disabled, to trigger // auto-rebuilding before this object may get passed to a ChangeUpdate. diff --git a/java/com/google/gerrit/server/notedb/ChangeNotesParser.java b/java/com/google/gerrit/server/notedb/ChangeNotesParser.java index 4fad58e3dc..27c2aa621c 100644 --- a/java/com/google/gerrit/server/notedb/ChangeNotesParser.java +++ b/java/com/google/gerrit/server/notedb/ChangeNotesParser.java @@ -187,7 +187,7 @@ class ChangeNotesParser { walk.reset(); walk.markStart(walk.parseCommit(tip)); - try (Timer1.Context timer = metrics.parseLatency.start(CHANGES)) { + try (Timer1.Context timer = metrics.parseLatency.start(CHANGES)) { ChangeNotesCommit commit; while ((commit = walk.next()) != null) { parse(commit); diff --git a/java/com/google/gerrit/server/notedb/NoteDbUpdateManager.java b/java/com/google/gerrit/server/notedb/NoteDbUpdateManager.java index e3a9a92364..32c8b064c9 100644 --- a/java/com/google/gerrit/server/notedb/NoteDbUpdateManager.java +++ b/java/com/google/gerrit/server/notedb/NoteDbUpdateManager.java @@ -267,7 +267,7 @@ public class NoteDbUpdateManager implements AutoCloseable { * @throws IOException if a storage layer error occurs. */ private void stage() throws IOException { - try (Timer1.Context timer = metrics.stageUpdateLatency.start(CHANGES)) { + try (Timer1.Context timer = metrics.stageUpdateLatency.start(CHANGES)) { if (isEmpty()) { return; } @@ -302,7 +302,7 @@ public class NoteDbUpdateManager implements AutoCloseable { executed = true; return null; } - try (Timer1.Context timer = metrics.updateLatency.start(CHANGES)) { + try (Timer1.Context timer = metrics.updateLatency.start(CHANGES)) { stage(); // ChangeUpdates must execute before ChangeDraftUpdates. // diff --git a/java/com/google/gerrit/server/notedb/Sequences.java b/java/com/google/gerrit/server/notedb/Sequences.java index 02cc2cd605..c989af4a5d 100644 --- a/java/com/google/gerrit/server/notedb/Sequences.java +++ b/java/com/google/gerrit/server/notedb/Sequences.java @@ -100,25 +100,29 @@ public class Sequences { } public int nextAccountId() { - try (Timer2.Context timer = nextIdLatency.start(SequenceType.ACCOUNTS, false)) { + try (Timer2.Context timer = + nextIdLatency.start(SequenceType.ACCOUNTS, false)) { return accountSeq.next(); } } public int nextChangeId() { - try (Timer2.Context timer = nextIdLatency.start(SequenceType.CHANGES, false)) { + try (Timer2.Context timer = + nextIdLatency.start(SequenceType.CHANGES, false)) { return changeSeq.next(); } } public ImmutableList nextChangeIds(int count) { - try (Timer2.Context timer = nextIdLatency.start(SequenceType.CHANGES, count > 1)) { + try (Timer2.Context timer = + nextIdLatency.start(SequenceType.CHANGES, count > 1)) { return changeSeq.next(count); } } public int nextGroupId() { - try (Timer2.Context timer = nextIdLatency.start(SequenceType.GROUPS, false)) { + try (Timer2.Context timer = + nextIdLatency.start(SequenceType.GROUPS, false)) { return groupSeq.next(); } } diff --git a/java/com/google/gerrit/server/plugincontext/PluginContext.java b/java/com/google/gerrit/server/plugincontext/PluginContext.java index a187d4c400..bb51a038ab 100644 --- a/java/com/google/gerrit/server/plugincontext/PluginContext.java +++ b/java/com/google/gerrit/server/plugincontext/PluginContext.java @@ -140,7 +140,7 @@ public class PluginContext { exportNameField); } - Timer3.Context startLatency(Extension extension) { + Timer3.Context startLatency(Extension extension) { return latency.start( extension.getPluginName(), extension.get().getClass().getName(), @@ -198,7 +198,7 @@ public class PluginContext { return; } try (TraceContext traceContext = newTrace(extension); - Timer3.Context ctx = pluginMetrics.startLatency(extension)) { + Timer3.Context ctx = pluginMetrics.startLatency(extension)) { extensionImplConsumer.run(extensionImpl); } catch (Throwable e) { pluginMetrics.incrementErrorCount(extension); @@ -227,7 +227,7 @@ public class PluginContext { } try (TraceContext traceContext = newTrace(extension); - Timer3.Context ctx = pluginMetrics.startLatency(extension)) { + Timer3.Context ctx = pluginMetrics.startLatency(extension)) { extensionConsumer.run(extension); } catch (Throwable e) { pluginMetrics.incrementErrorCount(extension); @@ -261,7 +261,7 @@ public class PluginContext { } try (TraceContext traceContext = newTrace(extension); - Timer3.Context ctx = pluginMetrics.startLatency(extension)) { + Timer3.Context ctx = pluginMetrics.startLatency(extension)) { extensionImplConsumer.run(extensionImpl); } catch (Throwable e) { Throwables.throwIfInstanceOf(e, exceptionClass); @@ -298,7 +298,7 @@ public class PluginContext { } try (TraceContext traceContext = newTrace(extension); - Timer3.Context ctx = pluginMetrics.startLatency(extension)) { + Timer3.Context ctx = pluginMetrics.startLatency(extension)) { extensionConsumer.run(extension); } catch (Throwable e) { Throwables.throwIfInstanceOf(e, exceptionClass); @@ -324,7 +324,7 @@ public class PluginContext { Extension extension, ExtensionImplFunction extensionImplFunction) { try (TraceContext traceContext = newTrace(extension); - Timer3.Context ctx = pluginMetrics.startLatency(extension)) { + Timer3.Context ctx = pluginMetrics.startLatency(extension)) { return extensionImplFunction.call(extension.get()); } } @@ -349,7 +349,7 @@ public class PluginContext { Class exceptionClass) throws X { try (TraceContext traceContext = newTrace(extension); - Timer3.Context ctx = pluginMetrics.startLatency(extension)) { + Timer3.Context ctx = pluginMetrics.startLatency(extension)) { try { return checkedExtensionImplFunction.call(extension.get()); } catch (Exception e) { @@ -378,7 +378,7 @@ public class PluginContext { Extension extension, ExtensionFunction, R> extensionFunction) { try (TraceContext traceContext = newTrace(extension); - Timer3.Context ctx = pluginMetrics.startLatency(extension)) { + Timer3.Context ctx = pluginMetrics.startLatency(extension)) { return extensionFunction.call(extension); } } @@ -404,7 +404,7 @@ public class PluginContext { Class exceptionClass) throws X { try (TraceContext traceContext = newTrace(extension); - Timer3.Context ctx = pluginMetrics.startLatency(extension)) { + Timer3.Context ctx = pluginMetrics.startLatency(extension)) { try { return checkedExtensionFunction.call(extension); } catch (Exception e) { diff --git a/java/com/google/gerrit/server/project/ProjectState.java b/java/com/google/gerrit/server/project/ProjectState.java index f657d9be4b..782ae84aee 100644 --- a/java/com/google/gerrit/server/project/ProjectState.java +++ b/java/com/google/gerrit/server/project/ProjectState.java @@ -354,14 +354,15 @@ public class ProjectState { * cached. Callers should try to cache this result per-request as much as possible. */ public List getAllSections() { - try (Timer1.Context ignored = computationLatency.start("getAllSections")) { + try (Timer1.Context ignored = computationLatency.start("getAllSections")) { if (isAllProjects) { return getLocalAccessSections(); } List all = new ArrayList<>(); Iterable tree = tree(); - try (Timer1.Context ignored2 = computationLatency.start("getAllSections-parsing-only")) { + try (Timer1.Context ignored2 = + computationLatency.start("getAllSections-parsing-only")) { for (ProjectState s : tree) { all.addAll(s.getLocalAccessSections()); } diff --git a/plugins/hooks b/plugins/hooks index 8c6baf54bc..d285496d44 160000 --- a/plugins/hooks +++ b/plugins/hooks @@ -1 +1 @@ -Subproject commit 8c6baf54bc9b889a8999815ef4281bc99efeed5e +Subproject commit d285496d44d8e49378910ea28fc8a77d4a86bf9f diff --git a/plugins/replication b/plugins/replication index 0ae2671124..c449ba1533 160000 --- a/plugins/replication +++ b/plugins/replication @@ -1 +1 @@ -Subproject commit 0ae2671124a94d8ec65966b653281759e271f339 +Subproject commit c449ba153358150927cb8d88e77f2b3d60d63ecc