List of usage examples for javax.jms JMSException printStackTrace
public void printStackTrace()
From source file:drepcap.frontend.jms.JmsAdapter.java
public void startReceiveData() throws JMSException { dataTopic = session.createTopic(componentName + ".data"); dataConsumer = session.createConsumer(dataTopic); dataConsumer.setMessageListener(new MessageListener() { @Override/*from ww w . j av a 2s. c o m*/ public void onMessage(Message msg) { for (ByteArrayReceiver baDataReceiver : byteArrayDataReceivers) { if (baDataReceiver != null && msg instanceof BytesMessage) { BytesMessage bMsg = (BytesMessage) msg; try { byte[] data = new byte[(int) bMsg.getBodyLength()]; bMsg.readBytes(data); baDataReceiver.process(data); } catch (JMSException e) { e.printStackTrace(); } } } for (ObjectReceiver objReceiver : objectReceivers) { if (objReceiver != null && msg instanceof ObjectMessage) { ObjectMessage objMsg = (ObjectMessage) msg; try { objReceiver.process(objMsg.getObject()); } catch (JMSException e) { e.printStackTrace(); } } } } }); }
From source file:eu.learnpad.simulator.mon.manager.GlimpseManager.java
public void onMessage(Message messagePayload) { TextMessage msg = null;//from w w w . j a va2 s. c om try { msg = (TextMessage) messagePayload; DebugMessages.line(); DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "receive " + msg.getText()); DebugMessages.line(); String xmlMessagePayload = msg.getText(); String sender = msg.getStringProperty("SENDER"); ComplexEventRuleActionListDocument ruleDoc; // check if the paylod of the message is a bpmn to be used for path // extraction and rules generation // or if the xml is already a rule to inject into the engine if (xmlMessagePayload.contains("http://www.omg.org/spec/BPMN/20100524/MODEL")) { DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "The message sent seems to contain a BPMN - Forwarding it to the LearnPAd Assessment Manager"); @SuppressWarnings("unchecked") List<String> learnersIDs = (List<String>) msg.getObjectProperty("USERSINVOLVEDID"); String bpmnID = msg.getObjectProperty("BPMNID").toString(); String sessionID = msg.getObjectProperty("SESSIONID").toString(); Vector<Learner> learnersInvolved = learnerAssessmentManager.getDBController() .getOrSetLearners(learnersIDs); DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Creating Session Score Buffer"); sessionScoreBuffer = new ScoreTemporaryStorage(learnersInvolved, sessionID); if (sessionScoreBuffer != null) DebugMessages.ok(); ruleDoc = learnerAssessmentManager.elaborateModel(xmlMessagePayload, learnersInvolved, sessionID, bpmnID); } else { ruleDoc = ComplexEventRuleActionListDocument.Factory.parse(xmlMessagePayload); } ComplexEventRuleActionType rules = ruleDoc.getComplexEventRuleActionList(); // the topic where the listener will give analysis results answerTopic = "answerTopic" + "#" + this.getName() + "#" + System.nanoTime(); DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Create answerTopic"); connectionTopic = publishSession.createTopic(answerTopic); // tPub = publishSession.createPublisher(connectionTopic); DebugMessages.ok(); DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Setting up ComplexEventProcessor with new rule."); try { Object[] loadedKnowledgePackage = rulesManagerOne.loadRules(rules); //Object[] loadedKnowledgePackage = rulesManagerOne.vandaLoadRules(rules); // inserisco la coppia chiave valore dove la chiave il KnowledgePackage // caricato, generato da DroolsRulesManager con la loadRules // e il valore l'enabler che l'ha inviata // (il KnowledgePackage array dovrebbe avere sempre dimensione 1 // essendo creato ad ogni loadrules) for (int i = 0; i < loadedKnowledgePackage.length; i++) { KnowledgePackageImp singleKnowlPack = (KnowledgePackageImp) loadedKnowledgePackage[i]; Rule[] singleRuleContainer = new Rule[singleKnowlPack.getRules().size()]; singleRuleContainer = singleKnowlPack.getRules().toArray(singleRuleContainer); for (int j = 0; j < singleRuleContainer.length; j++) { requestMap.put(singleRuleContainer[j].getName(), new ConsumerProfile(sender, answerTopic)); } } DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "KnowledgeBase packages loaded: " + rulesManagerOne.getLoadedKnowledgePackageCardinality()); DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Communicate the answerTopic to the requester"); sendMessage(createMessage("AnswerTopic == " + answerTopic, sender)); DebugMessages.ok(); } catch (IncorrectRuleFormatException e) { sendMessage(createMessage("PROVIDED RULE CONTAINS ERRORS", sender)); } } catch (NullPointerException asd) { try { sendMessage(createMessage("PROVIDED RULE IS NULL, PLEASE PROVIDE A VALID RULE", msg.getStringProperty("SENDER"))); } catch (JMSException e) { e.printStackTrace(); } } catch (XmlException e) { try { sendMessage(createMessage("PROVIDED XML CONTAINS ERRORS", msg.getStringProperty("SENDER"))); } catch (JMSException e1) { e1.printStackTrace(); } } catch (JMSException ee) { ee.printStackTrace(); } DebugMessages.line(); }
From source file:HierarchicalChat.java
/** Create JMS client for publishing and subscribing to messages. */ private void chatter(String broker, String username, String password, String pubTopicname, String subTopicname) {// w w w . j a va 2 s.c o m // Create a connection. try { javax.jms.ConnectionFactory factory; factory = new ActiveMQConnectionFactory(username, password, broker); connect = factory.createConnection(username, password); pubSession = connect.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); subSession = connect.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); } catch (javax.jms.JMSException jmse) { System.err.println("error: Cannot connect to Broker - " + broker); jmse.printStackTrace(); System.exit(1); } // Create Publisher and Subscriber to 'chat' topics // Note that the publish and subscribe topics are different. try { javax.jms.Topic subscriberTopic = pubSession.createTopic(subTopicname); javax.jms.MessageConsumer subscriber = subSession.createConsumer(subscriberTopic, null, false); subscriber.setMessageListener(this); javax.jms.Topic publisherTopic = pubSession.createTopic(pubTopicname); publisher = pubSession.createProducer(publisherTopic); // Now that setup is complete, start the Connection connect.start(); } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); } try { // Read all standard input and send it as a message. java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); System.out.println("\nHierarchicalChat application:\n" + "============================\n" + "The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n" + "The application will publish messages to the " + DEFAULT_PUBLISHER_TOPIC + " topic." + ".\n" + "The application also subscribes to topics using the wildcard syntax " + DEFAULT_SUBSCRIBER_TOPIC + " so that it can receive all messages to " + DEFAULT_SUBSCRIBER_ROOT + " and its subtopics.\n\n" + "Type some text, and then press Enter to publish a TextMesssage from " + username + ".\n"); while (true) { String s = stdin.readLine(); if (s == null) exit(); else if (s.length() > 0) { javax.jms.TextMessage msg = pubSession.createTextMessage(); msg.setText(username + ": " + s); publisher.send(msg); } } } catch (java.io.IOException ioe) { ioe.printStackTrace(); } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); } }
From source file:SelectorChat.java
/** Create JMS client for publishing and subscribing to messages. */ private void chatter(String broker, String username, String password, String selection) { // Create a connection. try {/*from www . j a v a 2s . c om*/ javax.jms.ConnectionFactory factory; factory = new ActiveMQConnectionFactory(username, password, broker); connect = factory.createConnection(username, password); pubSession = connect.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); subSession = connect.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); } catch (javax.jms.JMSException jmse) { System.err.println("error: Cannot connect to Broker - " + broker); jmse.printStackTrace(); System.exit(1); } // Create Publisher and Subscriber to 'chat' topics try { javax.jms.Topic topic = pubSession.createTopic(APP_TOPIC); // NOTE: The subscriber's message selector will now be set: javax.jms.MessageConsumer subscriber = subSession.createConsumer(topic, PROPERTY_NAME + " = \'" + selection + "\'", false); subscriber.setMessageListener(this); publisher = pubSession.createProducer(topic); // Now that setup is complete, start the Connection connect.start(); } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); System.exit(1); } try { // Read all standard input and send it as a message. java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); System.out.println("\nSelectorChat application:\n" + "===========================\n" + "The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n" + "The application will publish messages with " + PROPERTY_NAME + " set to " + selection + " to the " + APP_TOPIC + " topic .\n" + "The application also subscribes to that topic, selecting only messages where " + PROPERTY_NAME + " is " + selection + ".\n" + "Type some text, and then press Enter to publish it as a TextMesssage from " + username + ".\n"); while (true) { String s = stdin.readLine(); if (s == null) exit(); else if (s.length() > 0) { javax.jms.TextMessage msg = pubSession.createTextMessage(); msg.setText(username + ": " + s); // NOTE: here we set a property on messages to be published: msg.setStringProperty(PROPERTY_NAME, selection); publisher.send(msg); } } } catch (java.io.IOException ioe) { ioe.printStackTrace(); } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); } }
From source file:TopicReplier.java
/** Create JMS client for publishing and subscribing to messages. */ private void start(String broker, String username, String password, String mode) { // Set the operation mode imode = (mode.equals("uppercase")) ? UPPERCASE : LOWERCASE; // Create a connection. try {/* www . jav a 2s. c o m*/ javax.jms.ConnectionFactory factory; factory = new ActiveMQConnectionFactory(username, password, broker); connect = factory.createConnection(username, password); session = connect.createSession(true, javax.jms.Session.AUTO_ACKNOWLEDGE); } catch (javax.jms.JMSException jmse) { System.err.println("error: Cannot connect to Broker - " + broker); jmse.printStackTrace(); System.exit(1); } // Create Subscriber to application topics as well as a Publisher // to use for JMS replies. try { javax.jms.Topic topic = session.createTopic(APP_TOPIC); javax.jms.MessageConsumer subscriber = session.createConsumer(topic); subscriber.setMessageListener(this); replier = session.createProducer(null); // Topic will be set for each reply // Now that all setup is complete, start the Connection connect.start(); } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); } try { // Read all standard input and send it as a message. java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); while (true) { System.out.println("\nReplier application:\n" + "============================\n" + "The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n" + "The application gets requests with JMSReplyTo set on the " + APP_TOPIC + " topic." + "The message is transformed to all uppercase or all lowercase, and then returned to the requestor." + "The Requestor application displays the result.\n\n" + "Enter EXIT or press Ctrl+C to close the Replier.\n"); String s = stdin.readLine(); if (s == null || s.equalsIgnoreCase("EXIT")) { System.out.println("\nStopping Replier. Please wait..\n>"); exit(); } } } catch (java.io.IOException ioe) { ioe.printStackTrace(); } }
From source file:QueueMonitor.java
/** Constructor for MessageMonitor window. */ public QueueMonitor() { loadProperties();/*w w w.j av a 2 s.c o m*/ setTitle(title); // Connect to Message Broker try { javax.jms.ConnectionFactory factory; factory = new ActiveMQConnectionFactory(username, password, broker); connect = factory.createConnection(username, password); session = connect.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); } catch (javax.jms.JMSException jmse) { System.err.println("Cannot connect to Broker"); jmse.printStackTrace(); System.exit(1); } // Set up Queues: StringTokenizer queues = new StringTokenizer(browseQueues, ","); while (queues.hasMoreTokens()) { try { String queueName = queues.nextToken(); System.out.println("Monitoring " + queueName); theQueues.addElement(session.createQueue(queueName)); } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); } } // After init it is time to start the connection try { connect.start(); } catch (javax.jms.JMSException jmse) { System.err.println("Cannot start connection"); jmse.printStackTrace(); System.exit(1); } //Elements visible on the screen textArea.setEditable(false); scrollPane.setBorder( new CompoundBorder(new EmptyBorder(6, 6, 6, 6), new SoftBevelBorder(BevelBorder.LOWERED))); getContentPane().add(scrollPane, BorderLayout.CENTER); getContentPane().add(browseButton, BorderLayout.SOUTH); browseButton.addActionListener(new OnBrowse()); }
From source file:drepcap.frontend.jms.JmsAdapter.java
/** * //from w w w. j av a 2 s .c o m * Components are typically pcap-sensors or packet-mergers. The component * name is the name without any additional suffix, e.g., * "pcap.single.raw.2". * * @param connection * @param componentName * @throws JMSException */ public JmsAdapter(Connection connection, String componentName) throws JMSException { this.componentName = componentName; this.connection = connection; session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); commandTopic = session.createTopic(componentName + ".command"); commandConsumer = session.createConsumer(commandTopic); commandConsumer.setMessageListener(new MessageListener() { @Override public void onMessage(Message msg) { if (msg instanceof TextMessage) { TextMessage textMsg = (TextMessage) msg; try { final String txt = textMsg.getText(); for (StringReceiver cmdReplyReceiver : commandReplyReceivers) { if (cmdReplyReceiver != null && txt.startsWith("reply")) { cmdReplyReceiver.process(txt.replaceFirst("reply ", "")); } } } catch (JMSException e) { e.printStackTrace(); } } } }); commandProducer = session.createProducer(commandTopic); monitorTopic = session.createTopic(componentName + ".monitor"); monitorConsumer = session.createConsumer(monitorTopic); monitorConsumer.setMessageListener(new MessageListener() { @Override public void onMessage(Message msg) { if (msg instanceof TextMessage) { TextMessage textMsg = (TextMessage) msg; try { final String txt = textMsg.getText(); for (StringReceiver monReceiver : monitorReceivers) { if (monReceiver != null) { monReceiver.process(txt); } } if (statsDataReceivers.size() > 0) { processStatsFromString(txt); } } catch (JMSException e) { e.printStackTrace(); } } } }); }
From source file:TransactedChat.java
/** Create JMS client for publishing and subscribing to messages. */ private void chatter(String broker, String username, String password) { // Create a connection. try {/* w w w.ja v a 2 s . c o m*/ javax.jms.ConnectionFactory factory; factory = new ActiveMQConnectionFactory(username, password, broker); connect = factory.createConnection(username, password); // We want to be able up commit/rollback messages published, // but not affect messages consumed. Therefore, we need two sessions. publishSession = connect.createSession(true, javax.jms.Session.AUTO_ACKNOWLEDGE); subscribeSession = connect.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); } catch (javax.jms.JMSException jmse) { System.err.println("error: Cannot connect to Broker - " + broker); jmse.printStackTrace(); System.exit(1); } // Create Publisher and Subscriber to 'chat' topics try { javax.jms.Topic topic = subscribeSession.createTopic(APP_TOPIC); javax.jms.MessageConsumer subscriber = subscribeSession.createConsumer(topic); subscriber.setMessageListener(this); publisher = publishSession.createProducer(topic); // Now start the Connection connect.start(); } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); } try { // Read all standard input and send it as a message. java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); boolean showMessage = true; while (true) { if (showMessage) { System.out.println("TransactedChat application:"); System.out.println("==========================="); System.out.println("The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + "."); System.out.println("The application will stage messages to the " + APP_TOPIC + " topic until you either commit them or roll them back."); System.out.println( "The application also subscribes to that topic to consume any committed messages published there.\n"); System.out.println("1. Enter text to publish and then press Enter to stage the message."); System.out.println("2. Add a few messages to the transaction batch."); System.out.println("3. Then, either:"); System.out.println( " o Enter the text 'COMMIT', and press Enter to publish all the staged messages."); System.out.println( " o Enter the text 'CANCEL', and press Enter to drop the staged messages waiting to be sent."); showMessage = false; } String s = stdin.readLine(); if (s == null) exit(); else if (s.trim().equals("CANCEL")) { // Rollback the messages. A new transaction is implicitly // started for following messages. System.out.println("Cancelling messages..."); publishSession.rollback(); System.out.println("Staged messages have been cleared."); showMessage = false; // don't show the help message again. } else if (s.length() > 0) // See if we should send the messages if (s.trim().equals("COMMIT")) { // Commit (send) the messages. A new transaction is // implicitly started for following messages. System.out.println("Committing messages... "); publishSession.commit(); System.out.println("Staged messages have all been sent."); showMessage = false; // dont't show the help message again. } else { javax.jms.TextMessage msg = publishSession.createTextMessage(); msg.setText(username + ": " + s); // Publish the message persistently publisher.send(msg); } } } catch (java.io.IOException ioe) { ioe.printStackTrace(); } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); } }
From source file:org.apache.servicemix.jbi.cluster.requestor.ActiveMQJmsRequestorPool.java
public void onException(JMSException exception) { handleListenerException(exception);/*from w ww. j av a 2 s.co m*/ if (sharedConnectionEnabled()) { try { refreshSharedConnection(); } catch (JMSException e) { e.printStackTrace(); } } recreateConsumers(true); }
From source file:org.sakaiproject.kernel.messaging.email.EmailMessagingService.java
private void startConnections() { for (Connection conn : connections) { try {//w w w. java 2s. c o m conn.start(); } catch (JMSException e) { try { LOG.error("Fail to start connection: " + conn.getClientID()); } catch (JMSException e1) { // TMI } e.printStackTrace(); } } }