Search in sources :

Example 6 with JobException

use of com.swiftmq.swiftlet.scheduler.JobException in project swiftmq-ce by iitsoftware.

the class QueueMoverJob method start.

public void start(Properties properties, JobTerminationListener jobTerminationListener) throws JobException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/start, properties=" + properties + " ...");
    this.properties = properties;
    int cnt = 0;
    String queueName = properties.getProperty("Source Queue");
    if (!queueName.startsWith("tpc$")) {
        MessageSelector selector = null;
        String s = properties.getProperty("Message Selector");
        if (s != null) {
            selector = new MessageSelector(s);
            try {
                selector.compile();
            } catch (InvalidSelectorException e) {
                throw new JobException(e.toString(), e, false);
            }
        }
        try {
            receiver = ctx.queueManager.createQueueReceiver(queueName, null, selector);
            pullTx = receiver.createTransaction(false);
            targetQueue = new QueueImpl(properties.getProperty("Target Queue"));
            sender = ctx.queueManager.createQueueSender(targetQueue.getQueueName(), null);
            pushTx = sender.createTransaction();
        } catch (Exception e) {
            throw new JobException(e.toString(), e, false);
        }
        if (stopCalled) {
            terminate();
            return;
        }
        try {
            MessageEntry entry = null;
            while ((entry = pullTx.getMessage(0, selector)) != null) {
                MessageImpl msg = entry.getMessage();
                msg.setJMSDestination(targetQueue);
                msg.setSourceRouter(null);
                msg.setDestRouter(null);
                pushTx.putMessage(msg);
                cnt++;
                pushTx.commit();
                pullTx.commit();
                if (stopCalled) {
                    terminate();
                    return;
                }
                pullTx = receiver.createTransaction(false);
                pushTx = sender.createTransaction();
            }
        } catch (Exception e) {
            terminate();
            throw new JobException(e.toString(), e, false);
        }
    }
    terminate();
    jobTerminationListener.jobTerminated(cnt + " Messages moved");
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/start, properties=" + properties + " done, cnt=" + cnt);
}
Also used : JobException(com.swiftmq.swiftlet.scheduler.JobException) InvalidSelectorException(javax.jms.InvalidSelectorException) MessageSelector(com.swiftmq.ms.MessageSelector) MessageImpl(com.swiftmq.jms.MessageImpl) QueueImpl(com.swiftmq.jms.QueueImpl) InvalidSelectorException(javax.jms.InvalidSelectorException) JobException(com.swiftmq.swiftlet.scheduler.JobException)

Example 7 with JobException

use of com.swiftmq.swiftlet.scheduler.JobException in project swiftmq-ce by iitsoftware.

the class QueuePurgerJob method start.

public void start(Properties properties, JobTerminationListener jobTerminationListener) throws JobException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/start, properties=" + properties + " ...");
    this.properties = properties;
    int cnt = 0;
    String queueName = properties.getProperty("Queue Name");
    if (!queueName.startsWith("tpc$")) {
        MessageSelector selector = null;
        String s = properties.getProperty("Message Selector");
        if (s != null) {
            selector = new MessageSelector(s);
            try {
                selector.compile();
            } catch (InvalidSelectorException e) {
                throw new JobException(e.toString(), e, false);
            }
        }
        try {
            receiver = ctx.queueManager.createQueueReceiver(queueName, null, selector);
            transaction = receiver.createTransaction(false);
        } catch (Exception e) {
            throw new JobException(e.toString(), e, false);
        }
        if (stopCalled) {
            terminate();
            return;
        }
        try {
            while (transaction.getMessage(0, selector) != null) {
                cnt++;
                transaction.commit();
                if (stopCalled) {
                    terminate();
                    return;
                }
                transaction = receiver.createTransaction(false);
            }
        } catch (Exception e) {
            terminate();
            throw new JobException(e.toString(), e, false);
        }
    }
    terminate();
    jobTerminationListener.jobTerminated(cnt + " Messages purged");
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/start, properties=" + properties + " done, cnt=" + cnt);
}
Also used : JobException(com.swiftmq.swiftlet.scheduler.JobException) InvalidSelectorException(javax.jms.InvalidSelectorException) MessageSelector(com.swiftmq.ms.MessageSelector) InvalidSelectorException(javax.jms.InvalidSelectorException) JobException(com.swiftmq.swiftlet.scheduler.JobException)

Example 8 with JobException

use of com.swiftmq.swiftlet.scheduler.JobException in project swiftmq-ce by iitsoftware.

the class QueueResetJob method start.

