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