本文整理汇总了Java中org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback.execute方法的典型用法代码示例。如果您正苦于以下问题:Java RetryingTransactionCallback.execute方法的具体用法?Java RetryingTransactionCallback.execute怎么用?Java RetryingTransactionCallback.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback
的用法示例。
在下文中一共展示了RetryingTransactionCallback.execute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: contentStreamClosed
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; //导入方法依赖的package包/类
public final void contentStreamClosed() throws ContentIOException
{
RetryingTransactionCallback<Object> cb = new RetryingTransactionCallback<Object>()
{
public Object execute()
{
contentStreamClosedImpl();
return null;
}
};
if (transactionHelper != null)
{
// Execute in transaction.
transactionHelper.doInTransaction(cb, false);
}
else
{
try
{
cb.execute();
}
catch (Throwable e)
{
throw new ContentIOException("Failed to executed channel close callbacks", e);
}
}
}
示例2: executeAndCheck
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; //导入方法依赖的package包/类
/** Execute the callback and ensure that the backing cache is left with the expected value */
private void executeAndCheck(
RetryingTransactionCallback<Object> callback,
boolean readOnly,
String key,
Object expectedValue,
boolean mustContainKey) throws Throwable
{
if (expectedValue != null && !mustContainKey)
{
throw new IllegalArgumentException("Why have a value when the key should not be there?");
}
TransactionService transactionService = serviceRegistry.getTransactionService();
UserTransaction txn = transactionService.getUserTransaction(readOnly);
try
{
txn.begin();
callback.execute();
txn.commit();
}
finally
{
try { txn.rollback(); } catch (Throwable ee) {}
}
Object actualValue = TransactionalCache.getSharedCacheValue(backingCache, key, null);
assertEquals("Backing cache value was not correct", expectedValue, actualValue);
assertEquals("Backing cache contains(key): ", mustContainKey, backingCache.contains(key));
// Clear the backing cache to ensure that subsequent tests don't run into existing data
backingCache.clear();
}
示例3: executeAndCheck
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; //导入方法依赖的package包/类
private void executeAndCheck(NodeRef nodeRef, RetryingTransactionCallback<Object> callback) throws Throwable
{
UserTransaction txn = txnService.getUserTransaction();
txn.begin();
NodeRef.Status currentStatus = nodeService.getNodeStatus(nodeRef);
assertNotNull(currentStatus);
String currentTxnId = AlfrescoTransactionSupport.getTransactionId();
assertNotNull(currentTxnId);
assertNotSame(currentTxnId, currentStatus.getChangeTxnId());
try
{
callback.execute();
// get the status
NodeRef.Status newStatus = nodeService.getNodeStatus(nodeRef);
assertNotNull(newStatus);
// check
assertEquals("Change didn't update status", currentTxnId, newStatus.getChangeTxnId());
// Make sure we can pre-load the node i.e. nodes in all state need to be pre-loadable
// See CLOUD-1807
Long nodeId = newStatus.getDbId();
nodeDAO.getParentAssocs(nodeId, null, null, null, new DummyChildAssocRefQueryCallback());
nodeDAO.cacheNodesById(Collections.singletonList(nodeId));
txn.commit();
}
catch (Throwable e)
{
try { txn.rollback(); } catch (Throwable ee) {}
throw e;
}
}
示例4: testTransaction
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; //导入方法依赖的package包/类
public void testTransaction() throws Throwable
{
final boolean[] newTxn = new boolean[] {false};
RetryingTransactionCallback<Long> getTxnIdCallback = new RetryingTransactionCallback<Long>()
{
public Long execute() throws Throwable
{
return nodeDAO.getCurrentTransactionId(newTxn[0]);
}
};
// No txn
try
{
getTxnIdCallback.execute();
fail("Should have failed when running outside of a transaction");
}
catch (Throwable e)
{
// Expected
}
// Read-only
assertNull("No Txn ID should be present in read-only txn", txnHelper.doInTransaction(getTxnIdCallback, true));
// First success
Long txnId1 = txnHelper.doInTransaction(getTxnIdCallback);
assertNull("No Txn ID should be present in untouched txn", txnId1);
// Second success
newTxn[0] = true;
Long txnId2 = txnHelper.doInTransaction(getTxnIdCallback);
assertNotNull("Txn ID should be present by forcing it", txnId2);
}
示例5: testLockTimeout
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; //导入方法依赖的package包/类
/**
* Tests start and end with regard to locking. Going to cut down the timeout to a very short period, the lock should
* expire
*
* @throws Exception
*/
public void testLockTimeout() throws Exception
{
/**
* Simulates a client starting a transfer and then "going away";
*/
RetryingTransactionCallback<Object> startWithoutAnythingElse = new RetryingTransactionCallback<Object>()
{
public Object execute() throws Throwable
{
ftTransferReceiver.start("1234", true, ftTransferReceiver.getVersion());
return null;
}
};
RetryingTransactionCallback<Object> slowTransfer = new RetryingTransactionCallback<Object>()
{
public Object execute() throws Throwable
{
String transferId = ftTransferReceiver.start("1234", true, ftTransferReceiver.getVersion());
Thread.sleep(1000);
try
{
ftTransferReceiver.saveSnapshot(transferId, null);
fail("did not timeout");
}
catch (TransferException te)
{
// expect to go here with a timeout
}
return null;
}
};
long lockRefreshTime = ftTransferReceiver.getLockRefreshTime();
long lockTimeOut = ftTransferReceiver.getLockTimeOut();
try
{
ftTransferReceiver.setLockRefreshTime(500);
ftTransferReceiver.setLockTimeOut(200);
/**
* This test simulates a client that starts a transfer and then "goes away". We kludge the timeouts to far
* shorter than normal to make the test run in a reasonable time.
*/
for (int i = 0; i < 3; i++)
{
startWithoutAnythingElse.execute();
Thread.sleep(1000);
}
slowTransfer.execute();
}
catch (Throwable e)
{
e.printStackTrace();
fail();
}
finally
{
ftTransferReceiver.setLockRefreshTime(lockRefreshTime);
ftTransferReceiver.setLockTimeOut(lockTimeOut);
}
}