use of javax.jms.JMSException in project perun by CESNET.
the class SystemQueueProcessor method startProcessingSystemMessages.
public void startProcessingSystemMessages() {
connection = null;
try {
// Step 2. Instantiate the TransportConfiguration object which
// contains the knowledge of what transport to use,
// The server port etc.
log.debug("Creating transport configuration...");
Map<String, Object> connectionParams = new HashMap<String, Object>();
if (log.isDebugEnabled()) {
log.debug("Gonna connect to the host[" + dispatcherPropertiesBean.getProperty("dispatcher.ip.address") + "] on port[" + dispatcherPropertiesBean.getProperty("dispatcher.port") + "]...");
}
connectionParams.put(TransportConstants.PORT_PROP_NAME, Integer.parseInt(dispatcherPropertiesBean.getProperty("dispatcher.port")));
connectionParams.put(TransportConstants.HOST_PROP_NAME, dispatcherPropertiesBean.getProperty("dispatcher.ip.address"));
TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName(), connectionParams);
// Step 3 Directly instantiate the JMS ConnectionFactory object
// using that TransportConfiguration
log.debug("Creating connection factory...");
cf = (ConnectionFactory) HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, transportConfiguration);
((HornetQConnectionFactory) cf).setUseGlobalPools(false);
// Step 4.Create a JMS Connection
log.debug("Creating connection...");
connection = cf.createConnection();
// Step 5. Create a JMS Session
log.debug("Creating session...");
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Step 10. Start the Connection
log.debug("Starting connection...");
connection.start();
if (processingMessages) {
systemQueueReceiver.stop();
}
systemQueueReceiver.setUp("systemQueue", session);
log.debug("Executor: taskExecutor.execute(systemQueueReceiver)...");
taskExecutor.execute(systemQueueReceiver);
log.debug("Initialization done.");
processingMessages = true;
} catch (JMSException e) {
// If unable to connect to the server...
log.error("Connection failed. \nThis is weird...are you sure that the Perun-Dispatcher is running on host[" + dispatcherPropertiesBean.getProperty("dispatcher.ip.address") + "] on port[" + dispatcherPropertiesBean.getProperty("dispatcher.port") + "] ? \nSee: perun-dispatcher.properties. We gonna wait 5 sec and try again...", e);
throw new RuntimeException(e);
} catch (Exception e) {
log.error(e.toString(), e);
}
}
use of javax.jms.JMSException in project perun by CESNET.
the class PropagationMaintainerImpl method checkFinishedTasks.
/*
* private void checkProcessingTasks() {
* log.info("Gonna list tasks in PROCESSING...");
*
* for(Task task: schedulingPool.getProcessingTasks()) {
* if(task.getExecService
* ().getExecServiceType().equals(ExecService.ExecServiceType.GENERATE))
* continue; log.info("Gonna check results for Task ID:" + task.getId());
*
* }
*
* for (Task task : taskManager.listAllTasksInState(TaskStatus.PROCESSING,
* Integer.parseInt(propertiesBean.getProperty("engine.unique.id")))) {
* //skip GEN tasks
* if(task.getExecService().getExecServiceType().equals(ExecService
* .ExecServiceType.GENERATE)) continue;
* log.info("Gonna check results for Task ID:" + task.getId());
*
* List<TaskResult> taskResults =
* taskResultDao.getTaskResultsByTask(task.getId());
*
* List<Destination> destinations = null; try { destinations =
* Rpc.ServicesManager.getDestinations(engineManager.getRpcCaller(),
* task.getExecService().getService(), task.getFacility()); }
* catch(InternalErrorException ex) {
* log.error("Can't get destinations. Switching task to ERROR. Cause: {}",
* ex); task.setStatus(TaskStatus.ERROR); task.setEndTime(new
* Date(System.currentTimeMillis())); taskManager.updateTask(task,
* Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); }
* catch(PrivilegeException ex) {
* log.error("Can't get destinations. Switching task to ERROR. Cause: {}",
* ex); task.setStatus(TaskStatus.ERROR); task.setEndTime(new
* Date(System.currentTimeMillis())); taskManager.updateTask(task,
* Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); }
* catch(ServiceNotExistsException ex) {
* log.error("Service for the task no longer exists. Removing task", ex);
* taskManager.removeTask(task.getId(),
* Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); }
* catch(FacilityNotExistsException ex) {
* log.error("Facility for the task no longer exists. Removing task", ex);
* taskManager.removeTask(task.getId(),
* Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); }
*
* switch(task.getType()) {
*
* case SERIAL: collectSerialTaskResults(task, taskResults, destinations);
* break;
*
* case PARALLEL: collectParallelTaskResults(task, taskResults,
* destinations); break;
*
* default: log.error("Unknown task type. Assuming parallel.");
* collectParallelTaskResults(task, taskResults, destinations); break; } } }
*
*
* private void collectSerialTaskResults(Task task, List<TaskResult>
* taskResults, List<Destination> destinations) { if (taskResults.size() <=
* destinations.size()) { // Let's check whether they are all DONE or not...
* int amountDone = 0; int amountDenied = 0; int amountError = 0; int
* amountFatalError = 0; for (TaskResult taskResult : taskResults) { switch
* (taskResult.getStatus()) { case DONE: amountDone++; break; case DENIED:
* amountDenied++; break; case ERROR: amountError++; break; case
* FATAL_ERROR: amountFatalError++; break; default: throw new
* IllegalArgumentException("WTF?! " + taskResult.getStatus().toString()); }
* }
*
* if (amountDone > 0) { // Super, at least one task is DONE.
* log.info("Task ID " + task.getId() +
* " has one Tasks_result DONE, so we set it as DONE.");
* task.setStatus(TaskStatus.DONE); task.setEndTime(new
* Date(System.currentTimeMillis())); taskManager.updateTask(task,
* Integer.parseInt(propertiesBean.getProperty("engine.unique.id")));
*
* //Set its GENERATE dependencies as dirty //TODO: Hmm...what to do in case
* of exceptions?
*
* try { log.info("I am going to set all ExecService " +
* task.getExecServiceId() + " dependencies (the GENERATE ones) to NONE.");
* setAllGenerateDependenciesToNone
* (dependenciesResolver.listDependencies(task.getExecServiceId()),
* task.getFacilityId()); } catch (ServiceNotExistsException e) {
* log.error(e.toString(), e); } catch (InternalErrorException e) {
* log.error(e.toString(), e); } catch (PrivilegeException e) {
* log.error(e.toString(), e); } } else { //TODO Now FATAL_ERROR and ERROR
* are being treated exactly the same. Is FATAL_ERROR really necessary? //
* Not DONE yet, are there any destinations left? if (taskResults.size() ==
* destinations.size()) { // Well, we ended in ERROR... log.info(
* "There has been no DONE state Tasks_results, so I am going to set the Task ID"
* + task.getId() + " to ERROR."); task.setStatus(TaskStatus.ERROR);
* task.setEndTime(new Date(System.currentTimeMillis()));
* taskManager.updateTask(task,
* Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); //Set
* its GENERATE dependencies as dirty //TODO: Hmm...what to do in case of
* exceptions?
*
* try {
* setAllGenerateDependenciesToNone(dependenciesResolver.listDependencies
* (task.getExecServiceId()), task.getFacilityId()); } catch
* (ServiceNotExistsException e) { log.error(e.toString(), e); } catch
* (InternalErrorException e) { log.error(e.toString(), e); } catch
* (PrivilegeException e) { log.error(e.toString(), e); } } else { // There
* are some destinations left to try, schedule it back
* task.setStatus(TaskStatus.PLANNED); task.setSchedule(new
* Date(System.currentTimeMillis())); taskManager.updateTask(task,
* Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); } } }
* else if (taskResults.size() > destinations.size()) { log.error(
* "There are more Task_results then destinations. so I am going to set the Task ID"
* + task.getId() + " to ERROR."); task.setStatus(TaskStatus.ERROR);
* task.setEndTime(new Date(System.currentTimeMillis()));
* taskManager.updateTask(task,
* Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); //Set
* its GENERATE dependencies as dirty //TODO: Hmm...what to do in case of
* exceptions? try {
* setAllGenerateDependenciesToNone(dependenciesResolver.listDependencies
* (task.getExecServiceId()), task.getFacilityId()); } catch
* (ServiceNotExistsException e) { log.error(e.toString(), e); } catch
* (InternalErrorException e) { log.error(e.toString(), e); } catch
* (PrivilegeException e) { log.error(e.toString(), e); } }
*
* if(false) { final long THREE_HOUR = 1000 * 60 * 60 * 3; long
* timeDifference = System.currentTimeMillis() -
* task.getStartTime().getTime(); if(timeDifference > THREE_HOUR) { // //
* WARNING!! // // This can be dangerous. We are not sure if there isn't any
* slave script running for this task. // log.error("There are only " +
* taskResults.size() + " Task_results for Task ID" + task.getId() +
* ", but task is in processing too long, so switch task to ERROR");
* task.setStatus(TaskStatus.ERROR); task.setEndTime(new
* Date(System.currentTimeMillis())); taskManager.updateTask(task,
* Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); //Set
* its GENERATE dependencies as dirty //TODO: Hmm...what to do in case of
* exceptions? try {
* setAllGenerateDependenciesToNone(dependenciesResolver.listDependencies
* (task.getExecServiceId()), task.getFacilityId()); } catch
* (ServiceNotExistsException e) { log.error(e.toString(), e); } catch
* (InternalErrorException e) { log.error(e.toString(), e); } catch
* (PrivilegeException e) { log.error(e.toString(), e); } }
*
* log.info("There are only " + taskResults.size() +
* " Task_results for Task ID" + task.getId() +
* ", so we ain't gonna do anything."); // Well, we ain't gonna do anything
* bro... // TODO: Time out... } }
*
* private void collectParallelTaskResults(Task task, List<TaskResult>
* taskResults, List<Destination> destinations) { // Do we have the same
* number of Destinations as we have TaskResults? if (taskResults.size() ==
* destinations.size()) { // Let's check whether they are all DONE or not...
* int amountDone = 0; int amountDenied = 0; int amountError = 0; int
* amountFatalError = 0; for (TaskResult taskResult : taskResults) { switch
* (taskResult.getStatus()) { case DONE: amountDone++; break; case DENIED:
* amountDenied++; break; case ERROR: amountError++; break; case
* FATAL_ERROR: amountFatalError++; break; default: throw new
* IllegalArgumentException("WTF?! " + taskResult.getStatus().toString()); }
* }
*
* if (amountDone + amountDenied == taskResults.size()) { // Super, all is
* DONE or we don't care (DENIED) :-) log.info("Task ID " + task.getId() +
* " has all Tasks_results either DONE or DENIED, so we set it as DONE.");
* task.setStatus(TaskStatus.DONE); task.setEndTime(new
* Date(System.currentTimeMillis())); taskManager.updateTask(task,
* Integer.parseInt(propertiesBean.getProperty("engine.unique.id")));
*
* //Set its GENERATE dependencies as dirty //TODO: Hmm...what to do in case
* of exceptions? try { log.info("I am going to set all ExecService " +
* task.getExecServiceId() + " dependencies (the GENERATE ones) to NONE.");
*
* setAllGenerateDependenciesToNone(dependenciesResolver.listDependencies(task
* .getExecServiceId()), task.getFacilityId()); } catch
* (ServiceNotExistsException e) { log.error(e.toString(), e); } catch
* (InternalErrorException e) { log.error(e.toString(), e); } catch
* (PrivilegeException e) { log.error(e.toString(), e); } } else { final
* long TWO_HOUR = 1000 * 60 * 60 * 2; long timeDifference =
* System.currentTimeMillis() - task.getStartTime().getTime();
* if(timeDifference > TWO_HOUR) { // // WARNING!! // // This can be
* dangerous. We are not sure if there isn't any slave script running for
* this task. // log.error("There are only " + taskResults.size() +
* " Task_results for Task ID" + task.getId() +
* ", but task is in processing too long, so switch task to ERROR");
* task.setStatus(TaskStatus.ERROR); task.setEndTime(new
* Date(System.currentTimeMillis())); taskManager.updateTask(task,
* Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); //Set
* its GENERATE dependencies as dirty //TODO: Hmm...what to do in case of
* exceptions? try {
* setAllGenerateDependenciesToNone(dependenciesResolver.listDependencies
* (task.getExecServiceId()), task.getFacilityId()); } catch
* (ServiceNotExistsException e) { log.error(e.toString(), e); } catch
* (InternalErrorException e) { log.error(e.toString(), e); } catch
* (PrivilegeException e) { log.error(e.toString(), e); } } } } else if
* (taskResults.size() > destinations.size()) { log.error(
* "There are more Task_results then destinations. so I am going to set the Task ID"
* + task.getId() + " to ERROR."); task.setStatus(TaskStatus.ERROR);
* task.setEndTime(new Date(System.currentTimeMillis()));
* taskManager.updateTask(task,
* Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); //Set
* its GENERATE dependencies as dirty //TODO: Hmm...what to do in case of
* exceptions? try {
* setAllGenerateDependenciesToNone(dependenciesResolver.listDependencies
* (task.getExecServiceId()), task.getFacilityId()); } catch
* (ServiceNotExistsException e) { log.error(e.toString(), e); } catch
* (InternalErrorException e) { log.error(e.toString(), e); } catch
* (PrivilegeException e) { log.error(e.toString(), e); } } else { final
* long THREE_HOUR = 1000 * 60 * 60 * 3; long timeDifference =
* System.currentTimeMillis() - task.getStartTime().getTime();
* if(timeDifference > THREE_HOUR) { // // WARNING!! // // This can be
* dangerous. We are not sure if there isn't any slave script running for
* this task. // log.error("There are only " + taskResults.size() +
* " Task_results for Task ID" + task.getId() +
* ", but task is in processing too long, so switch task to ERROR");
* task.setStatus(TaskStatus.ERROR); task.setEndTime(new
* Date(System.currentTimeMillis())); taskManager.updateTask(task,
* Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); //Set
* its GENERATE dependencies as dirty //TODO: Hmm...what to do in case of
* exceptions? try {
* setAllGenerateDependenciesToNone(dependenciesResolver.listDependencies
* (task.getExecServiceId()), task.getFacilityId()); } catch
* (ServiceNotExistsException e) { log.error(e.toString(), e); } catch
* (InternalErrorException e) { log.error(e.toString(), e); } catch
* (PrivilegeException e) { log.error(e.toString(), e); } }
*
* log.info("There are only " + taskResults.size() +
* " Task_results for Task ID" + task.getId() +
* ", so we ain't gonna do anything."); // Well, we ain't gonna do anything
* bro... // TODO: Time out... } }
*/
private void checkFinishedTasks() {
// report finished tasks back to scheduler
// clear all tasks we are done with (ie. DONE, ERROR with no recurrence
// left)
List<Task> tasklist = schedulingPool.getDoneTasks();
log.debug("There are {} DONE tasks", tasklist.size());
for (Task task : tasklist) {
if (task.getEndTime() == null) {
log.error("RECOVERY FROM INCONSISTENT STATE: DONE task does not have end_time! Setting end_time to now.");
Date endTime = new Date(System.currentTimeMillis());
task.setEndTime(endTime);
}
log.debug("TASK " + task.toString() + " finished");
try {
log.debug("TASK reported as finished at " + System.currentTimeMillis());
jmsQueueManager.reportFinishedTask(task, "Destinations []");
schedulingPool.removeTask(task);
log.debug("TASK {} removed from database.", task.getId());
} catch (JMSException e) {
log.error("Failed to report finished task " + task.toString() + ": " + e.getMessage());
}
}
tasklist = schedulingPool.getErrorTasks();
log.debug("There are {} ERROR tasks", tasklist.size());
for (Task task : tasklist) {
if (task.getEndTime() == null) {
log.error("RECOVERY FROM INCONSISTENT STATE: ERROR task does not have end_time! Setting end_time to task.getDelay + 1.");
// getDelay is in minutes, therefore we multiply it with 60*1000
Date endTime = new Date(System.currentTimeMillis() - ((task.getDelay() + 1) * 60000));
task.setEndTime(endTime);
}
List<Destination> destinations = taskStatusManager.getTaskStatus(task).getSuccessfulDestinations();
List<Destination> failedDestinations = task.getDestinations();
failedDestinations.removeAll(destinations);
StringBuilder destinations_s = new StringBuilder("Destinations [");
if (!failedDestinations.isEmpty()) {
destinations_s.append(failedDestinations.remove(0).serializeToString());
for (Destination destination : failedDestinations) {
destinations_s.append(",");
destinations_s.append(destination.serializeToString());
}
}
destinations_s.append("]");
log.debug("TASK " + task.toString() + " finished in error, remaining destinations: " + destinations_s);
try {
jmsQueueManager.reportFinishedTask(task, destinations_s.toString());
schedulingPool.removeTask(task);
log.debug("TASK {} removed from database.", task.getId());
} catch (JMSException e) {
log.error("Failed to report finished task " + task.toString() + ": " + e.getMessage());
}
}
}
use of javax.jms.JMSException in project ACS by ACS-Community.
the class ACSJMSTopicPublisher method publish.
/* (non-Javadoc)
* @see javax.jms.TopicPublisher#publish(javax.jms.Topic, javax.jms.Message)
*/
public void publish(Topic topic, Message message) throws JMSException {
if (message == null) {
throw new NullPointerException("The message can't be null");
}
if (topic == null) {
throw new NullPointerException("The topic can't be null");
}
if (topic.getTopicName() == null || topic.getTopicName().isEmpty()) {
throw new IllegalArgumentException("Invalid topic name");
}
PublisherPoolItem item;
synchronized (publishersPool) {
item = publishersPool.get(topic.getTopicName());
}
if (item == null) {
try {
item = new PublisherPoolItem(topic.getTopicName(), containerServices);
} catch (Exception e) {
throw new JMSException("Error creating an AcsEventPublisher");
}
synchronized (publishersPool) {
publishersPool.put(topic.getTopicName(), item);
}
}
item.sendMessage(message);
}
use of javax.jms.JMSException in project ACS by ACS-Community.
the class DefaultSubscriberImpl method publishKeepAliveNotifications.
/**
* Method publishKeepAliveNotifications
*
*/
private void publishKeepAliveNotifications() {
cat.debug("publishKeepAliveNotifications()");
if (connection.isConnected()) {
SubscriptionHandle handle = null;
Collection local_subscribers = null;
synchronized (subscribers) {
local_subscribers = ((Map) subscribers.clone()).values();
}
try {
Iterator iterator = local_subscribers.iterator();
while (iterator.hasNext()) {
handle = (SubscriptionHandle) iterator.next();
if (!NotificationHelper.isNotification(handle.getSubscriptionTopic())) {
publishNotification(NotificationHelper.CONSUMER_ALIVE_NOTIFICATION, handle);
}
}
} catch (JMSException je) {
cat.error("unable to publish keep alive notifications", je);
}
}
}
use of javax.jms.JMSException in project ACS by ACS-Community.
the class DefaultSubscriberImpl method subscribe.
/**
* Method subscribe
*
*
* @param topic
* @param listener
* @param selector
*
* @return long the subscription handle identifier
*
* @throws JMSException
* @throws NamingException
*
*/
public long subscribe(String topic, SubscriptionListener listener, String selector) throws JMSException, NamingException {
cat.info("subscribe(" + topic + ", listener, " + selector + ")");
if (closed) {
throw (new JMSException("Subscriber closed."));
}
SubscriptionHandle handle = new SubscriptionHandle();
handle.setSubscriptionTopic(topic);
handle.setSubscriptionSelector(selector);
handle.setSubscriptionListener(listener);
StringBuffer local_selector = new StringBuffer();
if (NotificationHelper.isNotification(topic)) {
// this is a subscription to notifications, no further selection is required
local_selector.append(selector);
} else {
// subscription to a generic topic, adding subscriber specific selection
if (selector != null) {
local_selector.append(selector);
local_selector.append(" AND ");
}
local_selector.append("( (");
local_selector.append(NotificationHelper.SUBSCRIPTION_ID_PROPERTY);
local_selector.append(" IS NULL) OR (");
local_selector.append(NotificationHelper.SUBSCRIPTION_ID_PROPERTY);
local_selector.append(" = '");
local_selector.append(subscriberId);
local_selector.append("@");
local_selector.append(handle.getSubscriptionToken());
local_selector.append("') )");
}
TopicSession session = null;
TopicSubscriber subscriber = null;
Topic the_topic = createTopic(topic);
try {
session = connection.createTopicSession();
subscriber = session.createSubscriber(the_topic, local_selector.toString(), false);
} catch (JMSSecurityException jse) {
cat.error("JMSSecurityException caught");
throw (new NamingException(jse.getMessage()));
} catch (JMSException je) {
cat.error("JMSException caught");
throw (new NamingException(je.getMessage()));
} catch (ConnectionException ce) {
cat.error("ConnectionException caught");
throw (new JMSException(ce.getMessage()));
} catch (Exception e) {
cat.error("Generic exception caught", e);
}
subscriber.setMessageListener(listener);
handle.setSubscriber(subscriber);
handle.setSession(session);
synchronized (subscribers) {
subscribers.put(new Long(handle.getSubscriptionToken()), handle);
}
if (!NotificationHelper.isNotification(topic)) {
publishNotification(NotificationHelper.CONSUMER_OPEN_NOTIFICATION, handle);
}
return handle.getSubscriptionToken();
}
Aggregations