Skip to content

Instantly share code, notes, and snippets.

@idanmo
Created January 20, 2013 08:52
Show Gist options
  • Select an option

  • Save idanmo/4577356 to your computer and use it in GitHub Desktop.

Select an option

Save idanmo/4577356 to your computer and use it in GitHub Desktop.
GigaSpaces MongoDB persistency example implementation
public class MongoDbSpaceSynchronizationEndpoint extends SpaceSynchronizationEndpoint {
private DB db = ... // MongoDB database object
@Override
public void onOperationsBatchSynchronization(final OperationsBatchData data) {
// Get the MongoDB collection that will be used for persisting space documents
DBCollection collection = db.getCollection("spaceDocuments");
// Persist each of the space documents in this batch
for (DataSyncOperation operation : data.getBatchDataItems()) {
// Handle only write operations which are document supported
if (operation.getDataSyncOperationType() == DataSyncOperationType.WRITE && operation.supportsDataAsDocument()) {
// Get the space document for this operation
SpaceDocument spaceDocument = operation.getDataAsDocument();
// Create a MongoDB document
BasicDBObject mongoDocument = new BasicDBObject();
for (Map.Entry<String,Object> property : spaceDocument.getProperties().entrySet())
mongoDocument.append(property.getKey(), property.getValue());
// Insert to MongoDB
collection.insert(mongoDocument);
}
}
}
}
<bean id="spaceSynchronizationEndpoint" class="com.gigaspaces.persistency.MongoDbSpaceSynchronizationEndpoint" />
<os-core:space id="space" url="/./documentsSpace" space-sync-endpoint="spaceSynchronizationEndpoint" />
<os-core:giga-space id="gigaSpace" space="space" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment