Changeset 47 for trunk/src/main/java/omq/common/util
- Timestamp:
- 06/18/13 16:51:22 (11 years ago)
- Location:
- trunk/src/main/java/omq/common/util
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/main/java/omq/common/util/Log.java
r44 r47 7 7 import java.util.Properties; 8 8 9 import omq. exception.EnvironmentException;9 import omq.common.broker.Broker; 10 10 11 11 public class Log { 12 12 13 13 public static void saveLog(String processName, byte[] bytesResponse) throws IOException { 14 try {15 Properties env = Environment.getEnvironment();16 14 17 String debugPath = env.getProperty(ParameterQueue.DEBUGFILE, ""); 18 if (debugPath.length() > 0) { 19 long timeNow = (new Date()).getTime(); 15 Properties env = Broker.getEnvironment(); 20 16 21 File outputFolder = new File(debugPath + File.separator); 22 outputFolder.mkdirs(); 23 24 // File outputFolder = new File(debugPath + File.separator + processName); 25 // outputFolder.mkdirs(); 17 String debugPath = env.getProperty(ParameterQueue.DEBUGFILE, ""); 18 if (debugPath.length() > 0) { 19 long timeNow = (new Date()).getTime(); 26 20 27 // File outputFileContent = new File(outputFolder.getAbsoluteFile() + File.separator + "content_" + timeNow); 28 // FileOutputStream outputStream = new FileOutputStream(outputFileContent); 29 // IOUtils.write(bytesResponse, outputStream); 30 // outputStream.close(); 21 File outputFolder = new File(debugPath + File.separator); 22 outputFolder.mkdirs(); 31 23 32 File outputFileLog = new File(debugPath + File.separator + "log"); 33 boolean exist = outputFileLog.exists(); 34 35 FileWriter fw = new FileWriter(outputFileLog, true); // the true will append the new data 36 if(!exist){ 37 fw.write("#ProcessName\t\tFile\t\t\t\t\tDate\t\t\tSize\n"); 38 } 39 fw.write(processName + "\t" + "content_" + timeNow + "\t" + timeNow + "\t" + bytesResponse.length + "\tbytes\n"); 40 fw.close(); 24 // File outputFolder = new File(debugPath + File.separator + 25 // processName); 26 // outputFolder.mkdirs(); 27 28 // File outputFileContent = new 29 // File(outputFolder.getAbsoluteFile() + File.separator + 30 // "content_" + timeNow); 31 // FileOutputStream outputStream = new 32 // FileOutputStream(outputFileContent); 33 // IOUtils.write(bytesResponse, outputStream); 34 // outputStream.close(); 35 36 File outputFileLog = new File(debugPath + File.separator + "log"); 37 boolean exist = outputFileLog.exists(); 38 39 FileWriter fw = new FileWriter(outputFileLog, true); // the true 40 // will 41 // append 42 // the 43 // new 44 // data 45 if (!exist) { 46 fw.write("#ProcessName\t\tFile\t\t\t\t\tDate\t\t\tSize\n"); 41 47 } 42 } catch (EnvironmentException e) {43 throw new IOException(e.getMessage(), e);48 fw.write(processName + "\t" + "content_" + timeNow + "\t" + timeNow + "\t" + bytesResponse.length + "\tbytes\n"); 49 fw.close(); 44 50 } 51 45 52 } 46 53 47 54 public static void saveTimeSendRequestLog(String processName, String coorId, String method, long timeNow) throws IOException { 48 try {49 Properties env = Environment.getEnvironment();50 55 51 String debugPath = env.getProperty(ParameterQueue.DEBUGFILE, ""); 52 if (debugPath.length() > 0) { 53 File outputFolder = new File(debugPath + File.separator + processName); 54 outputFolder.mkdirs(); 55 56 File outputFileLog = new File(outputFolder + File.separator + "log"); 57 boolean exist = outputFileLog.exists(); 58 59 FileWriter fw = new FileWriter(outputFileLog, true); // the true will append the new data 60 if(!exist){ 61 fw.write("#CoorId\tMethod\tDate\n"); 62 } 63 fw.write(coorId + "\t" + method + "\t" + timeNow + "\n"); 64 fw.close(); 56 Properties env = Broker.getEnvironment(); 57 58 String debugPath = env.getProperty(ParameterQueue.DEBUGFILE, ""); 59 if (debugPath.length() > 0) { 60 File outputFolder = new File(debugPath + File.separator + processName); 61 outputFolder.mkdirs(); 62 63 File outputFileLog = new File(outputFolder + File.separator + "log"); 64 boolean exist = outputFileLog.exists(); 65 66 FileWriter fw = new FileWriter(outputFileLog, true); // the true 67 // will 68 // append 69 // the 70 // new 71 // data 72 if (!exist) { 73 fw.write("#CoorId\tMethod\tDate\n"); 65 74 } 66 } catch (EnvironmentException e) {67 throw new IOException(e.getMessage(), e);75 fw.write(coorId + "\t" + method + "\t" + timeNow + "\n"); 76 fw.close(); 68 77 } 69 } 78 79 } 70 80 } -
trunk/src/main/java/omq/common/util/Serializer.java
r44 r47 4 4 import java.util.Properties; 5 5 6 import omq.common.broker.Broker; 6 7 import omq.common.event.Event; 7 8 import omq.common.message.Request; … … 11 12 import omq.common.util.Serializers.JavaImp; 12 13 import omq.common.util.Serializers.KryoImp; 13 import omq.exception.EnvironmentException;14 14 import omq.exception.SerializerException; 15 15 import omq.server.RemoteObject; … … 21 21 */ 22 22 public class Serializer { 23 public static String kryo = KryoImp.class.getCanonicalName();24 public static String java = JavaImp.class.getCanonicalName();25 public static String gson = GsonImp.class.getCanonicalName();23 public static String kryo = "kryo"; 24 public static String java = "java"; 25 public static String gson = "gson"; 26 26 27 // Client serializer 27 28 public static ISerializer serializer; 28 29 30 // Server serializers 31 private static ISerializer kryoSerializer; 32 private static ISerializer javaSerializer; 33 private static ISerializer gsonSerializer; 34 29 35 private static Boolean getEnableCompression() { 30 Boolean enableCompression = false; 31 try { 32 Properties env = Environment.getEnvironment(); 33 enableCompression = Boolean.valueOf(env.getProperty(ParameterQueue.ENABLECOMPRESSION, "false")); 34 } catch (EnvironmentException e) { 35 e.printStackTrace(); 36 } 37 38 return enableCompression; 36 Properties env = Broker.getEnvironment(); 37 return Boolean.valueOf(env.getProperty(ParameterQueue.ENABLECOMPRESSION, "false")); 39 38 } 40 39 … … 42 41 if (serializer == null) { 43 42 try { 44 Properties env = Environment.getEnvironment();43 Properties env = Broker.getEnvironment(); 45 44 String className = env.getProperty(ParameterQueue.SERIALIZER_NAME, Serializer.java); 46 45 … … 49 48 } 50 49 51 serializer = (ISerializer) Class.forName(className).newInstance();50 serializer = getInstance(className); 52 51 } catch (Exception ex) { 53 52 throw new SerializerException(ex.getMessage(), ex); … … 58 57 } 59 58 59 public static ISerializer getInstance(String type) throws SerializerException { 60 if (kryo.equals(type)) { 61 if (kryoSerializer == null) { 62 kryoSerializer = new KryoImp(); 63 } 64 return kryoSerializer; 65 } else if (gson.endsWith(type)) { 66 if (gsonSerializer == null) { 67 gsonSerializer = new GsonImp(); 68 } 69 return gsonSerializer; 70 } else { 71 if (javaSerializer == null) { 72 javaSerializer = new JavaImp(); 73 } 74 return javaSerializer; 75 } 76 } 77 78 public static byte[] serialize(String type, Object obj) throws SerializerException { 79 ISerializer instance = getInstance(type); 80 81 Boolean enableCompression = getEnableCompression(); 82 if (enableCompression) { 83 byte[] objSerialized = instance.serialize(obj); 84 try { 85 return Zipper.zip(objSerialized); 86 } catch (IOException e) { 87 throw new SerializerException(e.getMessage(), e); 88 } 89 } else { 90 return instance.serialize(obj); 91 } 92 } 93 94 // TODO: remove this function and think about the event serialization 60 95 public static byte[] serialize(Object obj) throws SerializerException { 61 96 ISerializer instance = getInstance(); … … 74 109 } 75 110 76 public static Request deserializeRequest( byte[] bytes, RemoteObject obj) throws SerializerException {77 ISerializer instance = getInstance( );111 public static Request deserializeRequest(String type, byte[] bytes, RemoteObject obj) throws SerializerException { 112 ISerializer instance = getInstance(type); 78 113 79 114 Boolean enableCompression = getEnableCompression(); … … 121 156 } 122 157 } 158 159 public static void removeSerializers() { 160 serializer = null; 161 kryoSerializer = null; 162 javaSerializer = null; 163 gsonSerializer = null; 164 } 123 165 }
Note: See TracChangeset
for help on using the changeset viewer.