Search in sources :

Example 1 with TargetBeanProcess

use of com.revolsys.spring.TargetBeanProcess 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)

Example 2 with TargetBeanProcess

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

the class ProcessNetwork method start.

private synchronized void start(final Process process) {
    if (this.parent == null) {
        if (this.processes != null) {
            Thread thread = this.processes.get(process);
            if (thread == null) {
                final Process runProcess;
                if (process instanceof TargetBeanProcess) {
                    final TargetBeanProcess targetBeanProcess = (TargetBeanProcess) process;
                    runProcess = targetBeanProcess.getProcess();
                    this.processes.remove(process);
                } else {
                    runProcess = process;
                }
                final Runnable runnable = new ProcessRunnable(this, runProcess);
                final String name = runProcess.toString();
                final Runnable appenderRunnable = new ThreadLocalAppenderRunnable(runnable);
                thread = new Thread(this.threadGroup, appenderRunnable, name);
                this.processes.put(runProcess, thread);
                if (!thread.isAlive()) {
                    thread.start();
                    this.count++;
                }
            }
        }
    }
}
Also used : TargetBeanProcess(com.revolsys.spring.TargetBeanProcess) ThreadLocalAppenderRunnable(com.revolsys.logging.log4j.ThreadLocalAppenderRunnable) ThreadLocalAppenderRunnable(com.revolsys.logging.log4j.ThreadLocalAppenderRunnable) TargetBeanProcess(com.revolsys.spring.TargetBeanProcess)

Aggregations

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