Search in sources :

Example 1 with IAcknowledgeService

use of org.jumpmind.symmetric.service.IAcknowledgeService 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)

Example 2 with IAcknowledgeService

use of org.jumpmind.symmetric.service.IAcknowledgeService in project symmetric-ds by JumpMind.

the class RestService method putAcknowledgeBatch.

@ApiOperation(value = "Acknowledge a set of batches for the specified engine")
@RequestMapping(value = "/engine/{engine}/acknowledgebatch", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public final BatchAckResults putAcknowledgeBatch(@PathVariable("engine") String engineName, @ApiParam(value = "This the password for the nodeId being passed in.  The password is stored in the node_security table.") @RequestParam(value = WebConstants.SECURITY_TOKEN) String securityToken, @RequestBody BatchResults batchResults) {
    BatchAckResults finalResult = new BatchAckResults();
    ISymmetricEngine engine = getSymmetricEngine(engineName);
    List<BatchAckResult> results = null;
    if (batchResults.getBatchResults().size() > 0) {
        if (securityVerified(batchResults.getNodeId(), engine, securityToken)) {
            IAcknowledgeService ackService = engine.getAcknowledgeService();
            List<BatchAck> batchAcks = convertBatchResultsToAck(batchResults);
            results = ackService.ack(batchAcks);
        } else {
            throw new NotAllowedException();
        }
    }
    finalResult.setBatchAckResults(results);
    return finalResult;
}
Also used : BatchAck(org.jumpmind.symmetric.model.BatchAck) BatchAckResults(org.jumpmind.symmetric.web.rest.model.BatchAckResults) BatchAckResult(org.jumpmind.symmetric.model.BatchAckResult) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IAcknowledgeService(org.jumpmind.symmetric.service.IAcknowledgeService) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

BatchAck (org.jumpmind.symmetric.model.BatchAck)2 IAcknowledgeService (org.jumpmind.symmetric.service.IAcknowledgeService)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)1 BatchAckResult (org.jumpmind.symmetric.model.BatchAckResult)1 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)1 Status (org.jumpmind.symmetric.model.OutgoingBatch.Status)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 BatchAckResults (org.jumpmind.symmetric.web.rest.model.BatchAckResults)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1