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);
}
}
}
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);
}
}
}
}
}
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);
}
}
Aggregations