git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-publishing/document-store-lib-couchbase@146355 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9b664f88a7
commit
8f67991a34
2
pom.xml
2
pom.xml
|
@ -8,7 +8,7 @@
|
|||
</parent>
|
||||
<groupId>org.gcube.data.publishing</groupId>
|
||||
<artifactId>document-store-lib-couchbase</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>1.3.1-SNAPSHOT</version>
|
||||
<name>Document Store CouchBase Connector</name>
|
||||
<description>Document Store Connector for CouchBase</description>
|
||||
|
||||
|
|
|
@ -125,16 +125,35 @@ public class PersistenceCouchBase extends PersistenceBackend {
|
|||
//Bucket bucket = connectionMap.get(recordType);
|
||||
Bucket bucket = null;
|
||||
synchronized (Connections.connectionsMap) {
|
||||
/*
|
||||
String bucketNamesValue=bucketNames.get(recordType);
|
||||
logger.trace("bucketNamesValue:{}",bucketNamesValue);
|
||||
|
||||
Map<Nodes, Connection>conMap=Connections.connectionsMap;
|
||||
logger.trace("conMap:{}",conMap.toString());
|
||||
|
||||
logger.debug("nodes:{}",nodes.toString());
|
||||
Map<String,Bucket> mapStringBucket=conMap.get(nodes).getBucketsMap();
|
||||
|
||||
logger.trace("mapStringBucket:{}",mapStringBucket.toString());
|
||||
bucket =mapStringBucket.get(bucketNamesValue);
|
||||
*/
|
||||
//Old code
|
||||
bucket =Connections.connectionsMap.get(nodes).getBucketsMap().get(bucketNames.get(recordType));
|
||||
try {
|
||||
//logger.debug("PersistenceCouchBase getBucketConnection recordType:{}, bucket name:{}",recordType,bucketNames.get(recordType));
|
||||
if(bucket == null){
|
||||
//bucket = cluster.openBucket(recordType, password);
|
||||
bucket = Connections.connectionsMap.get(nodes).getCluster().openBucket(bucketNames.get(recordType), password);
|
||||
logger.trace("PersistenceCouchBase getBucketConnection bucket close, open:{}",bucket.toString() );
|
||||
//connectionMap.put(recordType, bucket);
|
||||
Connections.connectionsMap.get(nodes).getBucketsMap().put(bucketNames.get(recordType), bucket);
|
||||
logger.trace("PersistenceCouchBase getBucketConnection connectionMap:{}",Connections.connectionsMap.get(nodes).getBucketsMap());
|
||||
}
|
||||
if(bucket == null){
|
||||
//bucket = cluster.openBucket(recordType, password);
|
||||
bucket = Connections.connectionsMap.get(nodes).getCluster().openBucket(bucketNames.get(recordType), password);
|
||||
logger.trace("PersistenceCouchBase getBucketConnection bucket close, open:{}",bucket.toString() );
|
||||
//connectionMap.put(recordType, bucket);
|
||||
Connections.connectionsMap.get(nodes).getBucketsMap().put(bucketNames.get(recordType), bucket);
|
||||
logger.trace("PersistenceCouchBase getBucketConnection connectionMap:{}",Connections.connectionsMap.get(nodes).getBucketsMap());
|
||||
}
|
||||
} catch(Exception e) {
|
||||
logger.error("getBucketConnection connection error", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return bucket;
|
||||
}
|
||||
|
@ -165,7 +184,7 @@ public class PersistenceCouchBase extends PersistenceBackend {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void reallyAccount(Record record) throws Exception {
|
||||
protected void reallyAccount(Record record) throws Exception {
|
||||
JsonNode node = PersistenceCouchBase.usageRecordToJsonNode(record);
|
||||
JsonObject jsonObject = JsonObject.fromJson(node.toString());
|
||||
//get a bucket association
|
||||
|
@ -178,32 +197,36 @@ public class PersistenceCouchBase extends PersistenceBackend {
|
|||
*/
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
logger.debug("PersistenceCouchBase close" );
|
||||
logger.trace("PersistenceCouchBase close" );
|
||||
|
||||
}
|
||||
@Override
|
||||
protected void closeAndClean() throws Exception {
|
||||
synchronized (Connections.connectionsMap) {
|
||||
for (Map.Entry<String, Bucket> entry : Connections.connectionsMap.get(nodes).getBucketsMap().entrySet())
|
||||
{
|
||||
Boolean closed = entry.getValue().close();
|
||||
if (!closed){
|
||||
logger.warn("bucket not close :{}",entry.getKey());
|
||||
try {
|
||||
for (Map.Entry<String, Bucket> entry : Connections.connectionsMap.get(nodes).getBucketsMap().entrySet())
|
||||
{
|
||||
Boolean closed = entry.getValue().close();
|
||||
if (!closed){
|
||||
logger.warn("bucket not close :{}",entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
Boolean clusterClosed= Connections.connectionsMap.get(nodes).getCluster().disconnect();
|
||||
if (!clusterClosed){
|
||||
logger.warn("cluster not disconnect");
|
||||
}
|
||||
Connections.connectionsMap.remove(nodes);
|
||||
logger.trace("PersistenceCouchBase disconnect" );
|
||||
Boolean clusterClosed= Connections.connectionsMap.get(nodes).getCluster().disconnect();
|
||||
if (!clusterClosed){
|
||||
logger.warn("cluster not disconnect");
|
||||
}
|
||||
Connections.connectionsMap.remove(nodes);
|
||||
logger.trace("PersistenceCouchBase disconnect" );
|
||||
} catch(Exception e) {
|
||||
logger.error("closeAndClean error with close and clean", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void closeConnection() throws Exception {
|
||||
|
||||
logger.debug("PersistenceCouchBase closeConnection" );
|
||||
logger.trace("PersistenceCouchBase closeConnection" );
|
||||
};
|
||||
|
||||
|
||||
|
|
Reference in New Issue