Search in sources :

Example 1 with Locker

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;
}
Also used : Locker(nl.nn.adapterframework.util.Locker) SQLException(java.sql.SQLException) PipeLineResult(nl.nn.adapterframework.core.PipeLineResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) SQLException(java.sql.SQLException)

Example 2 with Locker

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;
}
Also used : TriggerState(org.quartz.Trigger.TriggerState) JobDetail(org.quartz.JobDetail) IbisJobDetail(nl.nn.adapterframework.scheduler.IbisJobDetail) JobDataMap(org.quartz.JobDataMap) Locker(nl.nn.adapterframework.util.Locker) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Scheduler(org.quartz.Scheduler) IJob(nl.nn.adapterframework.scheduler.job.IJob) DatabaseJob(nl.nn.adapterframework.scheduler.job.DatabaseJob) IbisJobDetail(nl.nn.adapterframework.scheduler.IbisJobDetail)

Example 3 with Locker

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());
}
Also used : Locker(nl.nn.adapterframework.util.Locker) Test(org.junit.Test)

Example 4 with Locker

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;
}
Also used : SendMessageJob(nl.nn.adapterframework.scheduler.job.SendMessageJob) Locker(nl.nn.adapterframework.util.Locker) IJob(nl.nn.adapterframework.scheduler.job.IJob)

Example 5 with Locker

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;
}
Also used : Locker(nl.nn.adapterframework.util.Locker) PipeLineResult(nl.nn.adapterframework.core.PipeLineResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeRunException(nl.nn.adapterframework.core.PipeRunException)

Aggregations

Locker (nl.nn.adapterframework.util.Locker)13 Test (org.junit.Test)5 PipeRunException (nl.nn.adapterframework.core.PipeRunException)4 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 HashMap (java.util.HashMap)2 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)2 IExtendedPipe (nl.nn.adapterframework.core.IExtendedPipe)2 PipeLineResult (nl.nn.adapterframework.core.PipeLineResult)2 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)2 FixedQuerySender (nl.nn.adapterframework.jdbc.FixedQuerySender)2 IbisJobDetail (nl.nn.adapterframework.scheduler.IbisJobDetail)2 SchedulerHelper (nl.nn.adapterframework.scheduler.SchedulerHelper)2 DatabaseJob (nl.nn.adapterframework.scheduler.job.DatabaseJob)2 IJob (nl.nn.adapterframework.scheduler.job.IJob)2 Scheduler (org.quartz.Scheduler)2 SchedulerException (org.quartz.SchedulerException)2 StringReader (java.io.StringReader)1 ResultSet (java.sql.ResultSet)1