Changeset 27 for trunk/objectmq/src/omq/common/broker/Broker.java
- Timestamp:
- 05/28/13 18:21:37 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/objectmq/src/omq/common/broker/Broker.java
r24 r27 23 23 import com.rabbitmq.client.Connection; 24 24 import com.rabbitmq.client.QueueingConsumer; 25 import com.rabbitmq.client.QueueingConsumer.Delivery; 25 26 import com.rabbitmq.client.ShutdownListener; 26 27 import com.rabbitmq.client.ShutdownSignalException; 27 import com.rabbitmq.client.QueueingConsumer.Delivery;28 28 29 29 public class Broker { … … 38 38 Environment.setEnvironment(env); 39 39 connection = OmqConnectionFactory.getNewConnection(env); 40 connection.addShutdownListener(new ShutdownListener() {41 @Override42 public void shutdownCompleted(ShutdownSignalException cause) {43 if (connection.isOpen()) {44 try {45 connection.close();46 } catch (IOException e) {47 e.printStackTrace();48 }49 }50 try {51 Properties env = Environment.getEnvironment();52 connection = OmqConnectionFactory.getNewWorkingConnection(env);53 channel = connection.createChannel();54 } catch (Exception e) {55 e.printStackTrace();56 }57 }58 });59 40 channel = connection.createChannel(); 41 addFaultTolerance(); 60 42 try { 61 43 tryConnection(env); … … 165 147 } 166 148 149 private static void addFaultTolerance() { 150 connection.addShutdownListener(new ShutdownListener() { 151 @Override 152 public void shutdownCompleted(ShutdownSignalException cause) { 153 154 if (cause.isHardError()) { 155 if (connection.isOpen()) { 156 try { 157 connection.close(); 158 } catch (IOException e) { 159 e.printStackTrace(); 160 } 161 } 162 try { 163 Properties env = Environment.getEnvironment(); 164 connection = OmqConnectionFactory.getNewWorkingConnection(env); 165 channel = connection.createChannel(); 166 addFaultTolerance(); 167 } catch (Exception e) { 168 e.printStackTrace(); 169 } 170 } else { 171 Channel channel = (Channel) cause.getReference(); 172 if (channel.isOpen()) { 173 try { 174 channel.close(); 175 } catch (IOException e) { 176 e.printStackTrace(); 177 } 178 } 179 } 180 } 181 }); 182 } 183 167 184 }
Note: See TracChangeset
for help on using the changeset viewer.