use of org.jumpmind.symmetric.model.NodeGroupLink in project symmetric-ds by JumpMind.
the class DataService method insertHeartbeatEvent.
/**
* Because we can't add a trigger on the _node table, we are artificially
* generating heartbeat events.
*
* @param node
*/
public void insertHeartbeatEvent(Node node, boolean isReload) {
ISqlTransaction transaction = null;
try {
transaction = sqlTemplate.startSqlTransaction();
String tableName = TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE_HOST);
List<NodeGroupLink> links = engine.getConfigurationService().getNodeGroupLinksFor(parameterService.getNodeGroupId(), false);
for (NodeGroupLink nodeGroupLink : links) {
if (nodeGroupLink.getDataEventAction() == NodeGroupLinkAction.P) {
Set<TriggerRouter> triggerRouters = engine.getTriggerRouterService().getTriggerRouterForTableForCurrentNode(nodeGroupLink, null, null, tableName, false);
if (triggerRouters != null && triggerRouters.size() > 0) {
Data data = createData(transaction, triggerRouters.iterator().next().getTrigger(), String.format(" t.node_id = '%s'", node.getNodeId()));
if (data != null) {
insertData(transaction, data);
} else {
log.warn("Not generating data/data events for table {} " + "because a trigger or trigger hist is not created yet.", tableName);
}
} else {
log.warn("Not generating data/data events for table {} " + "because a trigger or trigger hist is not created yet.", tableName);
}
}
}
transaction.commit();
} catch (Error ex) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
} catch (RuntimeException ex) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
} finally {
close(transaction);
}
}
use of org.jumpmind.symmetric.model.NodeGroupLink in project symmetric-ds by JumpMind.
the class TransformService method readInCacheIfExpired.
private Map<NodeGroupLink, Map<TransformPoint, List<TransformTableNodeGroupLink>>> readInCacheIfExpired() {
// get the cache timeout
long cacheTimeoutInMs = parameterService.getLong(ParameterConstants.CACHE_TIMEOUT_TRANSFORM_IN_MS);
Map<NodeGroupLink, Map<TransformPoint, List<TransformTableNodeGroupLink>>> byByLinkByTransformPoint = transformsCacheByNodeGroupLinkByTransformPoint;
synchronized (this) {
if (System.currentTimeMillis() - lastCacheTimeInMs >= cacheTimeoutInMs || byByLinkByTransformPoint == null) {
byByLinkByTransformPoint = new HashMap<NodeGroupLink, Map<TransformPoint, List<TransformTableNodeGroupLink>>>(2);
List<TransformTableNodeGroupLink> transforms = getTransformTablesFromDB(true, true);
for (TransformTableNodeGroupLink transformTable : transforms) {
NodeGroupLink nodeGroupLink = transformTable.getNodeGroupLink();
Map<TransformPoint, List<TransformTableNodeGroupLink>> byTransformPoint = byByLinkByTransformPoint.get(nodeGroupLink);
if (byTransformPoint == null) {
byTransformPoint = new HashMap<TransformPoint, List<TransformTableNodeGroupLink>>(2);
byByLinkByTransformPoint.put(nodeGroupLink, byTransformPoint);
}
List<TransformTableNodeGroupLink> byTableName = byTransformPoint.get(transformTable.getTransformPoint());
if (byTableName == null) {
byTableName = new ArrayList<TransformTableNodeGroupLink>();
byTransformPoint.put(transformTable.getTransformPoint(), byTableName);
}
byTableName.add(transformTable);
}
lastCacheTimeInMs = System.currentTimeMillis();
this.transformsCacheByNodeGroupLinkByTransformPoint = byByLinkByTransformPoint;
}
}
return byByLinkByTransformPoint;
}
use of org.jumpmind.symmetric.model.NodeGroupLink in project symmetric-ds by JumpMind.
the class TransformService method findTransformsFor.
public List<TransformTableNodeGroupLink> findTransformsFor(String sourceNodeGroupId, String targetNodeGroupId, String table) {
NodeGroupLink nodeGroupLink = new NodeGroupLink(sourceNodeGroupId, targetNodeGroupId);
List<TransformTableNodeGroupLink> transformsForNodeGroupLink = findTransformsFor(nodeGroupLink);
if (!CollectionUtils.isEmpty(transformsForNodeGroupLink)) {
List<TransformTableNodeGroupLink> transforms = new ArrayList<TransformTableNodeGroupLink>();
for (TransformTableNodeGroupLink transform : transformsForNodeGroupLink) {
if (StringUtils.equalsIgnoreCase(table, transform.getSourceTableName())) {
transforms.add(transform);
}
}
if (!transforms.isEmpty()) {
return transforms;
}
}
return null;
}
use of org.jumpmind.symmetric.model.NodeGroupLink in project symmetric-ds by JumpMind.
the class TriggerRouterService method getConfigurationTablesTriggerRoutersForCurrentNode.
/**
* Create a list of {@link TriggerRouter} for the SymmetricDS tables that
* should have triggers created for them on the current node.
*/
protected List<TriggerRouter> getConfigurationTablesTriggerRoutersForCurrentNode(String sourceNodeGroupId) {
List<TriggerRouter> triggerRouters = new ArrayList<TriggerRouter>();
List<NodeGroupLink> links = configurationService.getNodeGroupLinksFor(sourceNodeGroupId, false);
for (NodeGroupLink nodeGroupLink : links) {
triggerRouters.addAll(buildTriggerRoutersForSymmetricTables(Version.version(), nodeGroupLink));
}
return triggerRouters;
}
use of org.jumpmind.symmetric.model.NodeGroupLink in project symmetric-ds by JumpMind.
the class ConfigurationChangedDataRouterTest method buildTestableRouter.
protected IDataRouter buildTestableRouter(final Node nodeThatIsRouting, final List<NodeGroupLink> links, final NetworkedNode root) {
IConfigurationService configService = mock(IConfigurationService.class);
when(configService.isMasterToMaster()).thenReturn(false);
ISymmetricEngine engine = mock(ISymmetricEngine.class);
when(engine.getConfigurationService()).thenReturn(configService);
when(engine.getTablePrefix()).thenReturn("sym");
ConfigurationChangedDataRouter router = new ConfigurationChangedDataRouter(engine) {
@Override
protected Node findIdentity() {
return nodeThatIsRouting;
}
@Override
protected List<NodeGroupLink> getNodeGroupLinksFromContext(SimpleRouterContext routingContext) {
return links;
}
@Override
protected NetworkedNode getRootNetworkNodeFromContext(SimpleRouterContext routingContext) {
return root;
}
};
return router;
}
Aggregations