Skip to content

Commit 38cfddf

Browse files
author
Jeen Broekstra
authored
Merge pull request #776 from Fedict/issues/#535-sailbase-timeout
Fix #535: Made timeout configurable
2 parents 2f0c07c + 6984a6b commit 38cfddf

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

core/sail/api/src/main/java/org/eclipse/rdf4j/sail/config/AbstractSailImplConfig.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public abstract class AbstractSailImplConfig implements SailImplConfig {
2727
private String type;
2828

2929
private long iterationCacheSyncThreshold;
30+
private long connectionTimeOut;
3031

3132
/**
3233
* Create a new RepositoryConfigImpl.
@@ -71,6 +72,10 @@ public Resource export(Model m) {
7172
vf.createLiteral(iterationCacheSyncThreshold));
7273
}
7374

75+
if (connectionTimeOut > 0) {
76+
m.add(implNode, SailConfigSchema.CONNECTION_TIME_OUT,
77+
vf.createLiteral(connectionTimeOut));
78+
}
7479
return implNode;
7580
}
7681

@@ -83,6 +88,9 @@ public void parse(Model m, Resource implNode)
8388
Models.objectLiteral(
8489
m.filter(implNode, SailConfigSchema.ITERATION_CACHE_SYNC_THRESHOLD, null)).ifPresent(
8590
lit -> setIterationCacheSyncThreshold(lit.longValue()));
91+
Models.objectLiteral(
92+
m.filter(implNode, SailConfigSchema.CONNECTION_TIME_OUT, null)).ifPresent(
93+
lit -> setConnectionTimeOut(lit.longValue()));
8694
}
8795
catch (ModelException e) {
8896
throw new SailConfigException(e.getMessage(), e);
@@ -103,4 +111,22 @@ public long getIterationCacheSyncThreshold() {
103111
public void setIterationCacheSyncThreshold(long iterationCacheSyncThreshold) {
104112
this.iterationCacheSyncThreshold = iterationCacheSyncThreshold;
105113
}
114+
115+
/**
116+
* Get the connection timeout (in ms).
117+
*
118+
* @return connection timeout (in ms)
119+
*/
120+
public long getConnectionTimeOut() {
121+
return connectionTimeOut;
122+
}
123+
124+
/**
125+
* Set the connection timeout (in ms).
126+
*
127+
* @param connectionTimeOut timeout (in ms)
128+
*/
129+
public void setConnectionTimeOut(long connectionTimeOut) {
130+
this.connectionTimeOut = connectionTimeOut;
131+
}
106132
}

core/sail/api/src/main/java/org/eclipse/rdf4j/sail/config/SailConfigSchema.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@ public class SailConfigSchema {
3232
/** <tt>http://www.openrdf.org/config/sail#iterationCacheSyncTreshold</tt> */
3333
public final static IRI ITERATION_CACHE_SYNC_THRESHOLD;
3434

35+
/** <tt>http://www.openrdf.org/config/sail#connectionTimeOut</tt> */
36+
public final static IRI CONNECTION_TIME_OUT;
37+
38+
3539
static {
3640
ValueFactory factory = SimpleValueFactory.getInstance();
3741
SAILTYPE = factory.createIRI(NAMESPACE, "sailType");
3842
DELEGATE = factory.createIRI(NAMESPACE, "delegate");
3943
ITERATION_CACHE_SYNC_THRESHOLD = factory.createIRI(NAMESPACE, "iterationCacheSyncTreshold");
44+
CONNECTION_TIME_OUT = factory.createIRI(NAMESPACE, "connectionTimeOut");
4045
}
4146
}

core/sail/api/src/main/java/org/eclipse/rdf4j/sail/helpers/AbstractSail.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ public AbstractSail() {
130130
* Methods *
131131
*---------*/
132132

133+
/**
134+
* Set connection timeout on shutdown (in ms).
135+
*
136+
* @param connectionTimeOut timeout (in ms)
137+
*/
138+
public void setConnectionTimeOut(long connectionTimeOut) {
139+
this.connectionTimeOut = connectionTimeOut;
140+
}
141+
133142
@Override
134143
public void setDataDir(File dataDir) {
135144
if (isInitialized()) {
@@ -212,7 +221,7 @@ public void shutDown()
212221
if (!activeConnections.isEmpty()) {
213222
logger.debug("Waiting for active connections to close before shutting down...");
214223
try {
215-
activeConnections.wait(DEFAULT_CONNECTION_TIMEOUT);
224+
activeConnections.wait(connectionTimeOut);
216225
}
217226
catch (InterruptedException e) {
218227
// ignore and continue

0 commit comments

Comments
 (0)