Search in sources :

Example 6 with Property

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);
                }
            }
        }
    }
}
Also used : ObservableList(com.canoo.platform.remoting.ObservableList) Property(com.canoo.platform.remoting.Property)

Example 7 with Property

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;
}
Also used : JsonArray(com.google.gson.JsonArray) Field(java.lang.reflect.Field) JsonPrimitive(com.google.gson.JsonPrimitive) ObservableList(com.canoo.platform.remoting.ObservableList) JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) Property(com.canoo.platform.remoting.Property)

Example 8 with Property

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);
        }
    }
}
Also used : ObservableList(com.canoo.platform.remoting.ObservableList) Property(com.canoo.platform.remoting.Property)

Example 9 with Property

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);
                }
            }
        }
    }
}
Also used : ObservableList(com.canoo.platform.remoting.ObservableList) Property(com.canoo.platform.remoting.Property)

Example 10 with Property

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;
}
Also used : Field(java.lang.reflect.Field) IdentitySet(com.canoo.dp.impl.platform.core.IdentitySet) Property(com.canoo.platform.remoting.Property)

Aggregations

Property (com.canoo.platform.remoting.Property)15 ObservableList (com.canoo.platform.remoting.ObservableList)11 Binding (com.canoo.platform.core.functional.Binding)8 BidirectionalConverter (com.canoo.platform.remoting.client.javafx.BidirectionalConverter)8 DefaultBidirectionalConverter (com.canoo.dp.impl.client.javafx.DefaultBidirectionalConverter)5 MockedProperty (com.canoo.dp.impl.remoting.MockedProperty)5 ObservableArrayList (com.canoo.dp.impl.remoting.collections.ObservableArrayList)5 Converter (com.canoo.platform.remoting.client.javafx.Converter)5 FXBinder (com.canoo.platform.remoting.client.javafx.FXBinder)5 ArrayList (java.util.ArrayList)5 Arrays (java.util.Arrays)5 List (java.util.List)5 BooleanProperty (javafx.beans.property.BooleanProperty)5 DoubleProperty (javafx.beans.property.DoubleProperty)5 IntegerProperty (javafx.beans.property.IntegerProperty)5 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)5 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)5 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)5 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)5 StringProperty (javafx.beans.property.StringProperty)5