wrapped attributeService in tx
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package com.inteligr8.alfresco.asie.service;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.attributes.AttributeService;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -24,29 +24,61 @@ public class ShardBackupService implements com.inteligr8.alfresco.asie.spi.Shard
|
||||
@Autowired
|
||||
@Qualifier(Constants.QUALIFIER_ASIE)
|
||||
private AttributeService attributeService;
|
||||
|
||||
@Autowired
|
||||
private TransactionService txService;
|
||||
|
||||
@Value("${inteligr8.asie.backup.persistTimeMinutes}")
|
||||
private int persistTimeMinutes;
|
||||
|
||||
public SolrHost selectNode(ShardSet shardSet, int shardId, SolrHost node) {
|
||||
return this.txService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<SolrHost>() {
|
||||
@Override
|
||||
public SolrHost execute() {
|
||||
return selectNodeTx(shardSet, shardId, node);
|
||||
}
|
||||
}, false, false);
|
||||
}
|
||||
|
||||
protected SolrHost selectNodeTx(ShardSet shardSet, int shardId, SolrHost node) {
|
||||
String shardKey = shardSet.getCore() + "-" + shardId;
|
||||
|
||||
PersistedNode backupNode = (PersistedNode) this.attributeService.getAttribute(Constants.ATTR_ASIE, ATTR_BACKUP_NODE, shardKey);
|
||||
this.logger.debug("Found backup node: {}", backupNode);
|
||||
logger.debug("Found backup node: {}", backupNode);
|
||||
|
||||
if (backupNode == null || backupNode.isExpired()) {
|
||||
backupNode = new PersistedNode(node, this.persistTimeMinutes);
|
||||
this.attributeService.setAttribute(backupNode, Constants.ATTR_ASIE, ATTR_BACKUP_NODE, shardKey);
|
||||
}
|
||||
|
||||
|
||||
return backupNode.getNode();
|
||||
}
|
||||
|
||||
public void forget() {
|
||||
this.txService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {
|
||||
@Override
|
||||
public Void execute() {
|
||||
forgetTx();
|
||||
return null;
|
||||
}
|
||||
}, false, false);
|
||||
}
|
||||
|
||||
protected void forgetTx() {
|
||||
this.attributeService.removeAttribute(Constants.ATTR_ASIE, ATTR_BACKUP_NODE);
|
||||
}
|
||||
|
||||
public void forget(ShardSet shardSet, int shardId) {
|
||||
public void forget(final ShardSet shardSet, final int shardId) {
|
||||
this.txService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {
|
||||
@Override
|
||||
public Void execute() {
|
||||
forgetTx(shardSet, shardId);
|
||||
return null;
|
||||
}
|
||||
}, false, false);
|
||||
}
|
||||
|
||||
public void forgetTx(ShardSet shardSet, int shardId) {
|
||||
String shardKey = shardSet.getCore() + "-" + shardId;
|
||||
this.attributeService.removeAttribute(Constants.ATTR_ASIE, ATTR_BACKUP_NODE, shardKey);
|
||||
}
|
||||
|
Reference in New Issue
Block a user