Synchronizing, Sorting, and Filtering

The core functionality of the Cloud Hot Folder extension is agnostic of the remote storage service. This flexibility allows you to customize different providers. The bulk of this agnostic functionality is held within the cloudcommons and cloudhotfolder extensions. The azurecloudhotfolder extension contains code that is specific to working with Azure Blob storage and takes cares of the synchronizing, sorting, and filtering steps.

Synchronization

The synchronize action polls (at a fixed rate) an Azure Blob storage container, or a subdirectory thereof, for files, ZIP packages, and folders. As part of the synchronization step, a configurable FilterChain is used to filter and receive files that match a certain pattern. A configurable ComparatorChain sorts files during the copy processing. After filtering and sorting, Spring creates one message per file, ZIP package, or folder and delegates each message to a mapped message channel (spring integration file:outbound-gateway).

To support an Azure implementation of the synchronizing, sorting, and filtering steps, the following classes, within org.springframework.integration, are written.

Base Class / Interface Extension Class Explanation

extends... integration.endpoint.AbstractMessageSource<T>

implements...org.springframework.context.Lifecycle

azurecloudhotfolder AzureBlobSynchronizingMessageSource The source from which a Spring configured <inbound-channel-adapter> attempts to receive messages from, specific to an Azure Blob storage account. The specifics of the container connection and synchronization is delegated to the AzureBlobInboundSynchronizer.
implements...file.remote.synchronizer.InboundFileSynchronizer azurecloudhotfolder AzureBlobInboundSynchronizer

An implementation that handles the connecting to and synchronizing of the remote file system with the local one, in an inbound direction. Used by the AzureBlobSynchronizingMessageSource.

Also ensures that a remoteDirectoryExpression is set to use the directory delimiter of the Azure CloudBlobClient.

implements... file.remote.session.SessionFactory azurecloudhotfolder AzureBlobSessionFactory Implementation that provides a session to allow communication with an Azure Blob storage.
extends...file.remote.session.Session<F> azurecloudhotfolder ExtendedSession<F> Extended abstraction for a session with a remote file system.
implements ExtendedSession<F> azurecloudhotfolder AzureBlobSession Implementation that processes a ListBlobItem return by the given CloudBlobClient and sub.

implements... file.remote.FileInfo<T>

implements java.lang.Comparable(FileInfo<T>)

azurecloudhotfolder AzureBlobFileInfo Implementation around an Azure client CloudBlob to return information about that CloudBlob.

Sorting as Part of Synchronization

Sometimes certain files are processed before others, for example, products before product media, or customers before orders. It may also be necessary to process multiple files for the same integration by sequence order. The Cloud Hot Folder uses a Comparator to control the file processing order. The Comparator uses a chain of tests to sort the files before processing them.

Files are sorted using the following data:
  1. File Name prefix
  2. File Name
  3. File Name Sequence
  4. File Modified Time

The chain acts in a similar way to multi-column sorting in SQL, first sorting by prefix, and then by name. To support this, the following classes enable fine-grain control.

Base Class / Interface Extension Class / Interface Explanation
Not applicable cloudcommons NamedObject Interface to provide an object name.
Not applicable cloudcommons TimestampedObject Interface to provide an object timestamp.
implements...java.util.Comparator<T> azurecloudhotfolder AzureBlobNameComparatorAdapter Adapts a Comparator of NamedObject so that it can compare CloudBlob objects based on file name.
implements... java.util.Comparator<T> azurecloudhotfolder AzureBlobTimestampComparatorAdapter Adapts a Comparator of TimestampedObject so that it can compare CloudBlob objects based on file name.
org.apache.commons.collections4.comparators.ComparatorChain cloudcommons N/A - is spring bean
Used to chain the file Comparators to sort the file using the following default order of events:
  1. File Name Prefix
  2. File Name
  3. File Name Sequence
  4. File Modified Time
implements...java.util.Comparator<T> cloudcommons NamePrefixComparator Implementation that enables file sorting based on a file name prefix.
    NameComparator Implementation that enables file sorting based on a file name.
    NameSequenceComparator Implementation that enables file sorting based on the sequence number within the file name.
    TimestampComparator Implementation that enables file sorting based on a modified time.

Sorting Configuration Fine-Tuning

The Comparators require two configuration properties to fine-tune the AzureBlobNameComparatorAdapter and sort the data.

File Location Configuration items
project.properties <HYBRIS_BIN_DIR>/ext-cloud/cloudhotfolder
  • cloud.hotfolder.storage.file.sort.name.prefix.priority: a comma-separated list of prefix names. Sorting is based on the order specified in the string. Default:coredata,sampledata,product,url_media
  • cloud.hotfolder.storage.file.sort.name.sequence: a pattern used to extract the part of the file name representing a sequence id. Default: ^(?<filename>.*)-(?<sequence>\\d*)(?<extension>.*)$

Default Sort Order

If no changes are made to the existing Comparators, the ComparatorChain, and the properties, then the following file order applies.

File order in Blob storage Comparator Sort Order (import order)

product_ins_1.csv

customer_2.csv

product_ins_2.csv

product_upd_1.csv

customer_1.csv

customer_1.csv

customer_2.csv

product_ins_1.csv

product_ins_2.csv

product_upd_1.csv