Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
joram
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
joram
joram
Commits
40b638d5
Commit
40b638d5
authored
Dec 13, 2020
by
Andre Freyssinet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix JDBCTransaction parameters for reconnect mechanism.
Adds a metod allowing to dump configuration properties.
parent
b7ae54aa
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
8 deletions
+62
-8
joram/a3/rt/src/main/java/fr/dyade/aaa/ext/JDBCTransaction.java
...a3/rt/src/main/java/fr/dyade/aaa/ext/JDBCTransaction.java
+26
-3
joram/a3/rt/src/main/java/fr/dyade/aaa/util/DBTransaction.java
.../a3/rt/src/main/java/fr/dyade/aaa/util/DBTransaction.java
+36
-5
No files found.
joram/a3/rt/src/main/java/fr/dyade/aaa/ext/JDBCTransaction.java
View file @
40b638d5
...
...
@@ -91,9 +91,13 @@ public class JDBCTransaction extends DBTransaction implements JDBCTransactionMBe
*/
public
final
static
String
JDBC_CONNECT_RETRY_COUNT_PROP
=
JDBC_TRANSACTION_PREFIX
+
".connect_retry_count"
;
/**
* This property is used to set the m
aximum time to attempt to reconnect after a failure, by default 60.000 (60
seconds).
* This property is used to set the m
inimum time between two attempts to reconnect after a failure, by default 1.000 (1
seconds).
*/
public
final
static
String
JDBC_CONNECT_RETRY_DELAY_PROP
=
JDBC_TRANSACTION_PREFIX
+
".connect_retry_delay"
;
public
final
static
String
JDBC_CONNECT_RETRY_MIN_DELAY_PROP
=
JDBC_TRANSACTION_PREFIX
+
".connect_retry_min_delay"
;
/**
* This property is used to set the maximum time trying to reconnect after a failure, by default 60.000 (60 seconds).
*/
public
final
static
String
JDBC_CONNECT_RETRY_MAX_PERIOD_PROP
=
JDBC_TRANSACTION_PREFIX
+
".connect_retry_max_period"
;
/**
* This property allows to define the SQL statement allowing to create the table used by the module, for example:
...
...
@@ -253,7 +257,11 @@ public class JDBCTransaction extends DBTransaction implements JDBCTransactionMBe
}
connectRetryCount
=
AgentServer
.
getInteger
(
JDBC_CONNECT_RETRY_COUNT_PROP
,
JDBC_CONNECT_RETRY_COUNT_DFLT
);
connectRetryDelay
=
AgentServer
.
getLong
(
JDBC_CONNECT_RETRY_DELAY_PROP
,
JDBC_CONNECT_RETRY_DELAY_DFLT
);
if
(
connectRetryCount
<
0
)
connectRetryCount
=
0
;
connectRetryMinDelay
=
AgentServer
.
getLong
(
JDBC_CONNECT_RETRY_MIN_DELAY_PROP
,
JDBC_CONNECT_RETRY_MIN_DELAY_DFLT
);
if
(
connectRetryMinDelay
<
0
)
connectRetryMinDelay
=
0
;
connectRetryMaxPeriod
=
AgentServer
.
getLong
(
JDBC_CONNECT_RETRY_MAX_PERIOD_PROP
,
JDBC_CONNECT_RETRY_MAX_PERIOD_DFLT
);
if
(
connectRetryMaxPeriod
<
0
)
connectRetryMaxPeriod
=
0
;
try
{
Class
.
forName
(
driver
).
newInstance
();
...
...
@@ -286,6 +294,7 @@ public class JDBCTransaction extends DBTransaction implements JDBCTransactionMBe
logmon
.
log
(
BasicLevel
.
WARN
,
"DBTransaction, init()"
,
sqle
);
}
}
logmon
.
log
(
BasicLevel
.
INFO
,
"DBTransaction, init(): "
+
dumpProperties
());
}
@Override
...
...
@@ -329,4 +338,18 @@ public class JDBCTransaction extends DBTransaction implements JDBCTransactionMBe
public
String
getPropertiesPath
()
{
return
path
;
}
protected
void
dumpProperties
(
StringBuilder
strbuf
)
{
super
.
dumpProperties
(
strbuf
);
strbuf
.
append
(
'('
).
append
(
"driver="
).
append
(
driver
).
append
(
')'
);
strbuf
.
append
(
'('
).
append
(
"url="
).
append
(
connurl
).
append
(
')'
);
strbuf
.
append
(
'('
).
append
(
"dbtable="
).
append
(
dbtable
).
append
(
')'
);
strbuf
.
append
(
'('
).
append
(
"dbname="
).
append
(
dbname
).
append
(
')'
);
strbuf
.
append
(
'('
).
append
(
"user="
).
append
(
user
).
append
(
')'
);
strbuf
.
append
(
'('
).
append
(
"password="
).
append
(
"***"
).
append
(
')'
);
strbuf
.
append
(
'('
).
append
(
"connect_retry_count="
).
append
(
connectRetryCount
).
append
(
')'
);
strbuf
.
append
(
'('
).
append
(
"connect_retry_min_delay="
).
append
(
connectRetryMinDelay
).
append
(
')'
);
strbuf
.
append
(
'('
).
append
(
"connect_retry_max_period="
).
append
(
connectRetryMaxPeriod
).
append
(
')'
);
}
}
joram/a3/rt/src/main/java/fr/dyade/aaa/util/DBTransaction.java
View file @
40b638d5
...
...
@@ -457,8 +457,10 @@ public abstract class DBTransaction extends AbstractTransaction implements DBTra
protected
final
int
JDBC_CONNECT_RETRY_COUNT_DFLT
=
5
;
protected
int
connectRetryCount
=
JDBC_CONNECT_RETRY_COUNT_DFLT
;
protected
final
long
JDBC_CONNECT_RETRY_DELAY_DFLT
=
60000L
;
protected
long
connectRetryDelay
=
JDBC_CONNECT_RETRY_DELAY_DFLT
;
protected
final
long
JDBC_CONNECT_RETRY_MAX_PERIOD_DFLT
=
60000L
;
protected
long
connectRetryMaxPeriod
=
JDBC_CONNECT_RETRY_MAX_PERIOD_DFLT
;
protected
final
long
JDBC_CONNECT_RETRY_MIN_DELAY_DFLT
=
1000L
;
protected
long
connectRetryMinDelay
=
JDBC_CONNECT_RETRY_MIN_DELAY_DFLT
;
public
final
synchronized
void
commit
(
boolean
release
)
throws
IOException
{
if
(
phase
!=
RUN
)
...
...
@@ -472,6 +474,7 @@ public abstract class DBTransaction extends AbstractTransaction implements DBTra
boolean
completed
=
false
;
int
retry
=
0
;
long
startRetry
=
0L
;
long
lastTry
=
0L
;
SQLException
lastexc
=
null
;
do
{
try
{
...
...
@@ -486,12 +489,25 @@ public abstract class DBTransaction extends AbstractTransaction implements DBTra
lastexc
=
sqle
;
retry
+=
1
;
if
((
connectRetryCount
>
0
)
&&
(
retry
>
connectRetryCount
))
break
;
long
time
=
System
.
currentTimeMillis
();
if
(
startRetry
==
0L
)
startRetry
=
time
;
if
(
startRetry
==
0L
)
startRetry
=
System
.
currentTimeMillis
()
;
if
((
connectRetry
Delay
>
0L
)
&&
((
System
.
currentTimeMillis
()
-
startRetry
)
>
connectRetryDelay
))
break
;
if
(
(
connectRetryCount
>
0
)
&&
(
retry
>
connectRetryCount
))
break
;
if
((
connectRetry
MaxPeriod
>
0L
)
&&
((
time
-
startRetry
)
>
connectRetryMaxPeriod
))
break
;
try
{
if
(
lastTry
==
0L
)
{
// It's the first retry do not wait.
lastTry
=
time
;
}
else
{
// Wait for at least configured delay
long
delay
=
connectRetryMinDelay
-
(
time
-
lastTry
);
lastTry
=
time
;
try
{
if
(
delay
>
0
)
Thread
.
sleep
(
delay
);
}
catch
(
InterruptedException
exc
)
{}
}
connectDB
();
createPreparedStatement
();
}
catch
(
IOException
exc
)
{}
...
...
@@ -808,6 +824,21 @@ public abstract class DBTransaction extends AbstractTransaction implements DBTra
logmon
.
log
(
BasicLevel
.
INFO
,
"DBTransaction, closed"
);
}
}
@Override
public
String
dumpProperties
()
{
StringBuilder
strbuf
=
new
StringBuilder
();
strbuf
.
append
(
'['
);
dumpProperties
(
strbuf
);
strbuf
.
append
(
']'
);
return
strbuf
.
toString
();
}
protected
void
dumpProperties
(
StringBuilder
strbuf
)
{
strbuf
.
append
(
'('
).
append
(
"dbtable="
).
append
(
dbtable
);
}
}
final
class
DBOperation
implements
Serializable
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment