Ignore:
Timestamp:
06/29/13 20:44:27 (11 years ago)
Author:
stoda
Message:

Events deleted instead of them there's a new example of how to use the observer pattern

Location:
trunk/src/main/java/omq/common/util/Serializers
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/main/java/omq/common/util/Serializers/GsonImp.java

    r50 r72  
    33import java.util.List;
    44
    5 import omq.common.event.Event;
    65import omq.common.message.Request;
    76import omq.common.message.Response;
     
    7574        }
    7675
    77         @Override
    78         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 
    9876}
  • trunk/src/main/java/omq/common/util/Serializers/ISerializer.java

    r44 r72  
    11package omq.common.util.Serializers;
    22
    3 import omq.common.event.Event;
    43import omq.common.message.Request;
    54import omq.common.message.Response;
     
    1817
    1918        public Response deserializeResponse(byte[] bytes, Class<?> type) throws SerializerException;
    20 
    21         public Event deserializeEvent(byte[] bytes) throws SerializerException;
    2219}
  • trunk/src/main/java/omq/common/util/Serializers/JavaImp.java

    r44 r72  
    66import java.io.ObjectOutputStream;
    77
    8 import omq.common.event.Event;
    9 import omq.common.event.EventWrapper;
    108import omq.common.message.Request;
    119import omq.common.message.Response;
     
    5149        }
    5250
    53         @Override
    54         public Event deserializeEvent(byte[] bytes) throws SerializerException {
    55                 EventWrapper wrapper = (EventWrapper) deserializeObject(bytes);
    56                 return wrapper.getEvent();
    57         }
    58 
    5951        public Object deserializeObject(byte[] bytes) throws SerializerException {
    6052                try {
  • trunk/src/main/java/omq/common/util/Serializers/KryoImp.java

    r44 r72  
    33import java.io.ByteArrayOutputStream;
    44
    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;
    115import omq.common.message.Request;
    126import omq.common.message.Response;
    137import omq.exception.SerializerException;
    148import omq.server.RemoteObject;
     9
     10import com.esotericsoftware.kryo.Kryo;
     11import com.esotericsoftware.kryo.io.Input;
     12import com.esotericsoftware.kryo.io.Output;
    1513
    1614/**
     
    5351        }
    5452
    55         @Override
    56         public Event deserializeEvent(byte[] bytes) throws SerializerException {
    57                 EventWrapper wrapper = (EventWrapper) deserializeObject(bytes, EventWrapper.class);
    58                 return wrapper.getEvent();
    59         }
    60 
    6153        public Object deserializeObject(byte[] bytes, Class<?> type) throws SerializerException {
    6254                try {
Note: See TracChangeset for help on using the changeset viewer.