use of org.jumpmind.symmetric.ISymmetricEngine in project symmetric-ds by JumpMind.
the class InternalTransportManager method getPushTransport.
@Override
public IOutgoingWithResponseTransport getPushTransport(final Node remote, final Node local, String securityToken, Map<String, String> requestProperties, String registrationUrl) throws IOException {
final PipedOutputStream pushOs = new PipedOutputStream();
final PipedInputStream pushIs = new PipedInputStream(pushOs);
final PipedOutputStream respOs = new PipedOutputStream();
final PipedInputStream respIs = new PipedInputStream(respOs);
runAtClient(remote.getSyncUrl(), pushIs, respOs, new IClientRunnable() {
public void run(ISymmetricEngine engine, InputStream is, OutputStream os) throws Exception {
// This should be basically what the push servlet does ...
engine.getDataLoaderService().loadDataFromPush(local, pushIs, respOs);
}
});
return new InternalOutgoingWithResponseTransport(pushOs, respIs);
}
use of org.jumpmind.symmetric.ISymmetricEngine in project symmetric-ds by JumpMind.
the class DataExtractorService method sendOutgoingBatch.
protected OutgoingBatch sendOutgoingBatch(ProcessInfo processInfo, Node targetNode, OutgoingBatch currentBatch, boolean isRetry, IDataWriter dataWriter, BufferedWriter writer, ExtractMode mode) {
if (currentBatch.getStatus() != Status.OK || ExtractMode.EXTRACT_ONLY == mode) {
currentBatch.setSentCount(currentBatch.getSentCount() + 1);
long ts = System.currentTimeMillis();
IStagedResource extractedBatch = getStagedResource(currentBatch);
if (extractedBatch != null) {
if (mode == ExtractMode.FOR_SYM_CLIENT && writer != null) {
if (!isRetry && parameterService.is(ParameterConstants.OUTGOING_BATCH_COPY_TO_INCOMING_STAGING) && !parameterService.is(ParameterConstants.NODE_OFFLINE, false)) {
ISymmetricEngine targetEngine = AbstractSymmetricEngine.findEngineByUrl(targetNode.getSyncUrl());
if (targetEngine != null && extractedBatch.isFileResource()) {
try {
Node sourceNode = nodeService.findIdentity();
IStagedResource targetResource = targetEngine.getStagingManager().create(Constants.STAGING_CATEGORY_INCOMING, Batch.getStagedLocation(false, sourceNode.getNodeId()), currentBatch.getBatchId());
SymmetricUtils.copyFile(extractedBatch.getFile(), targetResource.getFile());
targetResource.setState(State.DONE);
isRetry = true;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Channel channel = configurationService.getChannel(currentBatch.getChannelId());
DataContext ctx = new DataContext();
transferFromStaging(mode, BatchType.EXTRACT, currentBatch, isRetry, extractedBatch, writer, ctx, channel.getMaxKBytesPerSecond());
} else {
IDataReader dataReader = new ProtocolDataReader(BatchType.EXTRACT, currentBatch.getNodeId(), extractedBatch);
DataContext ctx = new DataContext();
ctx.put(Constants.DATA_CONTEXT_TARGET_NODE, targetNode);
ctx.put(Constants.DATA_CONTEXT_SOURCE_NODE, nodeService.findIdentity());
new DataProcessor(dataReader, new ProcessInfoDataWriter(dataWriter, processInfo), "send from stage").process(ctx);
if (dataReader.getStatistics().size() > 0) {
Statistics stats = dataReader.getStatistics().values().iterator().next();
statisticManager.incrementDataSent(currentBatch.getChannelId(), stats.get(DataReaderStatistics.READ_RECORD_COUNT));
long byteCount = stats.get(DataReaderStatistics.READ_BYTE_COUNT);
statisticManager.incrementDataBytesSent(currentBatch.getChannelId(), byteCount);
} else {
log.warn("Could not find recorded statistics for batch {}", currentBatch.getNodeBatchId());
}
}
} else {
throw new IllegalStateException(String.format("Could not find the staged resource for batch %s", currentBatch.getNodeBatchId()));
}
currentBatch = requeryIfEnoughTimeHasPassed(ts, currentBatch);
}
return currentBatch;
}
use of org.jumpmind.symmetric.ISymmetricEngine in project symmetric-ds by JumpMind.
the class DataGapDetectorTest method setUp.
@Before
public void setUp() throws Exception {
sqlTemplate = mock(ISqlTemplate.class);
sqlTransaction = mock(ISqlTransaction.class);
when(sqlTemplate.startSqlTransaction()).thenReturn(sqlTransaction);
IDatabasePlatform platform = mock(IDatabasePlatform.class);
when(platform.getDatabaseInfo()).thenReturn(new DatabaseInfo());
when(platform.getSqlTemplate()).thenReturn(sqlTemplate);
symmetricDialect = mock(AbstractSymmetricDialect.class);
when(symmetricDialect.getPlatform()).thenReturn(platform);
when(symmetricDialect.supportsTransactionViews()).thenReturn(false);
when(symmetricDialect.getDatabaseTime()).thenReturn(0L);
parameterService = mock(ParameterService.class);
when(parameterService.getEngineName()).thenReturn(ENGINE_NAME);
when(parameterService.getLong(ParameterConstants.ROUTING_STALE_DATA_ID_GAP_TIME)).thenReturn(60000000L);
when(parameterService.getInt(ParameterConstants.DATA_ID_INCREMENT_BY)).thenReturn(1);
when(parameterService.getLong(ParameterConstants.ROUTING_LARGEST_GAP_SIZE)).thenReturn(50000000L);
when(parameterService.getLong(ParameterConstants.DBDIALECT_ORACLE_TRANSACTION_VIEW_CLOCK_SYNC_THRESHOLD_MS)).thenReturn(60000L);
when(parameterService.getLong(ParameterConstants.ROUTING_STALE_GAP_BUSY_EXPIRE_TIME)).thenReturn(60000L);
when(parameterService.is(ParameterConstants.ROUTING_DETECT_INVALID_GAPS)).thenReturn(true);
when(parameterService.getInt(ParameterConstants.ROUTING_MAX_GAP_CHANGES)).thenReturn(1000);
IExtensionService extensionService = mock(ExtensionService.class);
ISymmetricEngine engine = mock(AbstractSymmetricEngine.class);
when(engine.getParameterService()).thenReturn(parameterService);
when(engine.getStatisticManager()).thenReturn(statisticManager);
when(engine.getNodeService()).thenReturn(nodeService);
when(engine.getDataService()).thenReturn(dataService);
when(engine.getSymmetricDialect()).thenReturn(symmetricDialect);
when(engine.getExtensionService()).thenReturn(extensionService);
routerService = new RouterService(engine);
when(engine.getRouterService()).thenReturn(routerService);
contextService = mock(ContextService.class);
dataService = mock(DataService.class);
statisticManager = mock(StatisticManager.class);
when(statisticManager.newProcessInfo((ProcessInfoKey) any())).thenReturn(new ProcessInfo());
nodeService = mock(NodeService.class);
when(nodeService.findIdentity()).thenReturn(new Node(NODE_ID, NODE_GROUP_ID));
detector = newGapDetector();
detector.setFullGapAnalysis(false);
}
use of org.jumpmind.symmetric.ISymmetricEngine in project symmetric-ds by JumpMind.
the class XmlPublisherDataRouterTest method setUp.
@Before
public void setUp() {
ISymmetricEngine engine = mock(ISymmetricEngine.class);
when(engine.getSymmetricDialect()).thenReturn(mock(AbstractSymmetricDialect.class));
when(engine.getSymmetricDialect().getBinaryEncoding()).thenReturn(BinaryEncoding.BASE64);
table = Table.buildTable(TABLE_NAME, new String[] { "ID" }, new String[] { "ID", "DATA" });
context = new SimpleRouterContext();
router = new XmlPublisherDataRouter();
router.setSymmetricEngine(engine);
router.setTimeStringGenerator(new XmlPublisherDatabaseWriterFilter.ITimeGenerator() {
public String getTime() {
return "test";
}
});
List<String> groupByColumnNames = new ArrayList<String>();
groupByColumnNames.add("ID");
router.setGroupByColumnNames(groupByColumnNames);
output = new Output();
router.setPublisher(output);
}
use of org.jumpmind.symmetric.ISymmetricEngine in project symmetric-ds by JumpMind.
the class SymmetricEngineHolder method uninstallEngine.
public void uninstallEngine(ISymmetricEngine engine) {
Node node = engine.getNodeService().getCachedIdentity();
String engineName = engine.getEngineName();
File file = new SymmetricAdmin("uninstall", "", "").findPropertiesFileForEngineWithName(engineName);
engine.uninstall();
engine.destroy();
if (file != null) {
file.delete();
}
getEngines().remove(engineName);
for (ISymmetricEngine existingEngine : this.getEngines().values()) {
existingEngine.removeAndCleanupNode(node.getNodeId());
}
}
Aggregations