Search in sources :

Example 1 with ITransportManager

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

the class PushService method updateBatchStatus.

protected Status updateBatchStatus(OutgoingBatch batch, Node targetNode, Node identityNode, NodeSecurity identitySecurity) {
    OutgoingBatch.Status returnStatus = batch.getStatus();
    ITransportManager transportManager = engine.getTransportManager();
    IAcknowledgeService acknowledgeService = engine.getAcknowledgeService();
    IIncomingTransport transport = null;
    try {
        transport = transportManager.getAckStatusTransport(batch, targetNode, identityNode, identitySecurity.getNodePassword(), parameterService.getRegistrationUrl());
        BufferedReader reader = transport.openReader();
        String line = null;
        do {
            line = reader.readLine();
            if (line != null) {
                log.info("Updating batch status: {}", line);
                List<BatchAck> batchAcks = transportManager.readAcknowledgement(line, "");
                for (BatchAck batchInfo : batchAcks) {
                    if (batchInfo.getBatchId() == batch.getBatchId()) {
                        acknowledgeService.ack(batchInfo);
                        returnStatus = batchInfo.getStatus();
                    }
                }
            }
        } while (line != null);
    } catch (FileNotFoundException ex) {
        log.info("Failed to read batch status for {}.  It is probably because the server is not online yet", batch.getNodeBatchId());
    } catch (Exception ex) {
        log.warn(String.format("Failed to read the batch status for %s", batch.getNodeBatchId()), ex);
    } finally {
        transport.close();
    }
    return returnStatus;
}
Also used : Status(org.jumpmind.symmetric.model.OutgoingBatch.Status) BatchAck(org.jumpmind.symmetric.model.BatchAck) ITransportManager(org.jumpmind.symmetric.transport.ITransportManager) IIncomingTransport(org.jumpmind.symmetric.transport.IIncomingTransport) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) IAcknowledgeService(org.jumpmind.symmetric.service.IAcknowledgeService) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) FileNotFoundException(java.io.FileNotFoundException) ChannelDisabledException(org.jumpmind.symmetric.transport.ChannelDisabledException) ConnectionRejectedException(org.jumpmind.symmetric.transport.ConnectionRejectedException) ServiceUnavailableException(org.jumpmind.symmetric.transport.ServiceUnavailableException)

Aggregations

BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 BatchAck (org.jumpmind.symmetric.model.BatchAck)1 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)1 Status (org.jumpmind.symmetric.model.OutgoingBatch.Status)1 IAcknowledgeService (org.jumpmind.symmetric.service.IAcknowledgeService)1 ChannelDisabledException (org.jumpmind.symmetric.transport.ChannelDisabledException)1 ConnectionRejectedException (org.jumpmind.symmetric.transport.ConnectionRejectedException)1 IIncomingTransport (org.jumpmind.symmetric.transport.IIncomingTransport)1 ITransportManager (org.jumpmind.symmetric.transport.ITransportManager)1 ServiceUnavailableException (org.jumpmind.symmetric.transport.ServiceUnavailableException)1