use of com.canoo.platform.remoting.Property in project dolphin-platform by canoo.
the class GarbageCollector method removeFromGC.
private void removeFromGC(Instance instance) {
LOG.trace("Bean of type {} removed from GC and will not be removed on next GC run", instance.getBean().getClass());
Object removed = removeOnGC.remove(instance);
LOG.trace("GC will remove {} beans at next GC run", removeOnGC.size());
if (removed != null) {
for (Property property : instance.getProperties()) {
Object value = property.get();
if (value != null && DolphinUtils.isDolphinBean(value.getClass())) {
Instance childInstance = getInstance(value);
removeFromGC(childInstance);
}
}
for (ObservableList list : instance.getLists()) {
for (Object value : list) {
if (value != null && DolphinUtils.isDolphinBean(value.getClass())) {
Instance childInstance = getInstance(value);
removeFromGC(childInstance);
}
}
}
}
}
use of com.canoo.platform.remoting.Property in project dolphin-platform by canoo.
the class ModelJsonSerializer method toJson.
public static JsonObject toJson(Object dolphinModel) {
if (dolphinModel == null) {
return null;
}
JsonObject jsonObject = new JsonObject();
for (Field field : ReflectionHelper.getInheritedDeclaredFields(dolphinModel.getClass())) {
if (DolphinUtils.isProperty(field.getType())) {
Property property = (Property) ReflectionHelper.getPrivileged(field, dolphinModel);
Object value = property.get();
if (value == null) {
jsonObject.add(field.getName(), null);
} else if (Number.class.isAssignableFrom(value.getClass()) || Double.TYPE.isAssignableFrom(value.getClass()) || Float.TYPE.isAssignableFrom(value.getClass()) || Long.TYPE.isAssignableFrom(value.getClass()) || Integer.TYPE.isAssignableFrom(value.getClass())) {
jsonObject.add(field.getName(), new JsonPrimitive((Number) value));
} else if (String.class.isAssignableFrom(value.getClass())) {
jsonObject.add(field.getName(), new JsonPrimitive((String) value));
} else if (Boolean.class.isAssignableFrom(value.getClass()) || Boolean.TYPE.isAssignableFrom(value.getClass())) {
jsonObject.add(field.getName(), new JsonPrimitive((Boolean) value));
} else {
jsonObject.add(field.getName(), toJson(value));
}
} else if (DolphinUtils.isObservableList(field.getType())) {
ObservableList list = (ObservableList) ReflectionHelper.getPrivileged(field, dolphinModel);
JsonArray jsonArray = new JsonArray();
for (Object value : list) {
if (value == null) {
// TODO
// jsonArray.add(null);
} else if (Number.class.isAssignableFrom(value.getClass()) || Double.TYPE.isAssignableFrom(value.getClass()) || Float.TYPE.isAssignableFrom(value.getClass()) || Long.TYPE.isAssignableFrom(value.getClass()) || Integer.TYPE.isAssignableFrom(value.getClass())) {
jsonArray.add(new JsonPrimitive((Number) value));
} else if (String.class.isAssignableFrom(value.getClass())) {
jsonArray.add(new JsonPrimitive((String) value));
} else if (Boolean.class.isAssignableFrom(value.getClass()) || Boolean.TYPE.isAssignableFrom(value.getClass())) {
jsonArray.add(new JsonPrimitive((Boolean) value));
} else {
jsonArray.add(toJson(value));
}
}
jsonObject.add(field.getName(), jsonArray);
}
}
return jsonObject;
}
use of com.canoo.platform.remoting.Property in project dolphin-platform by canoo.
the class GarbageCollector method onBeanRemoved.
public synchronized void onBeanRemoved(Object bean) {
if (!configuration.isUseGc()) {
return;
}
Assert.requireNonNull(bean, "bean");
if (!allInstances.containsKey(bean)) {
throw new IllegalArgumentException("Bean is not managed by GC");
}
Instance instance = allInstances.remove(bean);
removeOnGC.remove(instance);
IdentitySet<Property> properties = getAllProperties(bean);
IdentitySet<ObservableList> lists = getAllLists(bean);
for (Property property : properties) {
propertyToParent.remove(property);
removeReferenceAndCheckForGC(property, property.get());
}
for (ObservableList list : lists) {
listToParent.remove(list);
for (Object item : list) {
removeReferenceAndCheckForGC(list, item);
}
}
}
use of com.canoo.platform.remoting.Property in project dolphin-platform by canoo.
the class GarbageCollector method addToGC.
private void addToGC(Instance instance, Object value) {
LOG.trace("Bean of type {} added to GC and will be removed on next GC run", value.getClass());
removeOnGC.put(instance, value);
LOG.trace("GC will remove {} beans at next GC run", removeOnGC.size());
for (Property property : instance.getProperties()) {
Object propertyValue = property.get();
if (propertyValue != null && DolphinUtils.isDolphinBean(propertyValue.getClass())) {
Instance childInstance = getInstance(propertyValue);
if (!childInstance.isReferencedByRoot()) {
addToGC(childInstance, propertyValue);
}
}
}
for (ObservableList list : instance.getLists()) {
for (Object listValue : list) {
if (listValue != null && DolphinUtils.isDolphinBean(listValue.getClass())) {
Instance childInstance = getInstance(listValue);
if (!childInstance.isReferencedByRoot()) {
addToGC(childInstance, listValue);
}
}
}
}
}
use of com.canoo.platform.remoting.Property in project dolphin-platform by canoo.
the class GarbageCollector method getAllProperties.
private IdentitySet<Property> getAllProperties(Object bean) {
IdentitySet<Property> ret = new IdentitySet<>();
List<Field> fields = propertyFieldCache.get(bean.getClass());
if (fields == null) {
fields = new ArrayList<>();
for (Field field : ReflectionHelper.getInheritedDeclaredFields(bean.getClass())) {
if (Property.class.isAssignableFrom(field.getType())) {
fields.add(field);
}
}
propertyFieldCache.put(bean.getClass(), fields);
}
for (Field field : fields) {
ret.add((Property) ReflectionHelper.getPrivileged(field, bean));
}
return ret;
}
Aggregations