1 21 package com.presumo.mobileagent; 22 23 24 import javax.jms.ExceptionListener ; 25 import javax.jms.Topic ; 26 import javax.jms.TopicConnection ; 27 import javax.jms.TopicSession ; 28 import javax.jms.TopicSubscriber ; 29 import javax.jms.TopicPublisher ; 30 import javax.jms.Message ; 31 import javax.jms.MessageListener ; 32 import javax.jms.ObjectMessage ; 33 import javax.jms.JMSException ; 34 import javax.jms.Session ; 35 36 public class AgentUtil 37 { 38 39 public static void sendStartMessage(TopicConnection connx, 40 String [] agentRunners) 41 throws JMSException  42 { 43 startStopHelper(connx, agentRunners, Agent.AGENT_START); 44 } 45 46 public static void sendStopMessage(TopicConnection connx, 47 String [] agentRunners) 48 throws JMSException  49 { 50 startStopHelper(connx, agentRunners, Agent.AGENT_STOP); 51 } 52 53 54 private static void startStopHelper(TopicConnection connx, 55 String [] agentRunners, 56 int messageType) 57 throws JMSException  58 { 59 TopicSession session = connx.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); 60 Topic topic = session.createTopic(Agent.AGENT_TOPIC); 61 TopicPublisher pub = session.createPublisher(topic); 62 63 StringBuffer buf = new StringBuffer (); 64 for (int i=0; i < agentRunners.length; ++i) { 65 buf.append(agentRunners[i]); 66 if (i < (agentRunners.length-1)) buf.append(';'); 67 } 68 69 Message msg = session.createMessage(); 70 msg.setIntProperty(Agent.MESSAGE_TYPE, messageType); 71 msg.setStringProperty(Agent.RUNNER_PROP, buf.toString()); 72 73 pub.publish(msg); 74 } 75 76 } 77
| Popular Tags
|