Search in sources :

Example 1 with TargetBeanFactoryBean

use of com.revolsys.spring.TargetBeanFactoryBean in project com.revolsys.open by revolsys.

the class SpringProcessNetwork method postProcessAfterInitialization.

@Override
public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException {
    final ProcessNetwork parent = getParent();
    if (parent == null) {
        if (bean instanceof TargetBeanFactoryBean) {
            final TargetBeanFactoryBean targetBean = (TargetBeanFactoryBean) bean;
            final Class<?> targetClass = targetBean.getObjectType();
            if (Process.class.isAssignableFrom(targetClass)) {
                try {
                    final Process process = new TargetBeanProcess(targetBean);
                    addProcess(process);
                } catch (final Exception e) {
                    Logs.error(this, "Unable to create process for bean " + beanName, e);
                }
            }
        } else if (bean instanceof Process) {
            final Map<Process, Thread> processes = getProcessMap();
            final Process process = (Process) bean;
            // threads aren't created
            if (processes != null) {
                for (final Entry<Process, Thread> entry : processes.entrySet()) {
                    final Process otherProcess = entry.getKey();
                    if (otherProcess instanceof TargetBeanProcess) {
                        final TargetBeanProcess targetProcessBean = (TargetBeanProcess) otherProcess;
                        if (targetProcessBean.isInstanceCreated()) {
                            final Process targetProcess = targetProcessBean.getProcess();
                            if (targetProcess == process) {
                                synchronized (getSync()) {
                                    final Thread thread = entry.getValue();
                                    processes.put(targetProcess, thread);
                                    processes.remove(otherProcess);
                                    return bean;
                                }
                            }
                        }
                    }
                }
            }
            addProcess(process);
        }
    } else if (parent instanceof SpringProcessNetwork) {
        final SpringProcessNetwork parentProcessNetwork = (SpringProcessNetwork) parent;
        parentProcessNetwork.postProcessAfterInitialization(bean, beanName);
    }
    return bean;
}
Also used : Entry(java.util.Map.Entry) TargetBeanProcess(com.revolsys.spring.TargetBeanProcess) TargetBeanFactoryBean(com.revolsys.spring.TargetBeanFactoryBean) TargetBeanProcess(com.revolsys.spring.TargetBeanProcess) Map(java.util.Map) BeansException(org.springframework.beans.BeansException)

Aggregations

TargetBeanFactoryBean (com.revolsys.spring.TargetBeanFactoryBean)1 TargetBeanProcess (com.revolsys.spring.TargetBeanProcess)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 BeansException (org.springframework.beans.BeansException)1