Skip to content

Commit 9c8344a

Browse files
committed
initial commit
1 parent 25640d3 commit 9c8344a

32 files changed

Lines changed: 2969 additions & 51 deletions

File tree

core/common/iterator/src/main/java/org/eclipse/rdf4j/common/iteration/DistinctIteration.java

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
*
99
* SPDX-License-Identifier: BSD-3-Clause
1010
*******************************************************************************/
11-
11+
// Some portions generated by Codex
1212
package org.eclipse.rdf4j.common.iteration;
1313

14+
import java.lang.reflect.InvocationTargetException;
15+
import java.lang.reflect.Method;
1416
import java.util.HashSet;
1517
import java.util.Set;
1618
import java.util.function.Supplier;
@@ -20,6 +22,8 @@
2022
*/
2123
public class DistinctIteration<E> extends FilterIteration<E> {
2224

25+
private static final String OPERATOR_NAME = "DISTINCT";
26+
2327
/*-----------*
2428
* Variables *
2529
*-----------*/
@@ -76,6 +80,8 @@ public DistinctIteration(CloseableIteration<? extends E> iter, Supplier<Set<E>>
7680
*/
7781
@Override
7882
protected boolean accept(E object) {
83+
QueryExecutionContextBridge.markHeavy(OPERATOR_NAME);
84+
QueryExecutionContextBridge.checkpoint(OPERATOR_NAME);
7985
if (inExcludeSet(object)) {
8086
// object has already been returned
8187
return false;
@@ -104,4 +110,73 @@ private boolean inExcludeSet(E object) {
104110
protected boolean add(E object) {
105111
return excludeSet.add(object);
106112
}
113+
114+
private static final class QueryExecutionContextBridge {
115+
116+
private static final String QUERY_EXECUTION_CONTEXT_CLASS = "org.eclipse.rdf4j.http.client.QueryExecutionContext";
117+
118+
private static volatile boolean initialized;
119+
private static volatile Method markHeavyMethod;
120+
private static volatile Method checkpointMethod;
121+
122+
private QueryExecutionContextBridge() {
123+
}
124+
125+
private static void markHeavy(String operator) {
126+
Method method = getMethod(true);
127+
if (method != null) {
128+
invoke(method, operator);
129+
}
130+
}
131+
132+
private static void checkpoint(String operator) {
133+
Method method = getMethod(false);
134+
if (method != null) {
135+
invoke(method, operator);
136+
}
137+
}
138+
139+
private static Method getMethod(boolean markHeavy) {
140+
if (!initialized) {
141+
initialize();
142+
}
143+
return markHeavy ? markHeavyMethod : checkpointMethod;
144+
}
145+
146+
private static synchronized void initialize() {
147+
if (initialized) {
148+
return;
149+
}
150+
try {
151+
Class<?> contextType = Class.forName(QUERY_EXECUTION_CONTEXT_CLASS);
152+
markHeavyMethod = contextType.getMethod("markHeavy", String.class);
153+
checkpointMethod = contextType.getMethod("checkpoint", String.class);
154+
} catch (ClassNotFoundException | NoSuchMethodException e) {
155+
markHeavyMethod = null;
156+
checkpointMethod = null;
157+
}
158+
initialized = true;
159+
}
160+
161+
private static void invoke(Method method, String operator) {
162+
try {
163+
method.invoke(null, operator);
164+
} catch (IllegalAccessException e) {
165+
throw new IllegalStateException("Unable to access query execution context bridge", e);
166+
} catch (InvocationTargetException e) {
167+
throw propagate(e.getCause());
168+
}
169+
}
170+
171+
private static RuntimeException propagate(Throwable throwable) {
172+
if (throwable instanceof RuntimeException) {
173+
throw (RuntimeException) throwable;
174+
}
175+
if (throwable instanceof Error) {
176+
throw (Error) throwable;
177+
}
178+
throw new IllegalStateException("Unexpected checked exception from query execution context bridge",
179+
throwable);
180+
}
181+
}
107182
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 Eclipse RDF4J contributors.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Distribution License v1.0
6+
* which accompanies this distribution, and is available at
7+
* http://www.eclipse.org/org/documents/edl-v10.php.
8+
*
9+
* SPDX-License-Identifier: BSD-3-Clause
10+
*******************************************************************************/
11+
// Some portions generated by Codex
12+
package org.eclipse.rdf4j.http.client;
13+
14+
import java.util.concurrent.atomic.AtomicInteger;
15+
16+
public final class QueryExecutionContext {
17+
18+
private static final AtomicInteger MARK_HEAVY_CALLS = new AtomicInteger();
19+
private static final AtomicInteger CHECKPOINT_CALLS = new AtomicInteger();
20+
21+
private static volatile RuntimeException checkpointFailure;
22+
23+
private QueryExecutionContext() {
24+
}
25+
26+
public static void markHeavy(String operator) {
27+
MARK_HEAVY_CALLS.incrementAndGet();
28+
}
29+
30+
public static void checkpoint(String operator) {
31+
CHECKPOINT_CALLS.incrementAndGet();
32+
if (checkpointFailure != null) {
33+
throw checkpointFailure;
34+
}
35+
}
36+
37+
public static void failOnCheckpoint(RuntimeException runtimeException) {
38+
checkpointFailure = runtimeException;
39+
}
40+
41+
public static int getMarkHeavyCalls() {
42+
return MARK_HEAVY_CALLS.get();
43+
}
44+
45+
public static int getCheckpointCalls() {
46+
return CHECKPOINT_CALLS.get();
47+
}
48+
49+
public static void reset() {
50+
MARK_HEAVY_CALLS.set(0);
51+
CHECKPOINT_CALLS.set(0);
52+
checkpointFailure = null;
53+
}
54+
}

0 commit comments

Comments
 (0)