use of io.s4.collector.EventWrapper in project core by s4.
the class GenericJsonClientStub method eventWrapperFromBytes.
@Override
public EventWrapper eventWrapperFromBytes(byte[] v) {
try {
// interpret v as a JSON string
String s = new String(v, Charset.forName("UTF8"));
JSONObject json = new JSONObject(s);
String streamName = json.getString("stream");
String className = json.getString("class");
Class<?> clazz;
try {
clazz = Class.forName(className);
} catch (ClassNotFoundException e) {
throw new ObjectBuilder.Exception("bad class name for json-encoded object: " + className, e);
}
String[] keyNames = null;
JSONArray keyArray = json.optJSONArray("keys");
if (keyArray != null) {
keyNames = new String[keyArray.length()];
for (int i = 0; i < keyNames.length; ++i) {
keyNames[i] = keyArray.optString(i);
}
}
String jevent = json.getString("object");
Object obj = GsonUtil.get().fromJson(jevent, clazz);
return new EventWrapper(streamName, keyNames, obj);
} catch (JSONException e) {
logger.error("problem with event JSON", e);
} catch (ObjectBuilder.Exception e) {
logger.error("failed to build object from JSON", e);
}
return null;
}
use of io.s4.collector.EventWrapper in project core by s4.
the class EventClock method update.
public void update(EventWrapper eventWrapper) {
long eventTime = -1;
String streamName = eventWrapper.getStreamName();
String fieldName = eventClockStreamsMap.get(streamName);
if (fieldName != null) {
Object event = eventWrapper.getEvent();
Schema schema = schemaContainer.getSchema(event.getClass());
Property property = schema.getProperties().get(fieldName);
if (property != null && (property.getType().equals(Long.TYPE) || property.getType().equals(Long.class))) {
try {
eventTime = (Long) property.getGetterMethod().invoke(event);
updateTime(eventTime);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
Aggregations