项目:dcp-api
文件:TaskPersisterJpa.java
@Override
public TaskStatusInfo getTaskToRun(String nodeId) {
List<TaskStatusInfo> tsi = listTasks(null,toRunTaskStatusFilter,0);
if (tsi != null && !tsi.isEmpty()) {
for (int i = tsi.size() - 1; i >= 0; i--) {
TaskStatusInfo work = tsi.get(i);
try {
em.lock(work,LockModeType.pessimistic_WRITE);
if (work.startTaskExecution(nodeId)) {
return work;
}
} catch (LockTimeoutException e) {
log.fine("Lock exception for task id=" + work.getId());
}
}
}
return null;
}
项目:dcp-api
文件:TaskPersisterJpa.java
@Override
public void heartbeat(String nodeId,Set<String> runningTasksId,long failoverTimeout) {
List<TaskStatusInfo> tsi = listTasks(null,runningTaskStatusFilter,0);
if (tsi != null && !tsi.isEmpty()) {
long ct = System.currentTimeMillis();
long ft = ct - failoverTimeout;
for (TaskStatusInfo task : tsi) {
try {
em.lock(task,LockModeType.pessimistic_WRITE);
if (task.getTaskStatus() == TaskStatus.RUNNING) {
if (runningTasksId != null && runningTasksId.contains(task.getId())) {
task.setHeartbeat(ct);
} else {
if (task.getHeartbeat() < ft) {
changeTaskStatus(task.getId(),TaskStatus.FAIlovER,"Failover necessity detected by node '" + nodeId
+ "' at " + ct + " due heartbeat timestamp " + task.getHeartbeat());
}
}
}
} catch (LockTimeoutException e) {
log.fine("Lock exception for task id=" + task.getId());
}
}
}
}
项目:searchisko
文件:TaskPersisterJpa.java
@Override
public TaskStatusInfo getTaskToRun(String nodeId) {
List<TaskStatusInfo> tsi = listTasks(null,0);
if (tsi != null && !tsi.isEmpty()) {
for (int i = tsi.size() - 1; i >= 0; i--) {
TaskStatusInfo work = tsi.get(i);
if (taskIsRunnableNow(nodeId,work)) {
try {
em.lock(work,LockModeType.pessimistic_WRITE);
if (work.startTaskExecution(nodeId)) {
return work;
}
} catch (LockTimeoutException e) {
log.fine("Lock exception for task id=" + work.getId());
}
}
}
}
return null;
}
项目:searchisko
文件:TaskPersisterJpa.java
@Override
public void heartbeat(String nodeId,"Failover necessity detected by node '" + nodeId
+ "' at " + ct + " due heartbeat timestamp " + task.getHeartbeat());
}
}
}
} catch (LockTimeoutException e) {
log.fine("Lock exception for task id=" + task.getId());
}
}
}
}
项目:lams
文件:EntityManagerFactoryUtils.java
/**
* Convert the given runtime exception to an appropriate exception from the
* {@code org.springframework.dao} hierarchy.
* Return null if no translation is appropriate: any other exception may
* have resulted from user code,and should not be translated.
* <p>The most important cases like object not found or optimistic locking failure
* are covered here. For more fine-granular conversion,JpaTransactionManager etc
* support sophisticated translation of exceptions via a JpaDialect.
* @param ex runtime exception that occurred
* @return the corresponding DataAccessException instance,* or {@code null} if the exception should not be translated
*/
public static DataAccessException convertJpaAccessExceptionIfPossible(RuntimeException ex) {
// Following the JPA specification,a persistence provider can also
// throw these two exceptions,besides PersistenceException.
if (ex instanceof IllegalStateException) {
return new InvalidDataAccessApiUsageException(ex.getMessage(),ex);
}
if (ex instanceof IllegalArgumentException) {
return new InvalidDataAccessApiUsageException(ex.getMessage(),ex);
}
// Check for well-kNown PersistenceException subclasses.
if (ex instanceof EntityNotFoundException) {
return new JpaObjectRetrievalFailureException((EntityNotFoundException) ex);
}
if (ex instanceof noresultException) {
return new EmptyResultDataAccessException(ex.getMessage(),1,ex);
}
if (ex instanceof NonUniqueResultException) {
return new IncorrectResultSizeDataAccessException(ex.getMessage(),ex);
}
if (ex instanceof QueryTimeoutException) {
return new org.springframework.dao.QueryTimeoutException(ex.getMessage(),ex);
}
if (ex instanceof LockTimeoutException) {
return new CannotAcquireLockException(ex.getMessage(),ex);
}
if (ex instanceof pessimisticLockException) {
return new pessimisticLockingFailureException(ex.getMessage(),ex);
}
if (ex instanceof OptimisticLockException) {
return new JpaOptimisticLockingFailureException((OptimisticLockException) ex);
}
if (ex instanceof EntityExistsException) {
return new DataIntegrityViolationException(ex.getMessage(),ex);
}
if (ex instanceof TransactionrequiredException) {
return new InvalidDataAccessApiUsageException(ex.getMessage(),ex);
}
// If we have another kind of PersistenceException,throw it.
if (ex instanceof PersistenceException) {
return new JpaSystemException((PersistenceException) ex);
}
// If we get here,we have an exception that resulted from user code,// rather than the persistence provider,so we return null to indicate
// that translation should not occur.
return null;
}
项目:spring4-understanding
文件:EntityManagerFactoryUtils.java
/**
* Convert the given runtime exception to an appropriate exception from the
* {@code org.springframework.dao} hierarchy.
* Return null if no translation is appropriate: any other exception may
* have resulted from user code,so we return null to indicate
// that translation should not occur.
return null;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。