Search in sources :

Example 6 with ObservableList

use of com.canoo.platform.remoting.ObservableList 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 7 with ObservableList

use of com.canoo.platform.remoting.ObservableList 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 8 with ObservableList

use of com.canoo.platform.remoting.ObservableList in project dolphin-platform by canoo.

the class GarbageCollector method onBeanCreated.

/**
 * This method must be called for each new Dolphin bean (see {@link RemotingBean}).
 * Normally beans are created by {@link BeanManager#create(Class)}
 *
 * @param bean     the bean that was created
 * @param rootBean if this is true the bean is handled as a root bean. This bean don't need a reference.
 */
public synchronized void onBeanCreated(Object bean, boolean rootBean) {
    if (!configuration.isUseGc()) {
        return;
    }
    Assert.requireNonNull(bean, "bean");
    if (allInstances.containsKey(bean)) {
        throw new IllegalArgumentException("Bean instance is already managed!");
    }
    IdentitySet<Property> properties = getAllProperties(bean);
    IdentitySet<ObservableList> lists = getAllLists(bean);
    Instance instance = new Instance(bean, rootBean, properties, lists);
    allInstances.put(bean, instance);
    for (Property property : properties) {
        propertyToParent.put(property, instance);
    }
    for (ObservableList list : lists) {
        listToParent.put(list, instance);
    }
    if (!rootBean) {
        // Until the bean isn't referenced in another bean it will be removed at gc
        addToGC(instance, bean);
    }
}
Also used : ObservableList(com.canoo.platform.remoting.ObservableList) Property(com.canoo.platform.remoting.Property)

Aggregations

ObservableList (com.canoo.platform.remoting.ObservableList)8 Property (com.canoo.platform.remoting.Property)6 Field (java.lang.reflect.Field)2 IdentityHashMap (java.util.IdentityHashMap)2 Assert (com.canoo.dp.impl.platform.core.Assert)1 IdentitySet (com.canoo.dp.impl.platform.core.IdentitySet)1 Binding (com.canoo.platform.core.functional.Binding)1 Subscription (com.canoo.platform.core.functional.Subscription)1 ListChangeEvent (com.canoo.platform.remoting.ListChangeEvent)1 JavaFXListBinder (com.canoo.platform.remoting.client.javafx.binding.JavaFXListBinder)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 Map (java.util.Map)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 ListChangeListener (javafx.collections.ListChangeListener)1 API (org.apiguardian.api.API)1 INTERNAL (org.apiguardian.api.API.Status.INTERNAL)1