List of usage examples for javax.jms Message propertyExists
boolean propertyExists(String name) throws JMSException;
From source file:org.hawkular.apm.server.jms.RetryCapableMDB.java
@Override public void onMessage(Message message) { if (log.isLoggable(Level.FINEST)) { log.finest("Message received=" + message); }/*from www . jav a 2 s. co m*/ try { String tenantId = message.getStringProperty("tenant"); int retryCount; if (message.propertyExists("retryCount")) { retryCount = message.getIntProperty("retryCount"); } else { retryCount = maxRetryCount; } String data = ((TextMessage) message).getText(); List<S> items = mapper.readValue(data, getTypeReference()); process(tenantId, items, retryCount); } catch (Exception e) { if (processor.isReportRetryExpirationAsWarning()) { serverMsgLogger.warnMaxRetryReached(e); } else if (log.isLoggable(Level.FINEST)) { log.log(Level.FINEST, "Maximum retry reached. Last exception to occur ....", e); } } }
From source file:com.kinglcc.spring.jms.core.converter.Jackson2JmsMessageConverter.java
protected JavaType getJavaTypeForMessage(Message message) throws JMSException { if (null == this.typeIdPropertyName || !message.propertyExists(this.typeIdPropertyName)) { return null; }/*from www. j a v a 2s .com*/ String typeId = message.getStringProperty(this.typeIdPropertyName); if (typeId == null) { LOGGER.debug("Could not find type id property [{}]", typeIdPropertyName); return null; } try { Class<?> typeClass = ClassUtils.forName(typeId, this.beanClassLoader); return this.objectMapper.getTypeFactory().constructType(typeClass); } catch (Throwable ex) { throw new MessageConversionException("Failed to resolve type id [" + typeId + "]", ex); } }
From source file:it.geosolutions.geoserver.jms.client.JMSQueueListener.java
@Override public void onMessage(Message message, Session session) throws JMSException { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Incoming message event for session: " + session.toString()); }/*w w w . j a va 2 s . c o m*/ // CHECKING LISTENER STATUS if (!isEnabled()) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Incoming message is swallowed since this component is disabled"); } return; } // FILTERING INCOMING MESSAGE if (!message.propertyExists(JMSConfiguration.INSTANCE_NAME_KEY)) { throw new JMSException("Unable to handle incoming message, property \'" + JMSConfiguration.INSTANCE_NAME_KEY + "\' not set."); } // FILTERING INCOMING MESSAGE if (!message.propertyExists(JMSConfiguration.GROUP_KEY)) { throw new JMSException( "Unable to handle incoming message, property \'" + JMSConfiguration.GROUP_KEY + "\' not set."); } // check if message comes from a master with the same name of this slave if (message.getStringProperty(JMSConfiguration.INSTANCE_NAME_KEY) .equals(config.getConfiguration(JMSConfiguration.INSTANCE_NAME_KEY))) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Incoming message discarded: source is equal to destination"); } // if so discard the message return; } // check if message comes from a different group final String group = message.getStringProperty(JMSConfiguration.GROUP_KEY); final String localGroup = config.getConfiguration(JMSConfiguration.GROUP_KEY); if (!group.equals(localGroup)) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Incoming message discarded: incoming group-->" + group + " is different from the local one-->" + localGroup); } // if so discard the message return; } // check the property which define the SPI used (to serialize on the // server side). if (!message.propertyExists(JMSEventHandlerSPI.getKeyName())) throw new JMSException("Unable to handle incoming message, property \'" + JMSEventHandlerSPI.getKeyName() + "\' not set."); // END -> FILTERING INCOMING MESSAGE // get the name of the SPI used to serialize the message final String generatorClass = message.getStringProperty(JMSEventHandlerSPI.getKeyName()); if (generatorClass == null || generatorClass.isEmpty()) { throw new IllegalArgumentException("Unable to handle a message without a generator class name"); } if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine( "Incoming message was serialized using an handler generated by: \'" + generatorClass + "\'"); } // USING INCOMING MESSAGE if (message instanceof ObjectMessage) { final ObjectMessage objMessage = (ObjectMessage) (message); final Serializable obj = objMessage.getObject(); try { // lookup the SPI handler, search is performed using the // name final JMSEventHandler<Serializable, Object> handler = jmsManager .getHandlerByClassName(generatorClass); if (handler == null) { throw new JMSException("Unable to find SPI named \'" + generatorClass + "\', be shure to load that SPI into your context."); } final Enumeration<String> keys = message.getPropertyNames(); final Properties options = new Properties(); while (keys.hasMoreElements()) { String key = keys.nextElement(); options.put(key, message.getObjectProperty(key)); } handler.setProperties(options); // try to synchronize object locally if (!handler.synchronize(handler.deserialize(obj))) { throw new JMSException("Unable to synchronize message locally.\n SPI: " + generatorClass); } } catch (Exception e) { final JMSException jmsE = new JMSException(e.getLocalizedMessage()); jmsE.initCause(e); throw jmsE; } } else throw new JMSException("Unrecognized message type for catalog incoming event"); }
From source file:org.openanzo.client.RealtimeUpdateManager.java
protected void handleUpdateMessage(Message message) throws AnzoException { try {//from w ww .ja v a 2 s . c om if (!message.propertyExists(SerializationConstants.method)) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_MISSING_MESSAGE_PARAMETER); } if (!message.propertyExists(SerializationConstants.subject)) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_MISSING_MESSAGE_PARAMETER); } if (!message.propertyExists(SerializationConstants.predicate)) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_MISSING_MESSAGE_PARAMETER); } if (!message.propertyExists(SerializationConstants.namedGraphUri)) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_MISSING_MESSAGE_PARAMETER); } if (!message.propertyExists(SerializationConstants.object)) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_MISSING_MESSAGE_PARAMETER); } boolean method = message.getBooleanProperty(SerializationConstants.method); // Extract statement info from message. String predicateUri = message.getStringProperty(SerializationConstants.predicate); String namedGraph = message.getStringProperty(SerializationConstants.namedGraphUri); // Construct statement. Value object = CommonSerializationUtils.getObjectFromMessage(message); if (object == null) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_MISSING_MESSAGE_PARAMETER); } Resource subject = CommonSerializationUtils.getSubjectFromMessage(message); if (subject == null) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_MISSING_MESSAGE_PARAMETER); } URI predicate = Constants.valueFactory.createURI(predicateUri); URI namedGraphUri = Constants.valueFactory.createURI(namedGraph); URI graphURI = namedGraphUri; Statement stmt = Constants.valueFactory.createStatement(subject, predicate, object, graphURI); notifyTrackers(method, stmt); } catch (JMSException jmsex) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_MESSAGE_PARSING, jmsex); } }
From source file:org.openanzo.client.RealtimeUpdateManager.java
protected void handleDatasetUpdateMessage(Message message) throws AnzoException { try {/* w w w. ja v a 2s .c o m*/ if (!message.propertyExists(SerializationConstants.datasetUri)) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_MISSING_MESSAGE_PARAMETER); } if (!message.propertyExists(SerializationConstants.namedGraphUri)) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_MISSING_MESSAGE_PARAMETER); } String namedGraph = message.getStringProperty(SerializationConstants.namedGraphUri); String datasetUris = message.getStringProperty(SerializationConstants.datasetUri); Collection<URI> uris = new ArrayList<URI>(); StringTokenizer st = new StringTokenizer(datasetUris, ","); while (st.hasMoreTokens()) { uris.add(Constants.valueFactory.createURI(st.nextToken())); } notifyTrackers(Constants.valueFactory.createURI(namedGraph), uris); } catch (JMSException jmsex) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_MESSAGE_PARSING, jmsex); } }
From source file:org.openanzo.client.RealtimeUpdateManager.java
protected void handleTransactionMessage(Message message) throws AnzoException { // Extract method and transactionId. String transactionContextString = null; try {/* w w w .j a v a 2 s . com*/ transactionContextString = message.propertyExists(SerializationConstants.transactionContext) ? message.getStringProperty(SerializationConstants.transactionContext) : null; } catch (JMSException e) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_MESSAGE_PARSING, e); } String updatedNamedGraphs = null; try { updatedNamedGraphs = message.propertyExists(SerializationConstants.namedGraphUpdates) ? message.getStringProperty(SerializationConstants.namedGraphUpdates) : null; } catch (JMSException e) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_MESSAGE_PARSING, e); } long timestamp = -1; try { timestamp = Long.valueOf(message.getLongProperty(SerializationConstants.transactionTimestamp)); } catch (JMSException e) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_MESSAGE_PARSING, e); } String transactionUri = null; try { transactionUri = message.propertyExists(SerializationConstants.transactionURI) ? message.getStringProperty(SerializationConstants.transactionURI) : null; } catch (JMSException e) { throw new AnzoException(ExceptionConstants.COMBUS.JMS_MESSAGE_PARSING, e); } URI transactionURI = (transactionUri != null) ? MemURI.create(transactionUri) : null; transactionLock.writeLock().lock(); try { Collection<Statement> context = null; if (transactionContextString != null) { context = ReadWriteUtils.readStatements(transactionContextString, RDFFormat.JSON); } Map<URI, Long> updatedGraphs = null; if (updatedNamedGraphs != null) { updatedGraphs = CommonSerializationUtils.readNamedGraphRevisions(updatedNamedGraphs); } UpdateTransaction transaction = new UpdateTransaction(transactionURI, timestamp, context, updatedGraphs); notifyTransactionListeners(transaction); } finally { transactionLock.writeLock().unlock(); } }
From source file:org.openanzo.combus.endpoint.BaseServiceListener.java
public void onMessage(Message message) { if (started) { try {//from w w w.j a v a2 s .c o m if (threadPool != null) { if (message.propertyExists(SerializationConstants.bypassPool) && message.getBooleanProperty(SerializationConstants.bypassPool)) { processMessage(message); } else { if (message.getJMSPriority() < 4) { while (threadPool.getNumActive() >= threadPool.getMaxActive() || (highActive > (threadPool.getNumActive() / 2) && lowActive > 1)) { synchronized (threadPool) { threadPool.wait(); } } ProcessThread pt = (ProcessThread) threadPool.borrowObject(); pt.setRequest(message, false); } else { ProcessThread pt = (ProcessThread) threadPool.borrowObject(); pt.setRequest(message, true); } } } else { processMessage(message); } } catch (Throwable jmex) { log.error(LogUtils.COMBUS_MARKER, "Error in BaseService Listener's process thread loop", jmex); } } }
From source file:org.openanzo.combus.endpoint.BaseServiceListener.java
private void processMessage(Message request) { try {/*from www . j a va 2 s . c om*/ IOperationContext context = null; TextMessage response = null; String operation = request.getStringProperty(SerializationConstants.operation); try { Destination replyTo = null; try { if (mp == null) { mp = session.createProducer(null); mp.setDeliveryMode(DeliveryMode.NON_PERSISTENT); } replyTo = request.getJMSReplyTo(); String resultFormat = request.getStringProperty(SerializationConstants.resultFormat); context = new BaseOperationContext(operation, request.getJMSCorrelationID(), null); if (request.propertyExists(SerializationConstants.userDescription)) { context.setAttribute(SerializationConstants.userDescription, request.getStringProperty(SerializationConstants.userDescription)); } if (request.propertyExists(OPTIONS.SKIPCACHE)) { context.setAttribute(OPTIONS.SKIPCACHE, request.getBooleanProperty(OPTIONS.SKIPCACHE)); } if (request.propertyExists(OPTIONS.INCLUDEMETADATAGRAPHS)) { context.setAttribute(OPTIONS.INCLUDEMETADATAGRAPHS, request.getBooleanProperty(OPTIONS.INCLUDEMETADATAGRAPHS)); } AnzoPrincipal callerPrincipal = getContextPrincipal(context, request); context.setOperationPrincipal(callerPrincipal); if (log.isTraceEnabled()) { log.trace(LogUtils.COMBUS_MARKER, MessageUtils.prettyPrint(request, "Message Recieved from [" + callerPrincipal.getName() + "]" + ((replyTo != null) ? (" with replyto [" + replyTo + "]") : ""))); } else if (log.isDebugEnabled()) { log.debug(LogUtils.COMBUS_MARKER, "Message Recieved from [" + callerPrincipal.getName() + "]" + ((replyTo != null) ? (" with replyto [" + replyTo + "]") : "")); } context.setMDC(); Boolean analyzeRequest = request .getBooleanProperty(RequestAnalysis.CONTEXT_PROP_REQUEST_ENABLED); if (analyzeRequest || recorder != null) { RequestAnalysis.setCurrentContext(context.getAttributes()); RequestAnalysis.setRequestAnalysisEnabled(true); } if (recorder != null) { recorder.recordRequest((TextMessage) request, request.getStringProperty("JMSXUserID"), request.getStringProperty(SerializationConstants.runAsUser)); } long start = 0, end = 0; if (RequestAnalysis.isAnalysisEnabled(context.getAttributes())) { start = System.currentTimeMillis(); } response = handleMessage(context, replyTo, resultFormat, operation, (TextMessage) request, mp); if (RequestAnalysis.isAnalysisEnabled(context.getAttributes())) { end = System.currentTimeMillis(); RequestAnalysis.addAnalysisProperty(RequestAnalysis.ANS_PROP_OPERATION_TIME, String.valueOf(end - start)); } if (response != null) { response.setIntProperty(SerializationConstants.protocolVersion, Constants.VERSION); if (operation != null) { response.setStringProperty(SerializationConstants.operation, operation); } Integer totalSolutions = context.getAttribute(SerializationConstants.totalSolutions, Integer.class); if (totalSolutions != null) { response.setIntProperty(SerializationConstants.totalSolutions, totalSolutions.intValue()); } if (analyzeRequest) { for (String name : RequestAnalysis.getAnalysisPropertyNames()) { response.setStringProperty(name, context.getAttribute(name).toString()); } } } if (response != null && replyTo != null) { response.setJMSCorrelationID(request.getJMSCorrelationID()); if (log.isTraceEnabled()) { log.trace(LogUtils.COMBUS_MARKER, MessageUtils.prettyPrint(response, "Sending Response to [" + replyTo + "]")); } else if (log.isDebugEnabled()) { log.debug(LogUtils.COMBUS_MARKER, "Sending Response to [" + replyTo + "]"); } mp.send(replyTo, response); } } catch (JMSException jmex) { response = sendJMSErrorMessage(replyTo, request, jmex, ExceptionConstants.COMBUS.JMS_SERVICE_EXCEPTION, jmex.toString()); } catch (AnzoException jmex) { response = sendJMSErrorMessage(replyTo, request, jmex, jmex.getErrorCode(), jmex.getArgs()); } catch (AnzoRuntimeException jmex) { response = sendJMSErrorMessage(replyTo, request, jmex, jmex.getErrorCode(), jmex.getArgs()); } catch (RuntimeException jmex) { response = sendJMSErrorMessage(replyTo, request, jmex, ExceptionConstants.COMBUS.JMS_SERVICE_EXCEPTION, jmex.toString()); } catch (Throwable jmex) { response = sendJMSErrorMessage(replyTo, request, jmex, ExceptionConstants.COMBUS.JMS_SERVICE_EXCEPTION, jmex.toString()); } if (recorder != null) { if (response != null) { recorder.recordResponse(response); } else { recorder.recordResponse(request.getJMSCorrelationID(), operation); } } } finally { if (context != null) { context.clearMDC(); } } } catch (JMSException jmsex) { if (jmsex.getCause() instanceof InterruptedException) { log.debug(LogUtils.COMBUS_MARKER, "Thread interrupted in order to stop.", jmsex); } else { log.error(LogUtils.COMBUS_MARKER, "Error in BaseService Listener's process thread loop", jmsex); } } catch (Throwable jmex) { log.error(LogUtils.COMBUS_MARKER, "Error in BaseService Listener's process thread loop", jmex); } }