KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > presumo > mobileagent > AgentUtil


1 /**
2  * This file is part of Presumo.
3  *
4  * Presumo is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * Presumo is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Presumo; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  *
19  * Copyright (c) 2001 Dan Greff
20  */

21 package com.presumo.mobileagent;
22
23
24 import javax.jms.ExceptionListener JavaDoc;
25 import javax.jms.Topic JavaDoc;
26 import javax.jms.TopicConnection JavaDoc;
27 import javax.jms.TopicSession JavaDoc;
28 import javax.jms.TopicSubscriber JavaDoc;
29 import javax.jms.TopicPublisher JavaDoc;
30 import javax.jms.Message JavaDoc;
31 import javax.jms.MessageListener JavaDoc;
32 import javax.jms.ObjectMessage JavaDoc;
33 import javax.jms.JMSException JavaDoc;
34 import javax.jms.Session JavaDoc;
35
36 public class AgentUtil
37 {
38
39   public static void sendStartMessage(TopicConnection JavaDoc connx,
40                                       String JavaDoc [] agentRunners)
41     throws JMSException JavaDoc
42   {
43     startStopHelper(connx, agentRunners, Agent.AGENT_START);
44   }
45
46   public static void sendStopMessage(TopicConnection JavaDoc connx,
47                                      String JavaDoc [] agentRunners)
48     throws JMSException JavaDoc
49   {
50     startStopHelper(connx, agentRunners, Agent.AGENT_STOP);
51   }
52
53
54   private static void startStopHelper(TopicConnection JavaDoc connx,
55                                       String JavaDoc [] agentRunners,
56                                       int messageType)
57     throws JMSException JavaDoc
58   {
59     TopicSession JavaDoc session = connx.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
60     Topic JavaDoc topic = session.createTopic(Agent.AGENT_TOPIC);
61     TopicPublisher JavaDoc pub = session.createPublisher(topic);
62
63     StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
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 JavaDoc 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