How to synchronize an acknowledgement message in a disconnected environment


Summary
This article demonstrates how to send acknowledgement messages between replicas in a disconnected environment. Acknowledgement messages are exchanged between replicas in a disconnected environment to acknowledge receipt of data changes. A disconnected environment means that the parent and child replica geodatabases are not connected by a local area network (LAN) or a wide area network (WAN).

In this topic


Exporting an acknowledgement message from a replica

  1. Connect to a geodatabase to host the replica from which you want to export the acknowledgement message. This requires initializing a geodataserver object.  Geodataserver objects allow you to access a geodatabase on a LAN or WAN through ArcGIS Server. To see how to initialize a geodataserver, refer to How to initialize a geodataserver object.
  2. Call the following procedure by pasting it into your application and passing in the following parameters:
sourceGDS
The GeoDataServer that you initialized in Step 1. This hosts the replica geodatabase that is the source of the acknowledgement file.
replicaName
The replicaName parameter takes the name of the replica.
outputDirectory
The outputDirectory parameter specifies the output location for the acknowledgement file. This location should point to a directory on your local drive. If this folder exists, it will be replaced. If it doesn't exist, it will be created.
[Java]
static void exportAcknowledgement(IGeoDataServer sourceGDS, String replicaName,
    String outputDirectory)throws Exception{
    // Export the acknowledgement file.
    IGDSData gdsData = sourceGDS.exportAcknowledgement(replicaName,
        esriGDSTransportType.esriGDSTransportTypeUrl);
    /*
     * Replace or create the output directory. If directory already exists,
     * delete it and create again by copying. Force deletion of folder and
     * contents, if they exist.
     */
    initializeDirectory(outputDirectory);
    // Download the acknowledgement file from the URL to the local output
    // directory.
    if (gdsData.getTransportType() == esriGDSTransportType.esriGDSTransportTypeUrl){
        String fileURL = gdsData.getURL();
        URLConnection connection = new URL(fileURL).openConnection();
        String fileName = fileURL.substring(fileURL.lastIndexOf('/') + 1);
        connection.connect();
        InputStream input = connection.getInputStream();
        FileOutputStream output = new FileOutputStream(new File(outputDirectory +
            File.separator + fileName));
        byte[] bytes = new byte[10000];
        int actuallyRead = input.read(bytes);
        while (actuallyRead !=  - 1){
            output.write(bytes, 0, actuallyRead);
            actuallyRead = input.read(bytes);
        }
        input.close();
        output.flush();
        output.close();
    }
    else{
        System.out.println("Server is not configured with a virtual directory");
        gdsData.getEmbeddedData(); // The file has been embedded because
        // there is no output directory set on
        // ArcGIS Server.
    }
}

private static void initializeDirectory(String outputDirectory){
    File directory = new File(outputDirectory);
    if (!directory.exists()){
        directory.mkdir();
        return ;
    }
    else{
        deleteContents(directory);
        directory.delete();
        directory.mkdir();
    }
}

private static void deleteContents(File directory){
    File[] contents = directory.listFiles();
    for (File file: contents){
        if (file.isDirectory())
            deleteContents(file);
        file.delete();
    }
}

Importing an acknowledgement message into the relative replica

  1. Connect to a geodatabase to host the replica to which you want to import the acknowledgement message. This requires initializing a geodataserver object.  Geodataserver objects allow you to access a geodatabase on a LAN or WAN through ArcGIS Server. To see how to initialize a geodataserver, refer to How to initialize a geodataserver object.
  2. Call the following procedure by pasting it into your application and passing in the following parameters:
targetGDS
The geodataserver that you initialized in Step 1. This hosts the replica geodatabase into which you want to import the acknowledgement file.
inputDirectory
The inputDirectory specifies the location of the acknowledgement file. This location should point to a directory, which holds the acknowledgement file. The function assumes that there is only one file in this directory. If there are more than one file in the inputDirectory, only the first file will be read.
[Java]
static void importAcknowledgement(IGeoDataServer targetGDS, String inputDirectory)
    throws Exception{
    /* Get the acknowledgement file from the input directory.
    It is assumed that the first file in the directory is the acknowledgement file. */
    File ackFile = new File(inputDirectory).listFiles()[0];
    long size = ackFile.length();
    if (size > Integer.MAX_VALUE){
        System.out.println("File is larger than anticipated. Aborting.");
        return ;
    }
    byte[] bytes = new byte[(int)size];
    FileInputStream inputStream = new FileInputStream(ackFile);
    inputStream.reset();
    int actuallyRead = inputStream.read(bytes);
    while (actuallyRead !=  - 1){
        actuallyRead += inputStream.read(bytes, actuallyRead, bytes.length -
            actuallyRead);
    }
    // Embed the GDSData object.
    IGDSData gdsData = new GDSData();
    gdsData.setTransportType(esriGDSTransportType.esriGDSTransportTypeEmbedded);
    gdsData.setCompressed(false);
    gdsData.setEmbeddedData(bytes);
    // Import the acknowledgement file.
    targetGDS.importAcknowledgement(gdsData);
}






Development licensingDeployment licensing
ArcGIS for Desktop StandardArcGIS for Desktop Standard
ArcGIS for Desktop AdvancedArcGIS for Desktop Advanced
Engine Developer KitEngine: Geodatabase Update