Changeset 83 for trunk/src/main/java/omq/common/util
- Timestamp:
- 07/08/13 13:29:24 (11 years ago)
- Location:
- trunk/src/main/java/omq/common/util
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/main/java/omq/common/util/OmqConnectionFactory.java
r77 r83 13 13 14 14 /** 15 * This class creates RabbitMQ connections 15 16 * 16 17 * @author Sergi Toda <sergi.toda@estudiants.urv.cat> … … 23 24 private static int connectionTimeout = 2 * 1000; 24 25 26 /** 27 * If this class is wanted to use as a singleton class this is the init 28 * function 29 * 30 * @param env 31 * - environment that sets the properties needed by RabbitMQ 32 * @throws KeyManagementException 33 * @throws NoSuchAlgorithmException 34 * @throws IOException 35 */ 25 36 public static void init(Properties env) throws KeyManagementException, NoSuchAlgorithmException, IOException { 26 37 if (connection == null) { … … 29 40 } 30 41 42 /** 43 * This function returns a working connection. 44 * 45 * @param env 46 * - used if it's necessary to create a new connection 47 * @return workingConnection 48 * @throws Exception 49 */ 31 50 public static Connection getNewWorkingConnection(Properties env) throws Exception { 32 51 Connection connection = null; … … 50 69 } 51 70 71 /** 72 * This function creates a new rabbitmq connection using the properties set 73 * in env 74 * 75 * @param env 76 * - Properties needed to create a new connection: username, 77 * password, rabbit_host, rabbit_port, enable_ssl (optional) 78 * @return new Connection 79 * @throws IOException 80 * @throws KeyManagementException 81 * @throws NoSuchAlgorithmException 82 */ 52 83 public static Connection getNewConnection(Properties env) throws IOException, KeyManagementException, NoSuchAlgorithmException { 53 84 // Get login info of rabbitmq … … 59 90 int port = Integer.parseInt(env.getProperty(ParameterQueue.RABBIT_PORT)); 60 91 61 boolean ssl = Boolean.parseBoolean(env.getProperty(ParameterQueue.ENABLE_SSL ));92 boolean ssl = Boolean.parseBoolean(env.getProperty(ParameterQueue.ENABLE_SSL, "false")); 62 93 63 94 // Start a new connection and channel … … 78 109 } 79 110 111 /** 112 * This method creates a new channel if the singleton pattern is used 113 * 114 * @return new Channel 115 * @throws IOException 116 */ 80 117 public static Channel getNewChannel() throws IOException { 81 118 Channel channel = connection.createChannel(); -
trunk/src/main/java/omq/common/util/ParameterQueue.java
r77 r83 2 2 3 3 /** 4 * This class is used to create new environments. 4 5 * 5 6 * @author Sergi Toda <sergi.toda@estudiants.urv.cat> … … 7 8 */ 8 9 public class ParameterQueue { 9 10 /*11 * Properties environment12 */13 10 14 11 /** … … 69 66 public static String MESSAGE_TTL_IN_QUEUES = "omq.message_ttl_queue"; 70 67 71 // TODO persistent messages? the messages will be saved in the disk if this72 // flag is set true73 74 68 /** 75 69 * Set if the system will use ssl … … 111 105 112 106 /** 113 * Time in milis 107 * Time in milis by default is set in a minute 114 108 */ 115 109 public static long DEFAULT_TIMEOUT = 1 * 1000 * 60; -
trunk/src/main/java/omq/common/util/Serializer.java
r77 r83 15 15 /** 16 16 * 17 * Serializer enables to serialize the requests and the responses of the 18 * remoteObjects. This class is used to have the same serializer object a not to 19 * create new instances every time they are needed. 20 * 17 21 * @author Sergi Toda <sergi.toda@estudiants.urv.cat> 18 22 * 19 23 */ 20 24 public class Serializer { 21 // private static final Logger logger =22 // Logger.getLogger(Serializer.class.getName());23 25 public static final String KRYO = "kryo"; 24 26 public static final String JAVA = "java"; -
trunk/src/main/java/omq/common/util/Serializers/GsonImp.java
r75 r83 15 15 import com.google.gson.JsonParser; 16 16 17 /** 18 * Json serialize implementation. It uses the Gson libraries. 19 * 20 * @author Sergi Toda <sergi.toda@estudiants.urv.cat> 21 * 22 */ 17 23 public class GsonImp implements ISerializer { 18 24 private final Gson gson = new Gson(); -
trunk/src/main/java/omq/common/util/Serializers/ISerializer.java
r72 r83 7 7 8 8 /** 9 * An ISerializer object can serialize any kind of objects and deserialize 10 * Requests and Responses. 9 11 * 10 12 * @author Sergi Toda <sergi.toda@estudiants.urv.cat> … … 12 14 */ 13 15 public interface ISerializer { 16 /** 17 * Serialize 18 * 19 * @param obj 20 * - object to serialize 21 * @return objectSerialized 22 * @throws SerializerException 23 * - If the serialization failed 24 */ 14 25 public byte[] serialize(Object obj) throws SerializerException; 15 26 27 /** 28 * Deserialize a Request 29 * 30 * @param bytes 31 * - serialized request 32 * @param obj 33 * - remoteObject which is receiving requests 34 * @return request 35 * @throws SerializerException 36 * - If the serialization failed 37 */ 16 38 public Request deserializeRequest(byte[] bytes, RemoteObject obj) throws SerializerException; 17 39 40 /** 41 * Deserialize a Response 42 * 43 * @param bytes 44 * serialized response 45 * @param type 46 * - return type expected 47 * @return response 48 * @throws SerializerException 49 * - If the serialization failed 50 */ 18 51 public Response deserializeResponse(byte[] bytes, Class<?> type) throws SerializerException; 19 52 } -
trunk/src/main/java/omq/common/util/Serializers/JavaImp.java
r72 r83 12 12 13 13 /** 14 * Java serialize implementation. It uses the default java serialization. 14 15 * 15 16 * @author Sergi Toda <sergi.toda@estudiants.urv.cat> -
trunk/src/main/java/omq/common/util/Serializers/KryoImp.java
r72 r83 13 13 14 14 /** 15 * Kryo serializerimplementation. It uses the Kryo libraries. 15 16 * 16 17 * @author Sergi Toda <sergi.toda@estudiants.urv.cat> -
trunk/src/main/java/omq/common/util/Zipper.java
r44 r83 7 7 import java.util.zip.GZIPOutputStream; 8 8 9 /** 10 * This class enables the compression of the information sent through the 11 * rabbitmq server. 12 * 13 * @author Sergi Toda <sergi.toda@estudiants.urv.cat> 14 * 15 */ 9 16 public class Zipper { 10 17 … … 16 23 zos = new GZIPOutputStream(baos); 17 24 zos.write(b); 18 } finally {19 if (zos != null){25 } finally { 26 if (zos != null) { 20 27 zos.close(); 21 28 } 22 29 23 30 baos.close(); 24 31 } 25 32 26 33 return baos.toByteArray(); 27 34 } … … 34 41 try { 35 42 zis = new GZIPInputStream(bais); 36 43 37 44 byte[] tmpBuffer = new byte[256]; 38 45 int n; … … 40 47 baos.write(tmpBuffer, 0, n); 41 48 } 42 } finally { 43 if (zis != null){49 } finally { 50 if (zis != null) { 44 51 zis.close(); 45 52 } 46 53 47 54 bais.close(); 48 55 baos.close(); 49 } 50 56 } 57 51 58 return baos.toByteArray(); 52 } 59 } 53 60 }
Note: See TracChangeset
for help on using the changeset viewer.