Skip to content

Commit

Permalink
Turn post processor back on
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Mar 15, 2010
1 parent 4b92cd5 commit 908fc94
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 46 deletions.
Expand Up @@ -55,19 +55,20 @@
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;

/**
* This manager registers
* {@link IExtensionPoint}s defined both by SymmetricDS and others found in the
* {@link ApplicationContext}.
* This manager registers {@link IExtensionPoint}s defined both by SymmetricDS
* and others found in the {@link ApplicationContext}.
* <P>
* SymmetricDS reads in any Spring XML file found in the classpath of the
* application that matches the following pattern:
* /META-INF/services/symmetric-*-ext.xml
*/
public class ExtensionPointManager implements IExtensionPointManager, BeanFactoryAware {
public class ExtensionPointManager implements IExtensionPointManager, BeanFactoryAware,
BeanFactoryPostProcessor {

final ILog log = LogFactory.getLog(getClass());

Expand All @@ -82,60 +83,73 @@ public class ExtensionPointManager implements IExtensionPointManager, BeanFactor
private INodeService nodeService;

private IAcknowledgeService acknowledgeService;

private List<IOfflineDetectorService> offlineDetectorServices;

private IRegistrationService registrationService;

private ITriggerRouterService triggerRouterService;

private ITransportManager transportManager;

private IRouterService routingService;

private BeanFactory beanFactory;

private boolean initialized = false;

private boolean postProcessEnabled = true;

public void register() throws BeansException {
ConfigurableListableBeanFactory cfgBeanFactory = (ConfigurableListableBeanFactory)beanFactory;
Map<String, IExtensionPoint> extensions = new TreeMap<String, IExtensionPoint>();
extensions.putAll(cfgBeanFactory.getBeansOfType(IExtensionPoint.class));
if (cfgBeanFactory.getParentBeanFactory() != null
&& cfgBeanFactory.getParentBeanFactory() instanceof ListableBeanFactory) {
extensions.putAll(((ListableBeanFactory) cfgBeanFactory.getParentBeanFactory())
.getBeansOfType(IExtensionPoint.class));
}
for (String beanName : extensions.keySet()) {
IExtensionPoint ext = extensions.get(beanName);
if (ext.isAutoRegister()) {
boolean registerExtension = false;
if (ext instanceof INodeGroupExtensionPoint) {
String nodeGroupId = parameterService.getNodeGroupId();
INodeGroupExtensionPoint nodeExt = (INodeGroupExtensionPoint) ext;
String[] ids = nodeExt.getNodeGroupIdsToApplyTo();
if (ids != null) {
for (String targetNodeGroupId : ids) {
if (nodeGroupId.equals(targetNodeGroupId)) {
registerExtension = true;
this.postProcessEnabled = true;
ConfigurableListableBeanFactory cfgBeanFactory = (ConfigurableListableBeanFactory) beanFactory;
this.postProcessBeanFactory(cfgBeanFactory);
}

public void postProcessBeanFactory(ConfigurableListableBeanFactory cfgBeanFactory)
throws BeansException {
if (!initialized && postProcessEnabled) {
Map<String, IExtensionPoint> extensions = new TreeMap<String, IExtensionPoint>();
extensions.putAll(cfgBeanFactory.getBeansOfType(IExtensionPoint.class));
if (cfgBeanFactory.getParentBeanFactory() != null
&& cfgBeanFactory.getParentBeanFactory() instanceof ListableBeanFactory) {
extensions.putAll(((ListableBeanFactory) cfgBeanFactory.getParentBeanFactory())
.getBeansOfType(IExtensionPoint.class));
}
for (String beanName : extensions.keySet()) {
IExtensionPoint ext = extensions.get(beanName);
if (ext.isAutoRegister()) {
boolean registerExtension = false;
if (ext instanceof INodeGroupExtensionPoint) {
String nodeGroupId = parameterService.getNodeGroupId();
INodeGroupExtensionPoint nodeExt = (INodeGroupExtensionPoint) ext;
String[] ids = nodeExt.getNodeGroupIdsToApplyTo();
if (ids != null) {
for (String targetNodeGroupId : ids) {
if (nodeGroupId.equals(targetNodeGroupId)) {
registerExtension = true;
}
}
} else {
registerExtension = true;
}
} else {
registerExtension = true;
}
} else {
registerExtension = true;
}

if (registerExtension) {
registerExtension(beanName, ext);
if (registerExtension) {
registerExtension(beanName, ext);
}
}
}
this.initialized = true;
}

}

private void registerExtension(String beanName, IExtensionPoint ext) {

log.debug("ExtensionRegistering", beanName, ext.getClass().getSimpleName());
log.info("ExtensionRegistering", beanName, ext.getClass().getSimpleName());

if (ext instanceof ISyncUrlExtension) {
transportManager.addExtensionSyncUrlHandler(beanName, (ISyncUrlExtension) ext);
Expand All @@ -157,9 +171,9 @@ private void registerExtension(String beanName, IExtensionPoint ext) {
if (ext instanceof IBatchListener) {
dataLoaderService.addBatchListener((IBatchListener) ext);
}

if (ext instanceof IHeartbeatListener) {
dataService.addHeartbeatListener((IHeartbeatListener)ext);
dataService.addHeartbeatListener((IHeartbeatListener) ext);
}

if (ext instanceof IDataLoaderFilter) {
Expand All @@ -177,8 +191,9 @@ private void registerExtension(String beanName, IExtensionPoint ext) {
}

} else {
throw new UnsupportedOperationException("IColumnFilter cannot be auto registered. Please use "
+ ITableColumnFilter.class.getName() + " instead.");
throw new UnsupportedOperationException(
"IColumnFilter cannot be auto registered. Please use "
+ ITableColumnFilter.class.getName() + " instead.");
}
}

Expand All @@ -205,15 +220,15 @@ private void registerExtension(String beanName, IExtensionPoint ext) {
if (ext instanceof IBatchAlgorithm) {
routingService.addBatchAlgorithm(beanName, (IBatchAlgorithm) ext);
}

if (ext instanceof IOfflineClientListener) {
for(IOfflineDetectorService service : offlineDetectorServices) {
service.addOfflineListener((IOfflineClientListener)ext);
for (IOfflineDetectorService service : offlineDetectorServices) {
service.addOfflineListener((IOfflineClientListener) ext);
}
}

if (ext instanceof IOfflineServerListener) {
nodeService.addOfflineServerListener((IOfflineServerListener)ext);
nodeService.addOfflineServerListener((IOfflineServerListener) ext);
}
}

Expand Down Expand Up @@ -252,16 +267,20 @@ public void setTransportManager(ITransportManager transportManager) {
public void setRoutingService(IRouterService routingService) {
this.routingService = routingService;
}

public void setTriggerRouterService(ITriggerRouterService triggerService) {
this.triggerRouterService = triggerService;
}

public void setOfflineDetectorServices(List<IOfflineDetectorService> offlineDetectorServices) {
this.offlineDetectorServices = offlineDetectorServices;
}

public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
this.beanFactory = beanFactory;
}

public void setPostProcessEnabled(boolean postProcessEnabled) {
this.postProcessEnabled = postProcessEnabled;
}
}
1 change: 1 addition & 0 deletions symmetric/src/main/resources/symmetric-extensions.xml
Expand Up @@ -6,6 +6,7 @@
<import resource="file:../conf/*-extensions.xml" />

<bean id="extensionManager" class="org.jumpmind.symmetric.ext.ExtensionPointManager">
<property name="postProcessEnabled" value="true"/>
<property name="dataLoaderService" ref="dataLoaderService" />
<property name="dataService" ref="dataService" />
<property name="dataExtractorService" ref="dataExtractorService" />
Expand Down

0 comments on commit 908fc94

Please sign in to comment.