Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/test/JmsResourceProvider.java


1   /*
2    * Created on May 9, 2004
3    * 
4    * TODO To change the template for this generated file go to Window -
5    * Preferences - Java - Code Generation - Code and Comments
6    */
7   package org.activemq.test;
8   import javax.jms.Connection;
9   import javax.jms.ConnectionConsumer;
10  import javax.jms.ConnectionFactory;
11  import javax.jms.Destination;
12  import javax.jms.JMSException;
13  import javax.jms.MessageConsumer;
14  import javax.jms.MessageProducer;
15  import javax.jms.ServerSessionPool;
16  import javax.jms.Session;
17  import javax.jms.DeliveryMode;
18  import javax.jms.Topic;
19  
20  import org.activemq.ActiveMQConnectionFactory;
21  /**
22   * @version $Revision: 1.1.1.1 $
23   */
24  public class JmsResourceProvider {
25    
26    private String serverUri = "vm://localhost";
27    private boolean transacted = false;
28    private int ackMode = Session.AUTO_ACKNOWLEDGE;
29    private boolean isTopic;
30      private int deliveryMode=DeliveryMode.PERSISTENT;
31      private String durableName = "DummyName";
32      private String clientID = getClass().getName();
33  
34  
35    /**
36     * @see org.activemq.test.JmsResourceProvider#createConnectionFactory()
37     */
38    public ConnectionFactory createConnectionFactory() throws JMSException {
39      return new ActiveMQConnectionFactory(serverUri);
40    }
41    
42    /**
43     * @see org.activemq.test.JmsResourceProvider#createConnection(javax.jms.ConnectionFactory)
44     */
45    public Connection createConnection(ConnectionFactory cf) throws JMSException {
46          Connection connection = cf.createConnection();
47          if (isDurableSubscriber()) {
48              connection.setClientID(getClientID());
49          }
50          return connection;
51    }
52    /**
53     * @see org.activemq.test.JmsResourceProvider#createSession(javax.jms.Connection)
54     */
55    public Session createSession(Connection conn) throws JMSException {
56      return conn.createSession(transacted, ackMode);
57    }
58    /**
59     * @see org.activemq.test.JmsResourceProvider#createConsumer(javax.jms.Session,
60     *      javax.jms.Destination)
61     */
62    public MessageConsumer createConsumer(Session session,
63        Destination destination) throws JMSException {
64          if (isDurableSubscriber()) {
65              return session.createDurableSubscriber((Topic) destination, durableName);
66          }
67      return session.createConsumer(destination);
68    }
69  
70    /**
71     * @param ssp
72     * @return
73     */
74    public ConnectionConsumer createConnectionConsumer(Connection connection, Destination destination, ServerSessionPool ssp) throws JMSException {
75      return connection.createConnectionConsumer(destination,null,ssp,1);
76    }
77  
78    /**
79     * @see org.activemq.test.JmsResourceProvider#createProducer(javax.jms.Session,
80     *      javax.jms.Destination)
81     */
82    public MessageProducer createProducer(Session session,
83        Destination destination) throws JMSException {
84          MessageProducer producer = session.createProducer(destination);
85          producer.setDeliveryMode(deliveryMode);
86          return producer;
87    }
88    /**
89     * @see org.activemq.test.JmsResourceProvider#createDestination(javax.jms.Session,
90     *      java.lang.String)
91     */
92    public Destination createDestination(Session session, String name)
93        throws JMSException {
94      if( isTopic )
95        return session.createTopic("TOPIC."+name);
96      else 
97        return session.createQueue("QUEUE."+name);
98    }
99  
100     public boolean isDurableSubscriber() {
101         return isTopic && deliveryMode == DeliveryMode.PERSISTENT;
102     }
103 
104   /**
105    * @return Returns the ackMode.
106    */
107   public int getAckMode() {
108     return ackMode;
109   }
110   /**
111    * @param ackMode The ackMode to set.
112    */
113   public void setAckMode(int ackMode) {
114     this.ackMode = ackMode;
115   }
116   /**
117    * @return Returns the isTopic.
118    */
119   public boolean isTopic() {
120     return isTopic;
121   }
122   /**
123    * @param isTopic The isTopic to set.
124    */
125   public void setTopic(boolean isTopic) {
126     this.isTopic = isTopic;
127   }
128   /**
129    * @return Returns the serverUri.
130    */
131   public String getServerUri() {
132     return serverUri;
133   }
134   /**
135    * @param serverUri The serverUri to set.
136    */
137   public void setServerUri(String serverUri) {
138     this.serverUri = serverUri;
139   }
140   /**
141    * @return Returns the transacted.
142    */
143   public boolean isTransacted() {
144     return transacted;
145   }
146   /**
147    * @param transacted The transacted to set.
148    */
149   public void setTransacted(boolean transacted) {
150     this.transacted = transacted;
151   }
152 
153     public int getDeliveryMode() {
154         return deliveryMode;
155     }
156 
157     public void setDeliveryMode(int deliveryMode) {
158         this.deliveryMode = deliveryMode;
159     }
160 
161     public String getClientID() {
162         return clientID;
163     }
164 
165     public void setClientID(String clientID) {
166         this.clientID = clientID;
167     }
168 
169     public String getDurableName() {
170         return durableName;
171     }
172 
173     public void setDurableName(String durableName) {
174         this.durableName = durableName;
175     }
176 }