Search in sources :

Example 1 with FileOutgoingTransport

use of org.jumpmind.symmetric.transport.file.FileOutgoingTransport in project symmetric-ds by JumpMind.

the class OfflinePushService method pushToNode.

private void pushToNode(Node remote, RemoteNodeStatus status) {
    Node identity = nodeService.findIdentity();
    FileOutgoingTransport transport = null;
    ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(identity.getNodeId(), status.getChannelId(), remote.getNodeId(), ProcessType.OFFLINE_PUSH));
    List<OutgoingBatch> extractedBatches = null;
    try {
        transport = (FileOutgoingTransport) transportManager.getPushTransport(remote, identity, null, null);
        extractedBatches = dataExtractorService.extract(processInfo, remote, status.getChannelId(), transport);
        if (extractedBatches.size() > 0) {
            log.info("Offline push data written for {} at {}", remote, transport.getOutgoingDir());
            List<BatchAck> batchAcks = readAcks(extractedBatches, transport, transportManager, acknowledgeService);
            status.updateOutgoingStatus(extractedBatches, batchAcks);
        }
        if (processInfo.getStatus() != Status.ERROR) {
            processInfo.setStatus(Status.OK);
        }
    } catch (Exception ex) {
        processInfo.setStatus(Status.ERROR);
        log.error("Failed to write offline file", ex);
    } finally {
        transport.close();
        transport.complete(processInfo.getStatus() == Status.OK);
    }
}
Also used : BatchAck(org.jumpmind.symmetric.model.BatchAck) FileOutgoingTransport(org.jumpmind.symmetric.transport.file.FileOutgoingTransport) Node(org.jumpmind.symmetric.model.Node) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch)

Example 2 with FileOutgoingTransport

use of org.jumpmind.symmetric.transport.file.FileOutgoingTransport in project symmetric-ds by JumpMind.

the class FileSyncService method pushFilesToNode.

protected void pushFilesToNode(NodeCommunication nodeCommunication, RemoteNodeStatus status, Node identity, NodeSecurity security) {
    ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(nodeCommunication.getNodeId(), identity.getNodeId(), ProcessType.FILE_SYNC_PUSH_JOB));
    IOutgoingWithResponseTransport transport = null;
    ITransportManager transportManager = null;
    try {
        if (!engine.getParameterService().is(ParameterConstants.NODE_OFFLINE)) {
            transportManager = engine.getTransportManager();
            transport = transportManager.getFilePushTransport(nodeCommunication.getNode(), identity, security.getNodePassword(), parameterService.getRegistrationUrl());
        } else {
            transportManager = ((AbstractSymmetricEngine) engine).getOfflineTransportManager();
            transport = transportManager.getFilePushTransport(nodeCommunication.getNode(), identity, security.getNodePassword(), parameterService.getRegistrationUrl());
        }
        List<OutgoingBatch> batches = sendFiles(processInfo, nodeCommunication.getNode(), transport);
        if (batches.size() > 0) {
            if (transport instanceof FileOutgoingTransport) {
                ((FileOutgoingTransport) transport).setProcessedBatches(batches);
            }
            List<BatchAck> batchAcks = readAcks(batches, transport, transportManager, engine.getAcknowledgeService());
            status.updateOutgoingStatus(batches, batchAcks);
        }
        if (!status.failed() && batches.size() > 0) {
            log.info("Pushed files to {}. {} files and {} batches were processed", new Object[] { nodeCommunication.getNodeId(), status.getDataProcessed(), status.getBatchesProcessed() });
        } else if (status.failed()) {
            log.info("There was a failure while pushing files to {}. {} files and {} batches were processed", new Object[] { nodeCommunication.getNodeId(), status.getDataProcessed(), status.getBatchesProcessed() });
        }
    } catch (Exception e) {
        fireOffline(e, nodeCommunication.getNode(), status);
    } finally {
        if (processInfo.getStatus() != ProcessInfo.Status.ERROR) {
            processInfo.setStatus(ProcessInfo.Status.OK);
        }
        if (transport != null) {
            transport.close();
            if (transport instanceof FileOutgoingTransport) {
                ((FileOutgoingTransport) transport).complete(processInfo.getStatus() == ProcessInfo.Status.OK);
            }
        }
    }
}
Also used : BatchAck(org.jumpmind.symmetric.model.BatchAck) ITransportManager(org.jumpmind.symmetric.transport.ITransportManager) IOutgoingWithResponseTransport(org.jumpmind.symmetric.transport.IOutgoingWithResponseTransport) FileOutgoingTransport(org.jumpmind.symmetric.transport.file.FileOutgoingTransport) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) FileConflictException(org.jumpmind.symmetric.file.FileConflictException) NoContentException(org.jumpmind.symmetric.transport.NoContentException) SymmetricException(org.jumpmind.symmetric.SymmetricException) IoException(org.jumpmind.exception.IoException) IOException(java.io.IOException)

Aggregations

BatchAck (org.jumpmind.symmetric.model.BatchAck)2 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)2 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)2 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)2 FileOutgoingTransport (org.jumpmind.symmetric.transport.file.FileOutgoingTransport)2 IOException (java.io.IOException)1 IoException (org.jumpmind.exception.IoException)1 SymmetricException (org.jumpmind.symmetric.SymmetricException)1 FileConflictException (org.jumpmind.symmetric.file.FileConflictException)1 Node (org.jumpmind.symmetric.model.Node)1 IOutgoingWithResponseTransport (org.jumpmind.symmetric.transport.IOutgoingWithResponseTransport)1 ITransportManager (org.jumpmind.symmetric.transport.ITransportManager)1 NoContentException (org.jumpmind.symmetric.transport.NoContentException)1