public void start(Properties properties, JobTerminationListener jobTerminationListener) throws JobException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/start, properties=" + properties + " ...");
    this.properties = properties;
    if (stopCalled) {
        terminate();
        return;
    }
    try {
        String predicate = properties.getProperty("Queue Name Predicate");
        String[] names = ctx.queueManager.getDefinedQueueNames();
        if (names != null) {
            for (int i = 0; i < names.length; i++) {
                if (LikeComparator.compare(names[i], predicate, '\\')) {
                    AbstractQueue queue = ctx.queueManager.getQueueForInternalUse(names[i]);
                    if (queue != null) {
                        if (ctx.traceSpace.enabled)
                            ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/reset: " + names[i]);
                        queue.resetCounters();
                    }
                }
                if (stopCalled)
                    break;
            }
        }
    } catch (Exception e) {
        terminate();
        throw new JobException(e.toString(), e, false);
    }
    terminate();
    jobTerminationListener.jobTerminated();
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/start, properties=" + properties + " done");
}
Also used : JobException(com.swiftmq.swiftlet.scheduler.JobException) AbstractQueue(com.swiftmq.swiftlet.queue.AbstractQueue) JobException(com.swiftmq.swiftlet.scheduler.JobException)

Example 9 with JobException

use of com.swiftmq.swiftlet.scheduler.JobException in project swiftmq-ce by iitsoftware.

the class BackupJob method start.

public synchronized void start(Properties properties, JobTerminationListener jobTerminationListener) throws JobException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.storeSwiftlet.getName(), toString() + "/start, properties=" + properties + " ...");
    this.jobTerminationListener = jobTerminationListener;
    this.properties = properties;
    Semaphore sem = new Semaphore();
    StartBackup po = new StartBackup(sem, this);
    ctx.backupProcessor.enqueue(po);
    sem.waitHere();
    if (!po.isSuccess())
        jobTerminationListener.jobTerminated(new JobException(po.getException(), new Exception(po.getException()), false));
}
Also used : JobException(com.swiftmq.swiftlet.scheduler.JobException) Semaphore(com.swiftmq.tools.concurrent.Semaphore) StartBackup(com.swiftmq.impl.store.standard.backup.po.StartBackup) JobException(com.swiftmq.swiftlet.scheduler.JobException)

Example 10 with JobException

use of com.swiftmq.swiftlet.scheduler.JobException in project swiftmq-ce by iitsoftware.

the class MessageSenderJob method start.

public void start(Properties properties, JobTerminationListener jobTerminationListener) throws JobException {
    id = properties.getProperty(ctx.PARM);
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.schedulerSwiftlet.getName(), toString() + "/start ...");
    try {
        MessageImpl msg = getMessage();
        String type = msg.getStringProperty(ctx.PROP_SCHED_DEST_TYPE).toLowerCase();
        String dest = msg.getStringProperty(ctx.PROP_SCHED_DEST);
        long expiration = 0;
        if (msg.propertyExists(ctx.PROP_SCHED_EXPIRATION))
            expiration = msg.getLongProperty(ctx.PROP_SCHED_EXPIRATION);
        List list = new ArrayList();
        for (Enumeration _enum = msg.getPropertyNames(); _enum.hasMoreElements(); ) {
            String name = (String) _enum.nextElement();
            if (name.startsWith("JMS_SWIFTMQ_SCHEDULER"))
                list.add(name);
        }
        for (int i = 0; i < list.size(); i++) msg.removeProperty((String) list.get(i));
        if (expiration > 0)
            msg.setJMSExpiration(System.currentTimeMillis() + expiration);
        msg.setJMSReplyTo(null);
        if (type.equals(ctx.QUEUE))
            sendToQueue(dest, msg);
        else
            sendToTopic(dest, msg);
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.schedulerSwiftlet.getName(), toString() + "/start, exception=" + e);
        throw new JobException(e.getMessage(), e, false);
    }
    jobTerminationListener.jobTerminated();
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.schedulerSwiftlet.getName(), toString() + "/start done");
}
Also used : JobException(com.swiftmq.swiftlet.scheduler.JobException) Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) MessageImpl(com.swiftmq.jms.MessageImpl) JobException(com.swiftmq.swiftlet.scheduler.JobException)

Aggregations

JobException (com.swiftmq.swiftlet.scheduler.JobException)11 MessageImpl (com.swiftmq.jms.MessageImpl)2 Entity (com.swiftmq.mgmt.Entity)2 Property (com.swiftmq.mgmt.Property)2 MessageSelector (com.swiftmq.ms.MessageSelector)2 AbstractQueue (com.swiftmq.swiftlet.queue.AbstractQueue)2 Semaphore (com.swiftmq.tools.concurrent.Semaphore)2 InvalidSelectorException (javax.jms.InvalidSelectorException)2 StartBackup (com.swiftmq.impl.store.standard.backup.po.StartBackup)1 StartShrink (com.swiftmq.impl.store.standard.cache.po.StartShrink)1 QueueImpl (com.swiftmq.jms.QueueImpl)1 QueueException (com.swiftmq.swiftlet.queue.QueueException)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 List (java.util.List)1