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);
}
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);
}
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");
}
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));
}
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");
}
Aggregations