use of nl.nn.adapterframework.util.Locker in project iaf by ibissource.
the class LockerPipeLineProcessor method processPipeLine.
public PipeLineResult processPipeLine(PipeLine pipeLine, String messageId, String message, IPipeLineSession pipeLineSession, String firstPipe) throws PipeRunException {
PipeLineResult pipeLineResult;
Locker locker = pipeLine.getLocker();
String objectId = null;
if (locker != null) {
try {
objectId = locker.lock();
} catch (Exception e) {
boolean isUniqueConstraintViolation = false;
if (e instanceof SQLException) {
SQLException sqle = (SQLException) e;
isUniqueConstraintViolation = locker.getDbmsSupport().isUniqueConstraintViolation(sqle);
}
if (isUniqueConstraintViolation) {
String msg = "error while setting lock: " + e.getMessage();
log.info(msg);
} else {
throw new PipeRunException(null, "error while setting lock", e);
}
}
if (objectId != null) {
try {
pipeLineResult = pipeLineProcessor.processPipeLine(pipeLine, messageId, message, pipeLineSession, firstPipe);
} finally {
try {
locker.unlock(objectId);
} catch (Exception e) {
// throw new PipeRunException(null, "error while removing lock", e);
String msg = "error while removing lock: " + e.getMessage();
log.warn(msg);
}
}
} else {
pipeLineResult = new PipeLineResult();
pipeLineResult.setState("success");
}
} else {
pipeLineResult = pipeLineProcessor.processPipeLine(pipeLine, messageId, message, pipeLineSession, firstPipe);
}
return pipeLineResult;
}
use of nl.nn.adapterframework.util.Locker in project iaf by ibissource.
the class ShowScheduler method getJobData.
private Map<String, Object> getJobData(JobKey jobKey, boolean expanded) throws SchedulerException {
Map<String, Object> jobData = new HashMap<String, Object>();
Scheduler scheduler = getScheduler();
String jobName = jobKey.getName();
JobDetail job = scheduler.getJobDetail(jobKey);
jobData.put("fullName", job.getKey().getGroup() + "." + job.getKey().getName());
jobData.put("name", job.getKey().getName());
jobData.put("group", job.getKey().getGroup());
String description = "-";
if (StringUtils.isNotEmpty(job.getDescription()))
description = job.getDescription();
jobData.put("description", description);
jobData.put("stateful", job.isPersistJobDataAfterExecution() && job.isConcurrentExectionDisallowed());
jobData.put("durable", job.isDurable());
jobData.put("jobClass", job.getJobClass().getSimpleName());
if (job instanceof IbisJobDetail) {
jobData.put("type", ((IbisJobDetail) job).getJobType());
}
TriggerState state = scheduler.getTriggerState(TriggerKey.triggerKey(jobName, jobKey.getGroup()));
jobData.put("state", state.name());
jobData.put("triggers", getJobTriggers(scheduler.getTriggersOfJob(jobKey)));
jobData.put("messages", getJobMessages(job));
JobDataMap jobMap = job.getJobDataMap();
jobData.put("properties", getJobData(jobMap));
if (expanded) {
IJob jobDef = (IJob) jobMap.get(ConfiguredJob.JOBDEF_KEY);
if (jobDef instanceof DatabaseJob) {
DatabaseJob dbJob = (DatabaseJob) jobDef;
jobData.put("adapter", dbJob.getAdapterName());
jobData.put("listener", dbJob.getJavaListener());
jobData.put("message", dbJob.getMessage());
}
Locker locker = jobDef.getLocker();
if (locker != null) {
jobData.put("locker", true);
jobData.put("lockkey", locker.getObjectId());
} else {
jobData.put("locker", false);
}
}
return jobData;
}
use of nl.nn.adapterframework.util.Locker in project iaf by ibissource.
the class StreamingPipeTest method testCanProvideOutputStreamWithLocker.
@Test
public void testCanProvideOutputStreamWithLocker() throws ConfigurationException, PipeStartException {
Locker locker = new Locker() {
@Override
public void configure() throws ConfigurationException {
// skip configure, only need locker object to be present
}
};
pipe.setLocker(locker);
configureAndStartPipe();
assertFalse(pipe.canProvideOutputStream());
}
use of nl.nn.adapterframework.util.Locker in project iaf by ibissource.
the class IbisJobDetail method compareWith.
public boolean compareWith(IJob otherJobDef) {
IJob thisJobDef = getJobDef();
// If the CRON expression is different in both jobs, it's not equal!
if (!StringUtils.equals(thisJobDef.getCronExpression(), otherJobDef.getCronExpression())) {
return false;
}
// If the Interval expression is different in both jobs, it's not equal!
if (thisJobDef.getInterval() != otherJobDef.getInterval()) {
return false;
}
Locker thisLocker = thisJobDef.getLocker();
Locker otherLocker = otherJobDef.getLocker();
// If one is NULL but the other isn't, (locker has been removed or added, it's not equal!
if ((thisLocker == null && otherLocker != null) || (thisLocker != null && otherLocker == null)) {
return false;
}
// If both contain a locker but the key is different, it's not equal!
if (thisLocker != null && otherLocker != null && !StringUtils.equals(thisLocker.getObjectId(), otherLocker.getObjectId())) {
return false;
}
// If at this point the message is equal in both jobs, the jobs are equal!
if (thisJobDef instanceof SendMessageJob && otherJobDef instanceof SendMessageJob) {
String msg1 = ((SendMessageJob) thisJobDef).getMessage();
String msg2 = ((SendMessageJob) otherJobDef).getMessage();
return StringUtils.equals(msg1, msg2);
}
return true;
}
use of nl.nn.adapterframework.util.Locker in project iaf by ibissource.
the class LockerPipeLineProcessor method processPipeLine.
@Override
public PipeLineResult processPipeLine(PipeLine pipeLine, String messageId, Message message, PipeLineSession pipeLineSession, String firstPipe) throws PipeRunException {
PipeLineResult pipeLineResult;
Locker locker = pipeLine.getLocker();
String objectId = null;
if (locker != null) {
try {
objectId = locker.acquire();
} catch (Exception e) {
throw new PipeRunException(null, "error while setting lock [" + locker + "]", e);
}
if (objectId == null) {
log.info("could not obtain lock [" + locker + "]");
pipeLineResult = new PipeLineResult();
pipeLineResult.setState(ExitState.SUCCESS);
} else {
try {
pipeLineResult = pipeLineProcessor.processPipeLine(pipeLine, messageId, message, pipeLineSession, firstPipe);
} finally {
try {
locker.release(objectId);
} catch (Exception e) {
// throw new PipeRunException(null, "error while removing lock", e);
String msg = "error while removing lock [" + locker + "]: " + e.getMessage();
log.warn(msg);
}
}
}
} else {
pipeLineResult = pipeLineProcessor.processPipeLine(pipeLine, messageId, message, pipeLineSession, firstPipe);
}
return pipeLineResult;
}
Aggregations