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

Quick Search    Search Deep

Source code: org/activemq/broker/BrokerClientStub.java


1   /** 
2    * 
3    * Copyright 2004 Protique Ltd
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * You may obtain a copy of the License at 
8    * 
9    * http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, 
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14   * See the License for the specific language governing permissions and 
15   * limitations under the License. 
16   * 
17   **/
18  package org.activemq.broker;
19  
20  import org.activemq.message.ActiveMQMessage;
21  import org.activemq.message.ConnectionInfo;
22  import org.activemq.transport.TransportChannel;
23  
24  import javax.jms.JMSException;
25  import javax.security.auth.Subject;
26  
27  import java.util.ArrayList;
28  import java.util.List;
29  
30  
31  /**
32   * A mock dispatcher for testing
33   *
34   * @version $Revision: 1.1.1.1 $
35   */
36  public class BrokerClientStub implements BrokerClient {
37  
38      private List messages = new ArrayList();
39      private Object semaphore;
40    private Subject subject;
41      private ConnectionInfo connectionInfo = new ConnectionInfo();
42  
43      public BrokerClientStub() {
44          this(new Object());
45      }
46  
47      public BrokerClientStub(Object semaphore) {
48          this.semaphore = semaphore;
49      }
50  
51      public ConnectionInfo getConnectionInfo() {
52          return connectionInfo;
53      }
54  
55      public void setConnectionInfo(ConnectionInfo connectionInfo) {
56          this.connectionInfo = connectionInfo;
57      }
58  
59      /**
60       * @return all the messages on the list so far, clearing the buffer
61       */
62      public synchronized List flushMessages() {
63          List answer = new ArrayList(messages);
64          messages.clear();
65          return answer;
66      }
67  
68      public synchronized void dispatch(ActiveMQMessage message) {
69          messages.add(message);
70          synchronized (semaphore) {
71              semaphore.notifyAll();
72          }
73      }
74  
75      public void initialize(BrokerConnector brokerConnector, TransportChannel channel) {
76      }
77  
78      public void waitForMessageToArrive() {
79          System.out.println("Waiting for message to arrive");
80  
81          long start = System.currentTimeMillis();
82  
83          try {
84              if (messages.isEmpty()) {
85                  synchronized (semaphore) {
86                      semaphore.wait(4000);
87                  }
88              }
89          }
90          catch (InterruptedException e) {
91              System.out.println("Caught: " + e);
92          }
93          long end = System.currentTimeMillis() - start;
94  
95          System.out.println("End of wait for " + end + " millis");
96      }
97  
98      public void start() throws JMSException {
99      }
100 
101     public void stop() throws JMSException {
102     }
103 
104     /**
105      * @return true if the peer for this Client is itself another Broker
106      */
107     public boolean isBrokerConnection() {
108         return false;
109     }
110 
111 
112     /**
113      * Get the Capacity for in-progress messages at the peer (probably a JMSConnection)
114      * Legimate values between 0-100. 100 representing that the peer cannot process
115      * any more messages at the current time
116      *
117      * @return
118      */
119     public int getCapacity() {
120         return 100;
121     }
122 
123     /**
124      * Get an indication if the peer should be considered as a slow consumer
125      *
126      * @return true id the peer should be considered as a slow consumer
127      */
128     public boolean isSlowConsumer() {
129         return false;
130     }
131 
132     /**
133      * Update the peer Connection about the Broker's capacity for messages
134      *
135      * @param capacity
136      */
137     public void updateBrokerCapacity(int capacity) {
138 
139     }
140 
141     public String getClientID() {
142         return "dummyClientID";
143     }
144 
145     public void cleanUp() {
146     }
147 
148     public TransportChannel getChannel() {
149         return null;
150     }
151 
152    
153     public BrokerConnector getBrokerConnector() {
154         return null;
155     }
156 
157    
158     public boolean isClusteredConnection() {
159         return false;
160     }
161 
162     
163   public void validateConnection(int timeout) throws JMSException {
164 
165   }
166     
167   public void setSubject(Subject subject) {
168     this.subject = subject;
169   }
170 
171   public Subject getSubject() {
172     return subject;
173   }
174   
175   
176 }