List of usage examples for javax.jms ObjectMessage getObject
Serializable getObject() throws JMSException;
From source file:org.oxymores.chronix.engine.Runner.java
@Override public void onMessage(Message msg) { if (msg instanceof ObjectMessage) { ObjectMessage omsg = (ObjectMessage) msg; try {// ww w.j a v a 2 s . c o m Object o = omsg.getObject(); if (o instanceof PipelineJob) { PipelineJob pj = (PipelineJob) o; log.debug(String.format("Job execution %s request was received", pj.getId())); recvPJ(pj); jmsCommit(); return; } else if (o instanceof RunResult) { RunResult rr = (RunResult) o; recvRR(rr); jmsCommit(); return; } else { log.warn( "An object was received by the Runner that was not of a valid type. It will be ignored."); jmsCommit(); return; } } catch (JMSException e) { log.error( "An error occurred during job reception. Message will stay in queue and will be analysed later", e); jmsRollback(); return; } } else if (msg instanceof TextMessage) { TextMessage tmsg = (TextMessage) msg; try { recvTextMessage(tmsg); jmsCommit(); } catch (JMSException e) { log.error("An error occurred during parameter resolution", e); jmsRollback(); return; } } else if (msg instanceof BytesMessage) { // log file reception BytesMessage bmsg = (BytesMessage) msg; String fn = "dump.txt"; try { fn = bmsg.getStringProperty("FileName"); } catch (JMSException e) { log.error( "An log file was sent without a FileName property. It will be lost. Will not impact the scheduler itself.", e); jmsCommit(); } try { int l = (int) bmsg.getBodyLength(); byte[] r = new byte[l]; bmsg.readBytes(r); IOUtils.write(r, new FileOutputStream(new File(FilenameUtils.concat(this.logDbPath, fn)))); jmsCommit(); } catch (Exception e) { log.error( "An error has occured while receiving a log file. It will be lost. Will not impact the scheduler itself.", e); jmsCommit(); } } }
From source file:org.oxymores.chronix.engine.RunnerAgent.java
@Override public void onMessage(Message msg) { log.info("Run request received"); ObjectMessage omsg = (ObjectMessage) msg; RunDescription rd;//w w w. jav a 2s . c om RunResult res = null; try { Object o = omsg.getObject(); if (!(o instanceof RunDescription)) { log.warn("An object was received on the runner queue but was not a RunDescription! Ignored."); jmsCommit(); return; } rd = (RunDescription) o; } catch (JMSException e) { log.error( "An error occurred during RunDescription reception. Message will stay in queue and will be analysed later", e); jmsRollback(); return; } if (!rd.getHelperExecRequest()) { log.info(String.format("Running command %s", rd.getCommand())); } else { log.debug(String.format("Running helper internal command %s", rd.getCommand())); } // Log file (only if true run) String logFilePath = null; String logFileName = null; Date start = new Date(); if (!rd.getHelperExecRequest()) { SimpleDateFormat myFormatDir = new SimpleDateFormat("yyyyMMdd"); SimpleDateFormat myFormatFile = new SimpleDateFormat("yyyyMMddhhmmssSSS"); String dd = myFormatDir.format(start); String logFileDateDir = FilenameUtils.concat(this.logDbPath, dd); if (!(new File(logFileDateDir)).exists() && !(new File(logFileDateDir)).mkdir()) { log.fatal("Could not create log directory, failing engine"); this.broker.stop(); jmsRollback(); return; } logFileName = String.format("%s_%s_%s_%s.log", myFormatFile.format(start), rd.getPlaceName().replace(" ", "-"), rd.getActiveSourceName().replace(" ", "-"), rd.getId1()); logFilePath = FilenameUtils.concat(logFileDateDir, logFileName); } // Run the command according to its method if (rd.getMethod().equals(Constants.JD_METHOD_SHELL)) { res = RunnerShell.run(rd, logFilePath, !rd.getHelperExecRequest(), rd.getShouldSendLogFile()); } else { res = new RunResult(); res.returnCode = -1; res.logStart = String.format("An unimplemented exec method (%s) was called!", rd.getMethod()); log.error(String.format("An unimplemented exec method (%s) was called! Job will be failed.", rd.getMethod())); } res.start = start; res.end = new Date(); res.logFileName = logFileName; res.logPath = logFilePath; // Copy the engine ids - that way it will be able to identify the launch // Part of the ids are in the JMS correlation id too res.id1 = rd.getId1(); res.id2 = rd.getId2(); res.outOfPlan = rd.getOutOfPlan(); // Send the result! Message response; if (!rd.getHelperExecRequest()) { InputStream is = null; try { response = jmsSession.createObjectMessage(res); response.setJMSCorrelationID(msg.getJMSCorrelationID()); jmsProducer.send(msg.getJMSReplyTo(), response); if (res.logSizeBytes <= 500000) { response = jmsSession.createBytesMessage(); byte[] bytes = new byte[(int) res.logSizeBytes]; is = new FileInputStream(res.logPath); is.read(bytes); IOUtils.closeQuietly(is); ((BytesMessage) response).writeBytes(bytes); response.setJMSCorrelationID(msg.getJMSCorrelationID()); response.setStringProperty("FileName", logFileName); jmsProducer.send(msg.getJMSReplyTo(), response); } else { log.warn( "A log file was too big and will not be sent. Only the full log file will be missing - the launch will still appear in the console."); } } catch (Exception e1) { log.error( "The runner was not able to send the result of an execution to the engine. This may corrupt plan execution!", e1); IOUtils.closeQuietly(is); } } else { try { response = jmsSession.createTextMessage(res.logStart); response.setJMSCorrelationID(msg.getJMSCorrelationID()); jmsProducer.send(msg.getJMSReplyTo(), response); } catch (JMSException e1) { log.error( "The runner was not able to send the result of a parameter resolution to the engine. This may corrupt plan execution!", e1); } } jmsCommit(); }
From source file:org.rhq.enterprise.server.alert.engine.jms.AlertConditionConsumerBean.java
public void onMessage(Message message) { AbstractAlertConditionMessage conditionMessage = null; try {//w w w .j a v a 2 s . c o m ObjectMessage objectMessage = (ObjectMessage) message; conditionMessage = (AbstractAlertConditionMessage) objectMessage.getObject(); } catch (Throwable t) { log.error("Error getting content of jms message", t); return; } Integer definitionId = null; try { if (log.isDebugEnabled()) log.debug("Received message: " + conditionMessage); int alertConditionId = conditionMessage.getAlertConditionId(); InventoryStatus status = alertConditionManager.getResourceStatusByConditionId(alertConditionId); if (status != InventoryStatus.COMMITTED) { log.debug("Resource for AlertCondition[id=" + alertConditionId + "] is no longer COMMITTED, status was '" + status + "'; this message will be discarded"); return; } definitionId = alertConditionManager.getAlertDefinitionByConditionIdInNewTransaction(alertConditionId); if (definitionId == null) { log.info("AlertCondition[id=" + alertConditionId + "] has been removed after it was triggered; this message will be discarded"); return; } AlertSerializer.getSingleton().lock(definitionId); /* * must be executed in a new, nested transaction so that by it * completes and unlocks, the next thread will see all of its results */ cachedConditionManager.processCachedConditionMessage(conditionMessage, definitionId); } catch (Throwable t) { log.error("Error handling " + conditionMessage + " - " + t.toString()); } finally { try { if (definitionId != null) { AlertSerializer.getSingleton().unlock(definitionId); } } catch (Throwable t) { } } }
From source file:org.rhq.enterprise.server.drift.DriftChangesetBean.java
@Override public void onMessage(Message message) { try {/*from www . j a v a 2 s . co m*/ if (log.isDebugEnabled()) { log.debug("Received drift change set message"); } ObjectMessage msg = (ObjectMessage) message; DriftUploadRequest request = (DriftUploadRequest) msg.getObject(); File tempFile = null; OutputStream os = null; InputStream is = null; try { tempFile = File.createTempFile("drift-changeset", ".zip"); os = new BufferedOutputStream(new FileOutputStream(tempFile)); is = DriftUtil.remoteStream(request.getDataStream()); StreamUtil.copy(is, os); is = null; os = null; if (log.isDebugEnabled()) { log.debug("Copied [" + request.getDataSize() + "] bytes from agent into [" + tempFile.getPath() + "]"); } driftManager.saveChangeSet(subjectManager.getOverlord(), request.getResourceId(), tempFile); } catch (IOException e) { log.error(e); } finally { if (null != tempFile) { tempFile.delete(); } DriftUtil.safeClose(os); DriftUtil.safeClose(is); } } catch (Throwable t) { // catch Throwable here, don't let anything escape as bad things can happen wrt XA/2PhaseCommit log.error("Error processing drift changeset message", t); } }
From source file:org.rhq.enterprise.server.drift.DriftFileBean.java
@Override public void onMessage(Message message) { try {/*from ww w . j a v a 2 s . c o m*/ if (log.isDebugEnabled()) { log.debug("Received drift file message"); } ObjectMessage msg = (ObjectMessage) message; DriftUploadRequest request = (DriftUploadRequest) msg.getObject(); File tempFile = null; OutputStream os = null; InputStream is = null; try { tempFile = File.createTempFile("drift-file", ".zip"); os = new BufferedOutputStream(new FileOutputStream(tempFile)); is = DriftUtil.remoteStream(request.getDataStream()); StreamUtil.copy(is, os); is = null; os = null; os = null; if (log.isDebugEnabled()) { log.debug("Copied [" + request.getDataSize() + "] bytes from agent into [" + tempFile.getPath() + "]"); } driftManager.saveChangeSetContent(subjectManager.getOverlord(), request.getResourceId(), request.getDriftDefName(), request.getToken(), tempFile); } catch (IOException e) { log.error(e); } finally { if (null != tempFile) { tempFile.delete(); } DriftUtil.safeClose(os); DriftUtil.safeClose(is); } } catch (Throwable t) { // catch Throwable here, don't let anything escape as bad things can happen wrt XA/2PhaseCommit log.error("Error processing drift file message", t); } }
From source file:org.sakaiproject.kernel.messaging.email.EmailMessageListener.java
/** * {@inheritDoc}/*ww w . j a va2s. com*/ * * @see javax.jms.MessageListener#onMessage(javax.jms.Message) */ public void onMessage(javax.jms.Message jmsMsg) { if (jmsMsg instanceof ObjectMessage) { ObjectMessage objMsg = (ObjectMessage) jmsMsg; try { // get the email message and break out the parts Message email = (Message) objMsg.getObject(); handleMessage(email); } catch (JMSException e) { // TODO log for now. We need to return a message to the sender that // something died while processing this message LOG.error(e.getMessage(), e); } catch (AddressException e) { LOG.error(e.getMessage(), e); } catch (UnsupportedEncodingException e) { LOG.error(e.getMessage(), e); } catch (SendFailedException e) { LOG.error(e.getMessage(), e); } catch (MessagingException e) { LOG.error(e.getMessage(), e); } catch (IOException e) { LOG.error(e.getMessage(), e); } } }
From source file:org.socraticgrid.taskmanager.TaskHandler.java
public void onMessage(Message message) { TaskMessage taskMessage = null;// w w w . j a v a2 s .co m try { log.debug("Received message id: " + message.getJMSMessageID()); if (message instanceof ObjectMessage) { ObjectMessage oMsg = (ObjectMessage) message; Object object = oMsg.getObject(); if (object instanceof TaskMessage) { taskMessage = (TaskMessage) object; } } } catch (JMSException e) { log.error("Error processing message for task bean.", e); //Don't rollback else message gets stuck in queue //mdc.setRollbackOnly(); } catch (Throwable te) { log.error("Error processing message for task handler.", te); } //Check if TaskMessage was found if (taskMessage == null) { log.error("Expected TaskMessage(ObjectMessage) not found, ignoring message."); return; } try { //Pull out task from database TaskService taskService = new TaskService(); TaskType task = taskService.getTask(new Long(taskMessage.getTaskID())); if (task == null) { throw new Exception("Task id(" + taskMessage.getTaskID() + ") was not found."); } if ((task.getSpecifications() == null) || (task.getSpecifications().isEmpty())) { throw new Exception("Task id(" + task.getTaskTypeId() + ") has no specifications."); } //Find tasking service String taskingServiceId = null; for (Specification spec : task.getSpecifications()) { if (SpecConstants.NAME_SERVICE_REF.equals(spec.getName())) { taskingServiceId = spec.getValue(); break; } } if (taskingServiceId == null) { throw new Exception("Task id(" + task.getTaskTypeId() + ") had no specification(" + SpecConstants.NAME_SERVICE_REF + ")."); } TaskServiceRef serviceRef = taskService.getServiceRef(new Long(taskingServiceId)); if (serviceRef == null) { throw new Exception("Task id(" + task.getTaskTypeId() + ") tasking service id(" + taskingServiceId + ") did not exist."); } //Handle each method appropriately // if (ServiceConstants.TYPE_JMS_QUEUE.equals(serviceRef.getType())) { // notifyQueue(message.getJMSMessageID(), serviceRef.getLocation(), taskMessage, task); // } // else if (ServiceConstants.TYPE_SWIFT_SMS.equals(serviceRef.getType())) { new SwiftSMSHandler().handleMessage(message.getJMSMessageID(), serviceRef, taskMessage, task); } else if (ServiceConstants.TYPE_ZIMBRA_VTODO.equals(serviceRef.getType())) { new VTodoHandler().handleMessage(message.getJMSMessageID(), serviceRef, taskMessage, task); } else if (ServiceConstants.TYPE_ZIMBRA_VEVENT.equals(serviceRef.getType())) { new VEventHandler().handleMessage(message.getJMSMessageID(), serviceRef, taskMessage, task); } else if (ServiceConstants.TYPE_SMTP.equals(serviceRef.getType())) { new MailHandler().handleMessage(message.getJMSMessageID(), serviceRef, taskMessage, task); } else if (ServiceConstants.TYPE_DISEASE_REGISTRY.equals(serviceRef.getType())) { new DiseaseRegistryHandler().handleMessage(message.getJMSMessageID(), serviceRef, taskMessage, task); } else if (ServiceConstants.TYPE_LAB_ORDER.equals(serviceRef.getType())) { new LabOrderHandler().handleMessage(message.getJMSMessageID(), serviceRef, taskMessage, task); } else if (ServiceConstants.TYPE_SLOT_REQUEST.equals(serviceRef.getType())) { new SlotRequestHandler().handleMessage(message.getJMSMessageID(), serviceRef, taskMessage, task); } else { throw new UnsupportedOperationException("Unsupported task service method: " + serviceRef.getType()); } } catch (Throwable t) { log.error("Error processing message for task handler.", t); } }
From source file:ru.runa.wfe.service.impl.EmailSenderBean.java
@Override public void onMessage(Message jmsMessage) { ObjectMessage message = (ObjectMessage) jmsMessage; EmailConfig config;/*from ww w. ja va2s. c om*/ try { config = (EmailConfig) message.getObject(); } catch (JMSException e) { throw Throwables.propagate(e); } try { EmailUtils.sendMessage(config); return; } catch (IOException e) { log.warn(config); log.error("unable to send email: " + e); } catch (MessagingException e) { log.warn(config); log.error("unable to send email: " + e); } catch (Exception e) { log.warn(config); log.error("unable to send email", e); if (!config.isThrowErrorOnFailure()) { return; } } if (SystemProperties.isEmailGuaranteedDeliveryEnabled()) { throw new MessagePostponedException("email guaranteed delivery requested"); } }
From source file:ru.runa.wfe.service.impl.ReceiveMessageBean.java
private void handleMessage(final ReceiveMessageData data, final ObjectMessage message) { try {//from w ww . j a v a2s . c om new TransactionalExecutor(context.getUserTransaction()) { @Override protected void doExecuteInTransaction() throws Exception { log.info("Handling " + message + " for " + data); Token token = tokenDao.getNotNull(data.tokenId); if (!Objects.equal(token.getNodeId(), data.node.getNodeId())) { throw new InternalApplicationException(token + " not in " + data.node.getNodeId()); } ProcessDefinition processDefinition = processDefinitionLoader .getDefinition(token.getProcess().getDeployment().getId()); ExecutionContext executionContext = new ExecutionContext(processDefinition, token); executionContext.activateTokenIfHasPreviousError(); executionContext.addLog(new ReceiveMessageLog(data.node, Utils.toString(message, true))); Map<String, Object> map = (Map<String, Object>) message.getObject(); for (VariableMapping variableMapping : data.node.getVariableMappings()) { if (!variableMapping.isPropertySelector()) { if (map.containsKey(variableMapping.getMappedName())) { Object value = map.get(variableMapping.getMappedName()); executionContext.setVariableValue(variableMapping.getName(), value); } else { log.warn("message does not contain value for '" + variableMapping.getMappedName() + "'"); } } } data.node.leave(executionContext); } }.executeInTransaction(true); } catch (final Throwable th) { Utils.failProcessExecution(context.getUserTransaction(), data.tokenId, th); Throwables.propagate(th); } }
From source file:ubic.gemma.core.job.executor.worker.TaskControlListener.java
@Override public void onMessage(Message message) { ObjectMessage objectMessage = (ObjectMessage) message; try {/*from w ww. ja v a 2s.com*/ TaskControl taskControl = (TaskControl) objectMessage.getObject(); String taskId = taskControl.getTaskId(); assert taskId != null; SubmittedTaskRemote submittedTask = remoteTaskRunningService.getSubmittedTask(taskControl.getTaskId()); if (submittedTask == null) { log.warn("Got control request for taskId:" + taskId + ", but no submitted task found."); return; } switch (taskControl.getRequest()) { case CANCEL: log.info("Received CANCEL control message for task: " + taskControl.getTaskId()); submittedTask.requestCancellation(); break; case ADD_EMAIL_NOTIFICATION: log.info("Received ADD_EMAIL_NOTIFICATION control message for task: " + taskControl.getTaskId()); submittedTask.addEmailAlertNotificationAfterCompletion(); break; default: log.info("Unknown request: " + taskControl.getRequest() + ", no action taken"); break; } } catch (JMSException e) { log.warn("Got JMSException: " + e.getMessage()); } }