|
3 | 3 | ml-javaclient-util is a library of Java classes that provide some useful functionality on top of |
4 | 4 | the [MarkLogic Java Client API](http://docs.marklogic.com/guide/java). Those features include: |
5 | 5 |
|
6 | | -- Support for loading any kind of module using the REST API |
7 | | -- Support for automatically loading a new/modified module using the REST API |
8 | | -- Basic integration with Spring via a Spring FactoryBean |
| 6 | +- Support for [loading modules via the REST API](https://github.com/rjrudin/ml-javaclient-util/tree/master/src/main/java/com/marklogic/client/modulesloader) |
| 7 | +- Basic integration with [Spring via a Spring FactoryBean](https://github.com/rjrudin/ml-javaclient-util/tree/master/src/main/java/com/marklogic/client/spring) |
| 8 | +- Library for [parallelizing batched writes](https://github.com/rjrudin/ml-javaclient-util/tree/master/src/main/java/com/marklogic/client/batch) |
| 9 | +- Spring-style [template/callback library for XCC](https://github.com/rjrudin/ml-javaclient-util/tree/master/src/main/java/com/marklogic/xcc/template) |
| 10 | +- Support for generating MarkLogic 9 [Entity Services modules](https://github.com/rjrudin/ml-javaclient-util/tree/master/src/main/java/com/marklogic/client/es) |
| 11 | +- Support for [importing/exporting qconsole workspaces] (https://github.com/rjrudin/ml-javaclient-util/tree/master/src/main/java/com/marklogic/client/qconsole) |
| 12 | + |
| 13 | +This is a lower-level library that is primarily used via [ml-app-deployer](https://github.com/rjrudin/ml-app-deployer) |
| 14 | +and [ml-gradle](https://github.com/rjrudin/ml-gradle) and [ml-junit](https://github.com/rjrudin/ml-junit). But you can use it by itself too. |
9 | 15 |
|
10 | | -This is a lower-level library that is primarily used via [ml-app-deployer](https://github.com/rjrudin/ml-app-deployer) and [ml-gradle](https://github.com/rjrudin/ml-gradle) and [ml-junit](https://github.com/rjrudin/ml-junit). But you can use it by itself too. |
| 16 | +### Loading Modules |
11 | 17 |
|
12 | 18 | Here's a sample of loading modules - though it's best to look at the aforementioned projects to see all the ways this can be done: |
13 | 19 |
|
14 | 20 | DatabaseClient client = DatabaseClientFactory.newClient(...); // Use the ML Java Client API |
15 | | - RestApiAssetLoader assetLoader = new RestApiAssetLoader(client); // Can use XCC or the REST API to load asset modules |
| 21 | + XccAssetLoader assetLoader = new XccAssetLoader(client); // Can use XCC or the REST API to load asset modules |
16 | 22 | DefaultModulesLoader modulesLoader = new DefaultModulesLoader(assetLoader); |
17 | 23 | File modulesDir = new File("src/main/ml-modules"); |
18 | 24 | ModulesFinder modulesFinder = new DefaultModulesFinder(); // Allows for adjusting where modules are stored on a filesystem |
19 | 25 | modulesLoader.loadModules(modulesDir, modulesFinder, client); |
20 | | - |
| 26 | + |
| 27 | +### Parallelized batch writes |
| 28 | + |
| 29 | +The [BatchWriter](https://github.com/rjrudin/ml-javaclient-util/tree/master/src/main/java/com/marklogic/client/batch) library |
| 30 | +was created primarily for applications using [marklogic-spring-batch](https://github.com/sastafford/marklogic-spring-batch). But |
| 31 | +it can be used in any environment. It provides the following features: |
| 32 | + |
| 33 | +1. Uses Spring's [TaskExecutor library](https://docs.spring.io/spring/docs/current/spring-framework-reference/html/scheduling.html) for parallelizing writes |
| 34 | +1. Supports writes via the REST API or XCC |
| 35 | + |
| 36 | +Via Spring's TaskExecutor library, you can essentially throw an infinite number of documents at this interface. The library |
| 37 | +will default to a sensible implementation of [ThreadPoolTaskExecutor](http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.html), |
| 38 | +but you can override that with any TaskExecutor implementation you like. |
| 39 | + |
| 40 | +Once MarkLogic 9 is available, an implementation will be used that depends on the new Data Movement SDK, which is being |
| 41 | +added to the MarkLogic Java Client API. |
| 42 | + |
| 43 | +Here's a sample using two DatabaseClient instances: |
| 44 | + |
| 45 | + // This is all basic Java Client API stuff |
| 46 | + DatabaseClient client1 = DatabaseClientFactory.newClient("host1", ...); |
| 47 | + DatabaseClient client2 = DatabaseClientFactory.newClient("host2", ...); |
| 48 | + DocumentWriteOperation doc1 = new DocumentWriteOperationImpl("test1.xml", ...); |
| 49 | + DocumentWriteOperation doc2 = new DocumentWriteOperationImpl("test2.xml", ...); |
| 50 | + |
| 51 | + // Here's how BatchWriter works |
| 52 | + BatchWriter writer = new RestBatchWriter(Arrays.asList(client1, client2)); |
| 53 | + writer.initialize(); |
| 54 | + writer.write(Arrays.asList(doc1, doc2)); |
| 55 | + writer.waitForCompletion(); |
0 commit comments