Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
JAliEn
JAliEn
Commits
4c917a75
Commit
4c917a75
authored
Jun 26, 2018
by
Miguel Martinez Pedreira
Browse files
Improve singleton implementation of Cassandra interface
parent
3907c245
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/alien/test/cassandra/DBCassandra.java
View file @
4c917a75
...
...
@@ -19,12 +19,18 @@ import lazyj.ExtProperties;
*
*/
public
class
DBCassandra
{
private
static
DBCassandra
dbc
=
n
ew
DBCassandra
()
;
private
Session
session
=
null
;
private
Cluster
cluster
=
null
;
private
static
DBCassandra
dbc
=
n
ull
;
private
static
Session
session
=
null
;
private
static
Cluster
cluster
=
null
;
private
static
transient
final
Logger
logger
=
ConfigUtils
.
getLogger
(
DBCassandra
.
class
.
getCanonicalName
());
private
DBCassandra
()
{
}
private
synchronized
static
void
createInstance
()
{
if
(
dbc
==
null
)
dbc
=
new
DBCassandra
();
// Create the connection pool
final
PoolingOptions
poolingOptions
=
new
PoolingOptions
();
poolingOptions
.
setConnectionsPerHost
(
HostDistance
.
LOCAL
,
56
,
56
).
setConnectionsPerHost
(
HostDistance
.
REMOTE
,
56
,
56
);
...
...
@@ -57,11 +63,11 @@ public class DBCassandra {
}
}
cluster
=
Cluster
.
builder
().
addContactPoints
(
addresses
).
withLoadBalancingPolicy
(
new
TokenAwarePolicy
(
new
RoundRobinPolicy
())).
withPoolingOptions
(
poolingOptions
)
DBCassandra
.
cluster
=
Cluster
.
builder
().
addContactPoints
(
addresses
).
withLoadBalancingPolicy
(
new
TokenAwarePolicy
(
new
RoundRobinPolicy
())).
withPoolingOptions
(
poolingOptions
)
// .withSocketOptions(socketOptions)
.
withCredentials
(
user
,
pass
).
build
();
session
=
cluster
.
connect
();
DBCassandra
.
session
=
cluster
.
connect
();
}
/**
...
...
@@ -70,14 +76,22 @@ public class DBCassandra {
* @return the instance
*/
public
static
Session
getInstance
()
{
return
dbc
.
session
;
if
(
dbc
==
null
)
createInstance
();
return
DBCassandra
.
session
;
}
/**
*
*/
public
static
void
shutdown
()
{
dbc
.
session
.
close
();
dbc
.
cluster
.
close
();
DBCassandra
.
session
.
close
();
DBCassandra
.
cluster
.
close
();
}
@Override
public
Object
clone
()
throws
CloneNotSupportedException
{
throw
new
CloneNotSupportedException
();
}
}
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