Permalink
Browse files

Recognize "services.timeout".

  • Loading branch information...
1 parent 2cb1214 commit ad7a9826d57406cf05c9586c9f97c494ca44a80a @Kami Kami committed Feb 24, 2013
@@ -18,11 +18,8 @@
package com.rackspacecloud.client.service_registry.clients;
import com.google.gson.reflect.TypeToken;
+import com.rackspacecloud.client.service_registry.events.server.*;
import com.rackspacecloud.client.service_registry.objects.*;
-import com.rackspacecloud.client.service_registry.events.server.BaseEvent;
-import com.rackspacecloud.client.service_registry.events.server.ConfigurationValueRemovedEvent;
-import com.rackspacecloud.client.service_registry.events.server.ConfigurationValueUpdatedEvent;
-import com.rackspacecloud.client.service_registry.events.server.ServiceJoinEvent;
import org.apache.http.client.methods.HttpGet;
import com.rackspacecloud.client.service_registry.ClientResponse;
import com.rackspacecloud.client.service_registry.containers.EventsContainer;
@@ -65,7 +62,6 @@ public EventsClient(AuthClient authClient) {
List<BaseEvent> result = new ArrayList<BaseEvent>();
EventPayload payload;
- Service service;
String configurationValueId;
ConfigurationValue oldValue, newValue;
@@ -83,10 +79,17 @@ public EventsClient(AuthClient authClient) {
if (type.compareTo("service.join") == 0) {
ServiceJoinEventPayload eventPayload = ((ServiceJoinEventPayload)payload);
+
event = new ServiceJoinEvent(eventPayload.getService());
+ result.add(event);
}
else if (type.compareTo("services.timeout") == 0) {
+ ServicesTimeoutEventPayload eventPayload = ((ServicesTimeoutEventPayload)payload);
+ for (Service service : eventPayload.getServices()) {
+ event = new ServiceTimeoutEvent(service);
+ result.add(event);
+ }
}
else if (type.compareTo("configuration_value.update") == 0) {
ConfigurationValueUpdatedEventPayload eventPayload = ((ConfigurationValueUpdatedEventPayload)payload);
@@ -96,6 +99,7 @@ else if (type.compareTo("configuration_value.update") == 0) {
newValue = new ConfigurationValue(configurationValueId,eventPayload.getNewValue());
event = new ConfigurationValueUpdatedEvent(oldValue, newValue);
+ result.add(event);
}
else if (type.compareTo("configuration_value.remove") == 0) {
@@ -105,9 +109,8 @@ else if (type.compareTo("configuration_value.remove") == 0) {
oldValue = (eventPayload.getOldValue() == null) ? null : new ConfigurationValue(configurationValueId, eventPayload.getOldValue());
event = new ConfigurationValueRemovedEvent(oldValue);
+ result.add(event);
}
-
- result.add(event);
}
return result;
@@ -12,4 +12,9 @@ public ServiceJoinEvent(Service service) {
public Service getService() {
return service;
}
+
+ @Override
+ public String toString() {
+ return String.format("[ServiceJoinEvent id=%s]", this.service.getId());
+ }
}
@@ -5,7 +5,16 @@
public class ServiceTimeoutEvent extends BaseEvent {
private Service service;
+ public ServiceTimeoutEvent(Service service) {
+ this.service = service;
+ }
+
public Service getService() {
return service;
}
+
+ @Override
+ public String toString() {
+ return String.format("[ServiceTimeoutEvent id=%s]", this.service.getId());
+ }
}
@@ -63,19 +63,17 @@ public EventPayload deserialize(JsonElement json, Type typeOfT, JsonDeserializat
}
else {
// service.join
- String id = jsonObject.get("id").getAsString();
- String sessionId = jsonObject.get("session_id").getAsString();
- List<String> tags = new Gson().fromJson(jsonObject.get("tags"), new TypeToken<List<String>>() {}.getType());
- Map<String, String> metadata = new Gson().fromJson(jsonObject.get("metadata"), new TypeToken<Map<String, String>>() {}.getType());
-
- Service service = new Service(id, sessionId, tags, metadata);
+ Service service = new Gson().fromJson(jsonObject, new TypeToken<Service>() {}.getType());
return new ServiceJoinEventPayload(service);
}
}
- else if (json.getClass().equals(JsonObject.class)) {
+ else if (json.getClass().equals(JsonArray.class)) {
// services.timeout
JsonArray jsonArray = json.getAsJsonArray();
- ArrayList<Service> services = new ArrayList<Service>();
+ ArrayList<Service> services = new Gson().fromJson(jsonArray, new TypeToken<ArrayList<Service>>() {}.getType());
+
+ System.out.println(services);
+ return new ServicesTimeoutEventPayload(services);
}
return null;

0 comments on commit ad7a982

Please sign in to comment.