Search in sources :

Example 1 with InternalIncomingTransport

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

the class DataLoaderService method loadDataFromPush.

/**
     * Load database from input stream and write acknowledgment to output
     * stream. This is used for a "push" request with a response of an
     * acknowledgment.
     */
public void loadDataFromPush(Node sourceNode, String channelId, InputStream in, OutputStream out) throws IOException {
    Node local = nodeService.findIdentity();
    if (local != null) {
        ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(sourceNode.getNodeId(), channelId, local.getNodeId(), ProcessInfoKey.ProcessType.PUSH_HANDLER));
        try {
            List<IncomingBatch> batchList = loadDataFromTransport(processInfo, sourceNode, new InternalIncomingTransport(in), out);
            logDataReceivedFromPush(sourceNode, batchList);
            NodeSecurity security = nodeService.findNodeSecurity(local.getNodeId());
            processInfo.setStatus(ProcessInfo.Status.ACKING);
            transportManager.writeAcknowledgement(out, sourceNode, batchList, local, security != null ? security.getNodePassword() : null);
            if (containsError(batchList)) {
                processInfo.setStatus(ProcessInfo.Status.ERROR);
            } else {
                processInfo.setStatus(ProcessInfo.Status.OK);
            }
        } catch (Exception e) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else if (e instanceof IOException) {
                throw (IOException) e;
            }
            throw new RuntimeException(e);
        }
    } else {
        throw new SymmetricException("Could not load data because the node is not registered");
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) Node(org.jumpmind.symmetric.model.Node) SymmetricException(org.jumpmind.symmetric.SymmetricException) InternalIncomingTransport(org.jumpmind.symmetric.transport.internal.InternalIncomingTransport) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IOException(java.io.IOException) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch) SymmetricException(org.jumpmind.symmetric.SymmetricException) SQLException(java.sql.SQLException) ConnectException(java.net.ConnectException) ConflictException(org.jumpmind.symmetric.io.data.writer.ConflictException) IOException(java.io.IOException) RegistrationNotOpenException(org.jumpmind.symmetric.service.RegistrationNotOpenException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ServiceUnavailableException(org.jumpmind.symmetric.transport.ServiceUnavailableException) UniqueKeyException(org.jumpmind.db.sql.UniqueKeyException) SqlException(org.jumpmind.db.sql.SqlException) TransportException(org.jumpmind.symmetric.transport.TransportException) RegistrationRequiredException(org.jumpmind.symmetric.service.RegistrationRequiredException) ConnectionRejectedException(org.jumpmind.symmetric.transport.ConnectionRejectedException) SyncDisabledException(org.jumpmind.symmetric.transport.SyncDisabledException) IoException(org.jumpmind.exception.IoException) MalformedURLException(java.net.MalformedURLException) AuthenticationException(org.jumpmind.symmetric.transport.AuthenticationException)

Example 2 with InternalIncomingTransport

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

the class DataLoaderService method loadDataFromPush.

/**
 * Load database from input stream and write acknowledgment to output
 * stream. This is used for a "push" request with a response of an
 * acknowledgment.
 */
public void loadDataFromPush(Node sourceNode, InputStream in, OutputStream out) throws IOException {
    Node local = nodeService.findIdentity();
    if (local != null) {
        ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(sourceNode.getNodeId(), local.getNodeId(), ProcessType.LOAD_FROM_PUSH));
        try {
            List<IncomingBatch> batchList = loadDataFromTransport(processInfo, sourceNode, new InternalIncomingTransport(in));
            logDataReceivedFromPush(sourceNode, batchList);
            NodeSecurity security = nodeService.findNodeSecurity(local.getNodeId());
            processInfo.setStatus(ProcessInfo.Status.ACKING);
            transportManager.writeAcknowledgement(out, sourceNode, batchList, local, security != null ? security.getNodePassword() : null);
            if (containsError(batchList)) {
                processInfo.setStatus(ProcessInfo.Status.ERROR);
            } else {
                processInfo.setStatus(ProcessInfo.Status.OK);
            }
        } catch (RuntimeException e) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            throw e;
        }
    } else {
        throw new SymmetricException("Could not load data because the node is not registered");
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) Node(org.jumpmind.symmetric.model.Node) SymmetricException(org.jumpmind.symmetric.SymmetricException) InternalIncomingTransport(org.jumpmind.symmetric.transport.internal.InternalIncomingTransport) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch)

Example 3 with InternalIncomingTransport

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

the class DataLoaderService method loadDataBatch.

public List<IncomingBatch> loadDataBatch(String batchData) {
    String nodeId = nodeService.findIdentityNodeId();
    if (StringUtils.isNotBlank(nodeId)) {
        ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(nodeId, nodeId, ProcessType.MANUAL_LOAD));
        try {
            InternalIncomingTransport transport = new InternalIncomingTransport(new BufferedReader(new StringReader(batchData)));
            List<IncomingBatch> list = loadDataFromTransport(processInfo, nodeService.findIdentity(), transport);
            processInfo.setStatus(ProcessInfo.Status.OK);
            return list;
        } catch (IOException ex) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            throw new IoException();
        } catch (RuntimeException ex) {
            processInfo.setStatus(ProcessInfo.Status.ERROR);
            throw ex;
        }
    } else {
        return new ArrayList<IncomingBatch>(0);
    }
}
Also used : InternalIncomingTransport(org.jumpmind.symmetric.transport.internal.InternalIncomingTransport) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) IoException(org.jumpmind.exception.IoException) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IOException(java.io.IOException) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch)

Example 4 with InternalIncomingTransport

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

the class AbstractDataLoaderServiceTest method load.

protected void load(ByteArrayOutputStream out) throws Exception {
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    getTransportManager().setIncomingTransport(new InternalIncomingTransport(in));
    getDataLoaderService().loadDataFromPull(client);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InternalIncomingTransport(org.jumpmind.symmetric.transport.internal.InternalIncomingTransport)

Aggregations

InternalIncomingTransport (org.jumpmind.symmetric.transport.internal.InternalIncomingTransport)4 IncomingBatch (org.jumpmind.symmetric.model.IncomingBatch)3 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)3 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)3 IOException (java.io.IOException)2 IoException (org.jumpmind.exception.IoException)2 SymmetricException (org.jumpmind.symmetric.SymmetricException)2 Node (org.jumpmind.symmetric.model.Node)2 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 StringReader (java.io.StringReader)1 ConnectException (java.net.ConnectException)1 MalformedURLException (java.net.MalformedURLException)1 UnknownHostException (java.net.UnknownHostException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 SqlException (org.jumpmind.db.sql.SqlException)1 UniqueKeyException (org.jumpmind.db.sql.UniqueKeyException)1