public void attach(ContainerLifeCycle container) { for (LifeCycle object : managedObjects) { container.addBean(object); } container.addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener() { @Override public void lifeCycleStarting(LifeCycle event) { LOGGER.debug("managed objects = {}", managedObjects); } }); for (LifeCycle.Listener listener : lifecycleListeners) { container.addLifeCycleListener(listener); } }
public void setBeans(Collection<Object> beans) { for (Object bean : beans) addBean(bean); }
/** * Adds the given bean, explicitly managing it or not. * * @param o The bean object to add * @param managed whether to managed the lifecycle of the bean * @return true if the bean was added, false if it was already present */ @Override public boolean addBean(Object o, boolean managed) { if (o instanceof LifeCycle) return addBean(o,managed?Managed.MANAGED:Managed.UNMANAGED); return addBean(o,managed?Managed.POJO:Managed.UNMANAGED); }
/** * Adds the given bean, detecting whether to manage it or not. * If the bean is a {@link LifeCycle}, then it will be managed if it is not * already started and not managed if it is already started. * The {@link #addBean(Object, boolean)} * method should be used if this is not correct, or the {@link #manage(Object)} and {@link #unmanage(Object)} * methods may be used after an add to change the status. * * @param o the bean object to add * @return true if the bean was added, false if it was already present */ @Override public boolean addBean(Object o) { if (o instanceof LifeCycle) { LifeCycle l = (LifeCycle)o; return addBean(o,l.isRunning()?Managed.UNMANAGED:Managed.AUTO); } return addBean(o,Managed.POJO); }
public void updateBean(Object oldBean, final Object newBean) { if (newBean!=oldBean) { if (oldBean!=null) removeBean(oldBean); if (newBean!=null) addBean(newBean); } }
public void updateBean(Object oldBean, final Object newBean, boolean managed) { if (newBean!=oldBean) { if (oldBean!=null) removeBean(oldBean); if (newBean!=null) addBean(newBean,managed); } }
continue loop; addBean(n);
@Override public void addEventListener(Container.Listener listener) { if (_listeners.contains(listener)) return; _listeners.add(listener); // tell it about existing beans for (Bean b:_beans) { listener.beanAdded(this,b._bean); // handle inheritance if (listener instanceof InheritedListener && b.isManaged() && b._bean instanceof Container) { if (b._bean instanceof ContainerLifeCycle) ((ContainerLifeCycle)b._bean).addBean(listener, false); else ((Container)b._bean).addBean(listener); } } }
/** * Adds a managed lifecycle. * <p>This is a convenience method that uses addBean(lifecycle,true) * and then ensures that the added bean is started iff this container * is running. Exception from nested calls to start are caught and * wrapped as RuntimeExceptions * @param lifecycle the managed lifecycle to add */ public void addManaged(LifeCycle lifecycle) { addBean(lifecycle,true); try { if (isRunning() && !lifecycle.isRunning()) start(lifecycle); } catch (RuntimeException | Error e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
private void manage(Bean bean) { if (bean._managed!=Managed.MANAGED) { bean._managed=Managed.MANAGED; if (bean._bean instanceof Container) { for (Container.Listener l:_listeners) { if (l instanceof InheritedListener) { if (bean._bean instanceof ContainerLifeCycle) ((ContainerLifeCycle)bean._bean).addBean(l,false); else ((Container)bean._bean).addBean(l); } } } if (bean._bean instanceof AbstractLifeCycle) { ((AbstractLifeCycle)bean._bean).setStopTimeout(getStopTimeout()); } } }
public void setBeans(Collection<Object> beans) { for (Object bean : beans) addBean(bean); }
public void setBeans(Collection<Object> beans) { for (Object bean : beans) addBean(bean); }
/** * Adds the given bean, explicitly managing it or not. * * @param o The bean object to add * @param managed whether to managed the lifecycle of the bean * @return true if the bean was added, false if it was already present */ public boolean addBean(Object o, boolean managed) { if (o instanceof LifeCycle) return addBean(o,managed?Managed.MANAGED:Managed.UNMANAGED); return addBean(o,managed?Managed.POJO:Managed.UNMANAGED); }
public void setBeans(Collection<Object> beans) { for (Object bean : beans) addBean(bean); }
public void setBeans(Collection<Object> beans) { for (Object bean : beans) addBean(bean); }
public void updateBean(Object oldBean, final Object newBean) { if (newBean!=oldBean) { if (oldBean!=null) removeBean(oldBean); if (newBean!=null) addBean(newBean); } }
public void updateBean(Object oldBean, final Object newBean) { if (newBean!=oldBean) { if (oldBean!=null) removeBean(oldBean); if (newBean!=null) addBean(newBean); } }
public void updateBean(Object oldBean, final Object newBean, boolean managed) { if (newBean!=oldBean) { if (oldBean!=null) removeBean(oldBean); if (newBean!=null) addBean(newBean,managed); } }
public void updateBean(Object oldBean, final Object newBean) { if (newBean!=oldBean) { if (oldBean!=null) removeBean(oldBean); if (newBean!=null) addBean(newBean); } }
public void updateBean(Object oldBean, final Object newBean) { if (newBean!=oldBean) { if (oldBean!=null) removeBean(oldBean); if (newBean!=null) addBean(newBean); } }