Changeset 72 for trunk/src/main/java/omq/common/util
- Timestamp:
- 06/29/13 20:44:27 (11 years ago)
- Location:
- trunk/src/main/java/omq/common/util
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/main/java/omq/common/util/Serializer.java
r62 r72 4 4 import java.util.Properties; 5 5 6 import omq.common.event.Event;7 6 import omq.common.message.Request; 8 7 import omq.common.message.Response; … … 48 47 try { 49 48 String className = env.getProperty(ParameterQueue.SERIALIZER_NAME, Serializer.JAVA); 50 49 51 50 if (className == null || className.isEmpty()) { 52 51 throw new ClassNotFoundException("Class name is null or empty."); 53 52 } 54 53 55 54 serializer = getInstance(className); 56 55 } catch (Exception ex) { … … 62 61 } 63 62 64 public ISerializer getInstance(String type) throws SerializerException { 63 public ISerializer getInstance(String type) throws SerializerException { 65 64 if (KRYO.equals(type)) { 66 65 if (kryoSerializer == null) { … … 79 78 return javaSerializer; 80 79 } 81 80 82 81 throw new SerializerException("Serializer not found."); 83 82 } … … 148 147 } 149 148 150 public Event deserializeEvent(byte[] bytes) throws SerializerException {151 ISerializer instance = getInstance();152 153 Boolean enableCompression = getEnableCompression();154 if (enableCompression) {155 try {156 byte[] unZippedBytes = Zipper.unzip(bytes);157 return instance.deserializeEvent(unZippedBytes);158 } catch (IOException e) {159 throw new SerializerException(e.getMessage(), e);160 }161 } else {162 return instance.deserializeEvent(bytes);163 }164 }165 166 // public static void removeSerializers() {167 // logger.warn("Removing serializers");168 // serializer = null;169 // kryoSerializer = null;170 // javaSerializer = null;171 // gsonSerializer = null;172 // }173 149 } -
trunk/src/main/java/omq/common/util/Serializers/GsonImp.java
r50 r72 3 3 import java.util.List; 4 4 5 import omq.common.event.Event;6 5 import omq.common.message.Request; 7 6 import omq.common.message.Response; … … 75 74 } 76 75 77 @Override78 public Event deserializeEvent(byte[] bytes) throws SerializerException {79 try {80 String json = new String(bytes);81 82 JsonParser parser = new JsonParser();83 JsonObject jsonObj = parser.parse(json).getAsJsonObject();84 85 String type = jsonObj.get("type").getAsString();86 87 JsonElement jsonElement = jsonObj.get("event");88 Event event;89 90 event = (Event) gson.fromJson(jsonElement, Class.forName(type));91 92 return event;93 } catch (Exception e) {94 throw new SerializerException("Deserialize event", e.getCause());95 }96 }97 98 76 } -
trunk/src/main/java/omq/common/util/Serializers/ISerializer.java
r44 r72 1 1 package omq.common.util.Serializers; 2 2 3 import omq.common.event.Event;4 3 import omq.common.message.Request; 5 4 import omq.common.message.Response; … … 18 17 19 18 public Response deserializeResponse(byte[] bytes, Class<?> type) throws SerializerException; 20 21 public Event deserializeEvent(byte[] bytes) throws SerializerException;22 19 } -
trunk/src/main/java/omq/common/util/Serializers/JavaImp.java
r44 r72 6 6 import java.io.ObjectOutputStream; 7 7 8 import omq.common.event.Event;9 import omq.common.event.EventWrapper;10 8 import omq.common.message.Request; 11 9 import omq.common.message.Response; … … 51 49 } 52 50 53 @Override54 public Event deserializeEvent(byte[] bytes) throws SerializerException {55 EventWrapper wrapper = (EventWrapper) deserializeObject(bytes);56 return wrapper.getEvent();57 }58 59 51 public Object deserializeObject(byte[] bytes) throws SerializerException { 60 52 try { -
trunk/src/main/java/omq/common/util/Serializers/KryoImp.java
r44 r72 3 3 import java.io.ByteArrayOutputStream; 4 4 5 import com.esotericsoftware.kryo.Kryo;6 import com.esotericsoftware.kryo.io.Input;7 import com.esotericsoftware.kryo.io.Output;8 9 import omq.common.event.Event;10 import omq.common.event.EventWrapper;11 5 import omq.common.message.Request; 12 6 import omq.common.message.Response; 13 7 import omq.exception.SerializerException; 14 8 import omq.server.RemoteObject; 9 10 import com.esotericsoftware.kryo.Kryo; 11 import com.esotericsoftware.kryo.io.Input; 12 import com.esotericsoftware.kryo.io.Output; 15 13 16 14 /** … … 53 51 } 54 52 55 @Override56 public Event deserializeEvent(byte[] bytes) throws SerializerException {57 EventWrapper wrapper = (EventWrapper) deserializeObject(bytes, EventWrapper.class);58 return wrapper.getEvent();59 }60 61 53 public Object deserializeObject(byte[] bytes, Class<?> type) throws SerializerException { 62 54 try {
Note: See TracChangeset
for help on using the changeset viewer.