Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
Can sommebody please help me with, how to create a SCHEDULE QUEUE Programmatically and add a schedule object to it!
Solved! Go to Solution.
To create a queue you can use the following java code.
public static ScheduleQueue createScheduleQueueIfNecessary(String queueName) throws WTException {
ScheduleQueue sq = (ScheduleQueue) QueueHelper.manager.getQueue(queueName, ScheduleQueue.class);
logger.debug("ScheduledQueue '" + queueName + "' exists? sq=" + sq);
//create queue itself if necessary
if (sq == null) {
sq = QueueHelper.manager.createScheduleQueue(queueName);
logger.debug("created ScheduledQueue '" + queueName + "': sq=" + sq);
}
return sq;
}
And to create an entry in this queue the following method can be used
public static void addNewScheduleQueueEntry(ScheduleQueue sq, String className, String methodName, Timestamp nextTime, String message) throws WTException {
//Adding an entry
Class[] argTypes = {String.class};
Object[] args = {message};
WTPrincipal administrator = SessionHelper.manager.getAdministrator();
WTPrincipal previous = SessionContext.setEffectivePrincipal(administrator);
try {
sq.addEntry(administrator, methodName, className, argTypes, args, nextTime);
logger.debug("added new queueEntry to call '" + className + "." + methodName + "' nextScheduledTime=" + nextTime);
} finally {
SessionContext.setEffectivePrincipal(previous);
}
}
To create a queue you can use the following java code.
public static ScheduleQueue createScheduleQueueIfNecessary(String queueName) throws WTException {
ScheduleQueue sq = (ScheduleQueue) QueueHelper.manager.getQueue(queueName, ScheduleQueue.class);
logger.debug("ScheduledQueue '" + queueName + "' exists? sq=" + sq);
//create queue itself if necessary
if (sq == null) {
sq = QueueHelper.manager.createScheduleQueue(queueName);
logger.debug("created ScheduledQueue '" + queueName + "': sq=" + sq);
}
return sq;
}
And to create an entry in this queue the following method can be used
public static void addNewScheduleQueueEntry(ScheduleQueue sq, String className, String methodName, Timestamp nextTime, String message) throws WTException {
//Adding an entry
Class[] argTypes = {String.class};
Object[] args = {message};
WTPrincipal administrator = SessionHelper.manager.getAdministrator();
WTPrincipal previous = SessionContext.setEffectivePrincipal(administrator);
try {
sq.addEntry(administrator, methodName, className, argTypes, args, nextTime);
logger.debug("added new queueEntry to call '" + className + "." + methodName + "' nextScheduledTime=" + nextTime);
} finally {
SessionContext.setEffectivePrincipal(previous);
}
}
Hey Kumarappan, thaku very much for your time! But now when i am trying to add a schedule entry in to the queue, it's giving me null pointer exception.
Hi,
this is working code. Try check the name of the queue.
Kumarappan.S
Hi,
Thanx....It's working now....error was due to method context...:)