Skip to content

Commit

Permalink
Recognize "services.timeout".
Browse files Browse the repository at this point in the history
  • Loading branch information
Kami committed Feb 24, 2013
1 parent 2cb1214 commit ad7a982
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -65,7 +62,6 @@ private List<BaseEvent> parseEvents(List<Event> events) throws Exception {
List<BaseEvent> result = new ArrayList<BaseEvent>();

EventPayload payload;
Service service;
String configurationValueId;
ConfigurationValue oldValue, newValue;

Expand All @@ -83,10 +79,17 @@ private List<BaseEvent> parseEvents(List<Event> events) throws Exception {

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);
Expand All @@ -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) {

Expand All @@ -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;
Expand Down
Expand Up @@ -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());
}
}
Expand Up @@ -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());
}
}
Expand Up @@ -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;
Expand Down

0 comments on commit ad7a982

Please sign in to comment.