Changeset 49 for trunk/src/main/java/omq/common
- Timestamp:
- 06/19/13 15:59:53 (11 years ago)
- Location:
- trunk/src/main/java/omq/common
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/main/java/omq/common/broker/Broker.java
r47 r49 2 2 3 3 import java.io.IOException; 4 import java.net.URL; 4 5 import java.util.HashMap; 5 6 import java.util.Map; … … 20 21 import omq.server.RemoteObject; 21 22 23 import org.apache.log4j.Logger; 24 import org.apache.log4j.xml.DOMConfigurator; 25 22 26 import com.rabbitmq.client.Channel; 23 27 import com.rabbitmq.client.Connection; … … 28 32 29 33 public class Broker { 34 35 private static final Logger logger = Logger.getLogger(Broker.class.getName()); 36 30 37 private static Connection connection; 31 38 private static Channel channel; … … 45 52 public static synchronized void initBroker(Properties env) throws Exception { 46 53 if (environment == null) { 54 55 // Load log4j configuration 56 URL log4jResource = Broker.class.getResource("/log4j.xml"); 57 DOMConfigurator.configure(log4jResource); 58 47 59 remoteObjs = new HashMap<String, RemoteObject>(); 48 60 environment = env; … … 58 70 } 59 71 } else { 60 throw new InitBrokerException("Broker already started"); 72 logger.error("Broker is already started"); 73 throw new InitBrokerException("Broker is already started"); 61 74 } 62 75 } 63 76 64 77 public static void stopBroker() throws Exception { 78 logger.warn("Stopping broker"); 65 79 // Stop the client 66 80 if (clientStarted) { … … 93 107 94 108 public static void closeConnection() throws IOException { 109 logger.warn("Clossing connection"); 95 110 connectionClosed = true; 96 111 connection.close(); … … 241 256 @Override 242 257 public void shutdownCompleted(ShutdownSignalException cause) { 258 logger.warn("Shutdown message received. Cause: " + cause.getMessage()); 243 259 if (!connectionClosed) 244 260 if (cause.isHardError()) { -
trunk/src/main/java/omq/common/event/EventDispatcher.java
r44 r49 9 9 import omq.common.util.ParameterQueue; 10 10 import omq.common.util.Serializer; 11 12 import org.apache.log4j.Logger; 11 13 12 14 import com.rabbitmq.client.Channel; … … 26 28 @SuppressWarnings("rawtypes") 27 29 public class EventDispatcher extends Thread { 30 private static final Logger logger = Logger.getLogger(EventDispatcher.class.getName()); 28 31 private static EventDispatcher dispatcher; 29 32 … … 67 70 68 71 public static void stopEventDispatcher() throws Exception { 72 logger.warn("Stopping EventDispatcher"); 69 73 dispatcher.setListeners(null); 70 74 dispatcher.killed = true; … … 102 106 event = Serializer.deserializeEvent(delivery.getBody()); 103 107 104 System.out.println("Event received -> Topic: " + event.getTopic() + "CorrId: " + event.getCorrId());108 logger.info("Event received -> Topic: " + event.getTopic() + "CorrId: " + event.getCorrId()); 105 109 // Log.saveLog("Client-Deserialize", delivery.getBody()); 106 110 … … 112 116 dispatch(event.getTopic(), event); 113 117 } catch (InterruptedException i) { 114 System.out.println("InterruptedException e: " + i); 115 i.printStackTrace(); 118 logger.error(i); 116 119 } catch (ShutdownSignalException e) { 117 System.out.println("ShutdownSignalException e: " + e); 118 e.printStackTrace(); 120 logger.error(e); 119 121 try { 120 122 if (channel.isOpen()) { … … 127 129 Thread.sleep(milis); 128 130 } catch (InterruptedException e2) { 129 e2.printStackTrace();131 logger.error(e2); 130 132 } 131 e1.printStackTrace();133 logger.error(e1); 132 134 } 133 135 } catch (ConsumerCancelledException e) { 134 System.out.println("ConsumerCancelledException e: " + e); 135 e.printStackTrace(); 136 logger.error(e); 136 137 } catch (Exception e) { 137 System.out.println("Exception e: " + e); 138 e.printStackTrace(); 138 logger.error(e); 139 139 } 140 140 } … … 160 160 String reference = e.getTopic(); 161 161 162 System.out.println("EventDispatcher declaring fanout -> " + reference + " Binding with: " + queueName);162 logger.info("Declaring fanout -> " + reference + " Binding with: " + queueName); 163 163 164 164 channel.exchangeDeclare(reference, "fanout"); -
trunk/src/main/java/omq/common/util/OmqConnectionFactory.java
r44 r49 5 5 import java.security.NoSuchAlgorithmException; 6 6 import java.util.Properties; 7 8 import org.apache.log4j.Logger; 7 9 8 10 import com.rabbitmq.client.Channel; … … 16 18 */ 17 19 public class OmqConnectionFactory { 20 private static final Logger logger = Logger.getLogger(OmqConnectionFactory.class.getName()); 21 18 22 private static Connection connection; 19 23 private static int connectionTimeout = 2 * 1000; … … 34 38 working = true; 35 39 } catch (Exception e) { 36 e.printStackTrace();40 logger.error(e); 37 41 long milis = Long.parseLong(env.getProperty(ParameterQueue.RETRY_TIME_CONNECTION, "2000")); 38 42 Thread.sleep(milis); … … 64 68 factory.useSslProtocol(); 65 69 } 66 return factory.newConnection(); 70 71 Connection connection = factory.newConnection(); 72 logger.info("New connection created using: username: " + username + ", host: " + host + ", port: " + port + ", connection timeout: " 73 + connectionTimeout + " SSL enabled: " + ssl); 74 return connection; 67 75 } 68 76 69 77 public static Channel getNewChannel() throws IOException { 70 return connection.createChannel(); 78 Channel channel = connection.createChannel(); 79 logger.info("New channel created using the default connection"); 80 return channel; 71 81 } 72 82 } -
trunk/src/main/java/omq/common/util/Serializer.java
r47 r49 3 3 import java.io.IOException; 4 4 import java.util.Properties; 5 6 import org.apache.log4j.Logger; 5 7 6 8 import omq.common.broker.Broker; … … 21 23 */ 22 24 public class Serializer { 25 private static final Logger logger = Logger.getLogger(Serializer.class.getName()); 23 26 public static String kryo = "kryo"; 24 27 public static String java = "java"; … … 158 161 159 162 public static void removeSerializers() { 163 logger.warn("Removing serializers"); 160 164 serializer = null; 161 165 kryoSerializer = null; -
trunk/src/main/java/omq/common/util/Serializers/GsonImp.java
r44 r49 22 22 public byte[] serialize(Object obj) throws SerializerException { 23 23 String json = gson.toJson(obj); 24 System.out.println(json);25 24 return json.getBytes(); 26 25 }
Note: See TracChangeset
for help on using the changeset viewer.