Working on a project were I migrated some methods from inline #QueryParam param lists into #BeanParam I noticed a significant and unexplained impact in latency.
I am unsure what internals are causing this issue because it does not seem to be just the new Bean creation, since an empty Bean is as fast as no Bean. Also #QueryParams added into the Bean increase the latency proportionally, the same definitely does not happen at the method level.
The difference between both forms is huge in terms of latency, the #BeanParam one takes 20% longer despite doing essentially the same.
#Path("test1")
public Response test1(#QueryParam("instring") String one, #QueryParam("instring2") String two)
vs
public class Params {
#QueryParam("instring") String one;
#QueryParam("instring2") String two;
}
#Path("test2")
public Response test2(#BeanParam Params params)
I have created a minimal example here.
My goal is to find a workaround for this since I really find #BeanParam very nice to organise groups of params and its not clear to me where the latency increase comes from, perhaps there is some kind of hint I can supply to eliminate the perf hit.
As #paul-samsotha mentioned, the additional latency you are encountering seems to be associated with the reflection used to associate query params with the bean fields after the bean is constructed.
Taking your example, commenting out all the Params bean fields initially and running the tests multiple times, adding a field back into the Params bean on each run you get the following results:
No Fields: Commenting all fields out of Params class
15:14:53.664 [main] INFO org.example.ProofOfConcept - Warming up
15:15:35.562 [main] INFO org.example.ProofOfConcept - Warmed up
15:15:49.244 [main] INFO org.example.ProofOfConcept - Reqs1: 731.101 10000 in 13.68
15:16:02.968 [main] INFO org.example.ProofOfConcept - Reqs2: 728.7037 10000 in 13.72
15:16:17.016 [main] INFO org.example.ProofOfConcept - Req2/Req1 1.0032899
Single Field: First param only
15:16:57.160 [main] INFO org.example.ProofOfConcept - Warming up
15:17:26.052 [main] INFO org.example.ProofOfConcept - Warmed up
15:17:39.715 [main] INFO org.example.ProofOfConcept - Reqs1: 732.06445 10000 in 13.66
15:17:54.582 [main] INFO org.example.ProofOfConcept - Reqs2: 672.6759 10000 in 14.87
...
3 Fields: First 3 string params
15:20:33.870 [main] INFO org.example.ProofOfConcept - Warming up
15:21:01.859 [main] INFO org.example.ProofOfConcept - Warmed up
15:21:15.825 [main] INFO org.example.ProofOfConcept - Reqs1: 716.17847 10000 in 13.96
15:21:30.926 [main] INFO org.example.ProofOfConcept - Reqs2: 662.2078 10000 in 15.10
...
All params
15:23:55.339 [main] INFO org.example.ProofOfConcept - Warming up
15:24:25.717 [main] INFO org.example.ProofOfConcept - Warmed up
15:24:39.376 [main] INFO org.example.ProofOfConcept - Reqs1: 732.2789 10000 in 13.66
15:24:55.676 [main] INFO org.example.ProofOfConcept - Reqs2: 613.5346 10000 in 16.30
15:24:55.676 [main] INFO org.example.ProofOfConcept - Req2/Req1 1.1935413
The performance gradually gets worse as more Bean fields are added.
As a workaround you could update your Bean class as follows:
#ToString
public static class Params {
String instring;
String inint;
int inint2;
int inint3;
String inint4;
String inint5;
String inint6;
String inint7;
Params(#Context UriInfo allUri){
MultivaluedMap<String, String> params = allUri.getQueryParameters();
instring = params.getFirst("instring");
inint = params.getFirst("inint");
inint2 = toInt(params.getFirst("inint2"));
inint3 = toInt(params.getFirst("inint3"));
inint4 = params.getFirst("inint4");
inint5 = params.getFirst("inint5");
inint6 = params.getFirst("inint6");
inint7 = params.getFirst("inint7");
}
int toInt(String value){
return nonNull(value) ? Integer.parseInt(value) : -1;
}
}
This update should eliminate the reflection mapping stage and result in improved performance:
15:35:16.713 [main] INFO org.example.ProofOfConcept - Warming up
15:35:45.513 [main] INFO org.example.ProofOfConcept - Warmed up
15:35:59.493 [main] INFO org.example.ProofOfConcept - Reqs1: 715.5123 10000 in 13.98
15:36:13.536 [main] INFO org.example.ProofOfConcept - Reqs2: 712.0986 10000 in 14.04
15:36:13.536 [main] INFO org.example.ProofOfConcept - Req2/Req1 1.004794
Related
I am trying to generate Jooq code to use with in memory SQLite.
The problem is, that each new Connection creates a fresh SQLite instance which makes the code creation rely on sql scripts. But when I try to fit my code generation to the documentation the code wont be generated. I believe it still tries to access the database which is empty.
I am also not sure if jooq will work with a non persistent database. The database is intented to only exist during the program run. When the program shuts down the database should be gone. If jooq fetches new connections all troughout the runtime, I have to switch anyway.
Jooq generation:
public static void runJooqCodeGen() throws Exception {
String url = "jdbc:sqlite:";
String driver = "org.sqlite.JDBC";
Configuration configuration = new Configuration().withJdbc(new Jdbc().withDriver(driver).withUrl(url))
.withGenerator(new Generator()
.withDatabase(new Database()
.withProperties(new Property()
.withKey("scripts")
.withValue("src/main/resources/db/Schema.sql")))
.withGenerate(new Generate()
.withPojos(Boolean.TRUE)
.withDeprecationOnUnknownTypes(Boolean.FALSE))
.withTarget(new Target()
.withPackageName("me.leslie.generals.server.persistence.jooq")
.withDirectory("Generals-Server/src/main/java")));
GenerationTool.generate(configuration);
}
src/main/resources/db/Schema.sql:
CREATE TABLE IF NOT EXISTS TROOP(
id INTEGER PRIMARY KEY AUTOINCREMENT,
current_health INTEGER NOT NULL,
max_health INTEGER NOT NULL,
pos_x DOUBLE NOT NULL,
pos_y DOUBLE NOT NULL,
normal_speed DOUBLE NOT NULL,
street_speed DOUBLE NOT NULL,
difficult_terrain_speed DOUBLE NOT NULL,
close_combat_range DOUBLE NOT NULL,
ranged_combat_range DOUBLE NOT NULL,
normal_view_distance DOUBLE NOT NULL,
disadvantaged_view_distance DOUBLE NOT NULL,
advantaged_view_distance DOUBLE NOT NULL
);
CREATE TABLE IF NOT EXISTS ARMY(
id INTEGER,
hq INTEGER,
troop INTEGER,
FOREIGN KEY(hq) REFERENCES TROOP(id),
FOREIGN KEY(troop) REFERENCES TROOP(id),
UNIQUE(hq, troop),
PRIMARY KEY (id, hq, troop)
);
The generation does not finish with an error, but this is the console output.
19:02:57.342 [main] DEBUG org.jooq.codegen.GenerationTool - Input configuration : <onError>FAIL</onError><jdbc><driver>org.sqlite.JDBC</driver><url>jdbc:sqlite:</url></jdbc><generator><name>org.jooq.codegen.DefaultGenerator</name><database><regexMatchesPartialQualification>true</regexMatchesPartialQualification><sqlMatchesPartialQualification>true</sqlMatchesPartialQualification><includes>.*</includes><excludes></excludes><includeExcludeColumns>false</includeExcludeColumns><includeTables>true</includeTables><includeEmbeddables>true</includeEmbeddables><includeRoutines>true</includeRoutines><includeTriggerRoutines>false</includeTriggerRoutines><includePackages>true</includePackages><includePackageRoutines>true</includePackageRoutines><includePackageUDTs>true</includePackageUDTs><includePackageConstants>true</includePackageConstants><includeUDTs>true</includeUDTs><includeSequences>true</includeSequences><includeIndexes>true</includeIndexes><includePrimaryKeys>true</includePrimaryKeys><includeUniqueKeys>true</includeUniqueKeys><includeForeignKeys>true</includeForeignKeys><includeCheckConstraints>true</includeCheckConstraints><includeInvisibleColumns>true</includeInvisibleColumns><recordVersionFields></recordVersionFields><recordTimestampFields></recordTimestampFields><syntheticIdentities></syntheticIdentities><syntheticPrimaryKeys></syntheticPrimaryKeys><overridePrimaryKeys></overridePrimaryKeys><dateAsTimestamp>false</dateAsTimestamp><ignoreProcedureReturnValues>false</ignoreProcedureReturnValues><unsignedTypes>true</unsignedTypes><integerDisplayWidths>true</integerDisplayWidths><inputCatalog></inputCatalog><outputCatalogToDefault>false</outputCatalogToDefault><inputSchema></inputSchema><outputSchemaToDefault>false</outputSchemaToDefault><schemaVersionProvider></schemaVersionProvider><catalogVersionProvider></catalogVersionProvider><orderProvider></orderProvider><forceIntegerTypesOnZeroScaleDecimals>true</forceIntegerTypesOnZeroScaleDecimals><logSlowQueriesAfterSeconds>5</logSlowQueriesAfterSeconds><logSlowResultsAfterSeconds>5</logSlowResultsAfterSeconds><properties><property><key>scripts</key><value>src/main/resources/db/Schema.sql</value></property></properties></database><generate><indexes>true</indexes><relations>true</relations><implicitJoinPathsToOne>true</implicitJoinPathsToOne><deprecated>true</deprecated><deprecationOnUnknownTypes>false</deprecationOnUnknownTypes><instanceFields>true</instanceFields><generatedAnnotation>true</generatedAnnotation><generatedAnnotationType>DETECT_FROM_JDK</generatedAnnotationType><routines>true</routines><sequences>true</sequences><udts>true</udts><queues>true</queues><links>true</links><keys>true</keys><tables>true</tables><embeddables>true</embeddables><records>true</records><recordsImplementingRecordN>true</recordsImplementingRecordN><pojos>true</pojos><pojosEqualsAndHashCode>false</pojosEqualsAndHashCode><pojosToString>true</pojosToString><immutablePojos>false</immutablePojos><serializablePojos>true</serializablePojos><interfaces>false</interfaces><immutableInterfaces>false</immutableInterfaces><serializableInterfaces>true</serializableInterfaces><daos>false</daos><jpaAnnotations>false</jpaAnnotations><validationAnnotations>false</validationAnnotations><springAnnotations>false</springAnnotations><globalObjectReferences>true</globalObjectReferences><globalCatalogReferences>true</globalCatalogReferences><globalSchemaReferences>true</globalSchemaReferences><globalTableReferences>true</globalTableReferences><globalSequenceReferences>true</globalSequenceReferences><globalUDTReferences>true</globalUDTReferences><globalRoutineReferences>true</globalRoutineReferences><globalQueueReferences>true</globalQueueReferences><globalLinkReferences>true</globalLinkReferences><globalKeyReferences>true</globalKeyReferences><javadoc>true</javadoc><comments>true</comments><commentsOnCatalogs>true</commentsOnCatalogs><commentsOnSchemas>true</commentsOnSchemas><commentsOnTables>true</commentsOnTables><commentsOnColumns>true</commentsOnColumns><commentsOnUDTs>true</commentsOnUDTs><commentsOnAttributes>true</commentsOnAttributes><commentsOnPackages>true</commentsOnPackages><commentsOnRoutines>true</commentsOnRoutines><commentsOnParameters>true</commentsOnParameters><commentsOnSequences>true</commentsOnSequences><commentsOnLinks>true</commentsOnLinks><commentsOnQueues>true</commentsOnQueues><commentsOnKeys>true</commentsOnKeys><fluentSetters>false</fluentSetters><javaBeansGettersAndSetters>false</javaBeansGettersAndSetters><varargSetters>true</varargSetters><fullyQualifiedTypes></fullyQualifiedTypes><emptyCatalogs>false</emptyCatalogs><emptySchemas>false</emptySchemas><javaTimeTypes>false</javaTimeTypes><primaryKeyTypes>false</primaryKeyTypes><newline>\n</newline></generate><target><packageName>me.leslie.generals.server.persistence.jooq</packageName><directory>Generals-Server/src/main/java</directory><encoding>UTF-8</encoding><clean>true</clean></target></generator>
19:02:57.424 [main] INFO org.jooq.codegen.GenerationTool - Database : Inferring database org.jooq.meta.sqlite.SQLiteDatabase from URL jdbc:sqlite:
19:02:57.426 [main] INFO org.jooq.codegen.GenerationTool - No <inputCatalog/> was provided. Generating ALL available catalogs instead.
19:02:57.426 [main] INFO org.jooq.codegen.GenerationTool - No <inputSchema/> was provided. Generating ALL available schemata instead.
19:02:57.524 [main] INFO org.jooq.codegen.AbstractGenerator - License parameters
19:02:57.524 [main] INFO org.jooq.codegen.AbstractGenerator - ----------------------------------------------------------
19:02:57.524 [main] INFO org.jooq.codegen.AbstractGenerator - Thank you for using jOOQ and jOOQ's code generator
19:02:57.524 [main] INFO org.jooq.codegen.AbstractGenerator -
19:02:57.524 [main] INFO org.jooq.codegen.AbstractGenerator - Database parameters
19:02:57.524 [main] INFO org.jooq.codegen.AbstractGenerator - ----------------------------------------------------------
19:02:57.524 [main] INFO org.jooq.codegen.AbstractGenerator - dialect : SQLITE
19:02:57.524 [main] INFO org.jooq.codegen.AbstractGenerator - URL : jdbc:sqlite:
19:02:57.524 [main] INFO org.jooq.codegen.AbstractGenerator - target dir : Generals-Server/src/main/java
19:02:57.524 [main] INFO org.jooq.codegen.AbstractGenerator - target package : me.leslie.generals.server.persistence.jooq
19:02:57.524 [main] INFO org.jooq.codegen.AbstractGenerator - includes : [.*]
19:02:57.524 [main] INFO org.jooq.codegen.AbstractGenerator - excludes : []
19:02:57.524 [main] INFO org.jooq.codegen.AbstractGenerator - includeExcludeColumns : false
19:02:57.524 [main] INFO org.jooq.codegen.AbstractGenerator - ----------------------------------------------------------
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator -
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - JavaGenerator parameters
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - ----------------------------------------------------------
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - annotations (generated): true
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - annotations (JPA: any) : false
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - annotations (JPA: version):
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - annotations (validation): false
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - comments : true
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - comments on attributes : true
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - comments on catalogs : true
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - comments on columns : true
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - comments on keys : true
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - comments on links : true
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - comments on packages : true
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - comments on parameters : true
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - comments on queues : true
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - comments on routines : true
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - comments on schemas : true
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - comments on sequences : true
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - comments on tables : true
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - comments on udts : true
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - daos : false
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - deprecated code : true
19:02:57.524 [main] INFO org.jooq.codegen.JavaGenerator - global references (any): true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - global references (catalogs): true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - global references (keys): true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - global references (links): true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - global references (queues): true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - global references (routines): true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - global references (schemas): true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - global references (sequences): true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - global references (tables): true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - global references (udts): true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - indexes : true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - instance fields : true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - interfaces : false
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - interfaces (immutable) : false
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - javadoc : true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - keys : true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - links : true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - pojos : true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - pojos (immutable) : false
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - queues : true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - records : true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - routines : true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - sequences : true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - table-valued functions : true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - tables : true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - udts : true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - relations : true
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - ----------------------------------------------------------
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator -
19:02:57.525 [main] INFO org.jooq.codegen.AbstractGenerator - Generation remarks
19:02:57.525 [main] INFO org.jooq.codegen.AbstractGenerator - ----------------------------------------------------------
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator -
19:02:57.525 [main] INFO org.jooq.codegen.JavaGenerator - ----------------------------------------------------------
19:02:57.526 [main] INFO org.jooq.codegen.JavaGenerator - Generating catalogs : Total: 1
19:02:57.526 [main] INFO org.jooq.meta.AbstractDatabase - ARRAYs fetched : 0 (0 included, 0 excluded)
19:02:57.526 [main] INFO org.jooq.meta.AbstractDatabase - Enums fetched : 0 (0 included, 0 excluded)
19:02:57.526 [main] INFO org.jooq.meta.AbstractDatabase - Packages fetched : 0 (0 included, 0 excluded)
19:02:57.526 [main] INFO org.jooq.meta.AbstractDatabase - Routines fetched : 0 (0 included, 0 excluded)
19:02:57.526 [main] INFO org.jooq.meta.AbstractDatabase - Sequences fetched : 0 (0 included, 0 excluded)
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.jooq.tools.reflect.Reflect (file:/home/leslie/.m2/repository/org/jooq/jooq/3.12.1/jooq-3.12.1.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class)
WARNING: Please consider reporting this to the maintainers of org.jooq.tools.reflect.Reflect
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
19:02:57.725 [main] INFO org.jooq.Constants -
######################################
######################################
################ ## ##########
#################### ##########
################ ## ## ##########
########## #### ## ## ##########
########## ## ##########
######################################
######################################
########## ## ##########
########## ## ## #### ##########
########## ## ## #### ##########
########## ## # # ##########
########## ## ##########
####################### #############
######################################
###################################### Thank you for using jOOQ 3.12.1
19:02:57.732 [main] DEBUG org.jooq.tools.LoggerListener - Executing query : select 1 one
19:02:57.788 [main] DEBUG org.jooq.tools.LoggerListener - Fetched result : +----+
19:02:57.788 [main] DEBUG org.jooq.tools.LoggerListener - : | one|
19:02:57.788 [main] DEBUG org.jooq.tools.LoggerListener - : +----+
19:02:57.788 [main] DEBUG org.jooq.tools.LoggerListener - : | 1|
19:02:57.788 [main] DEBUG org.jooq.tools.LoggerListener - : +----+
19:02:57.788 [main] DEBUG org.jooq.tools.LoggerListener - Fetched row(s) : 1
19:02:57.791 [main] DEBUG org.jooq.tools.LoggerListener - Executing query : select sqlite_master.name from sqlite_master where sqlite_master.type in (?, ?) order by sqlite_master.name
19:02:57.792 [main] DEBUG org.jooq.tools.LoggerListener - -> with bind values : select sqlite_master.name from sqlite_master where sqlite_master.type in ('table', 'view') order by sqlite_master.name
19:02:57.793 [main] DEBUG org.jooq.tools.LoggerListener - Fetched result : +----+
19:02:57.793 [main] DEBUG org.jooq.tools.LoggerListener - : |name|
19:02:57.793 [main] DEBUG org.jooq.tools.LoggerListener - : +----+
19:02:57.793 [main] DEBUG org.jooq.tools.LoggerListener - Fetched row(s) : 0
19:02:57.793 [main] INFO org.jooq.meta.AbstractDatabase - Tables fetched : 0 (0 included, 0 excluded)
19:02:57.793 [main] INFO org.jooq.meta.AbstractDatabase - UDTs fetched : 0 (0 included, 0 excluded)
19:02:57.793 [main] INFO org.jooq.codegen.JavaGenerator - Excluding empty catalog :
19:02:57.793 [main] INFO org.jooq.codegen.JavaGenerator - Removing excess files
Process finished with exit code 0
If you want to use the DDLDatabase as documented in the link you've posted, you should:
remove the JDBC connection parameters
add the DDLDatabase as a database implementation, to replace the default SQLiteDatabase (which is derived from your JDBC connection parameters).
In other words, try this:
public static void runJooqCodeGen() throws Exception {
// Removed this
/* String url = "jdbc:sqlite:";
String driver = "org.sqlite.JDBC"; */
Configuration configuration = new Configuration()/*.withJdbc(new Jdbc()
.withDriver(driver).withUrl(url))*/
.withGenerator(new Generator()
.withDatabase(new Database()
// Added this
.withName("org.jooq.meta.extensions.ddl.DDLDatabase")
.withProperties(new Property()
.withKey("scripts")
.withValue("src/main/resources/db/Schema.sql")))
.withGenerate(new Generate()
.withPojos(Boolean.TRUE)
.withDeprecationOnUnknownTypes(Boolean.FALSE))
.withTarget(new Target()
.withPackageName("me.leslie.generals.server.persistence.jooq")
.withDirectory("Generals-Server/src/main/java")));
GenerationTool.generate(configuration);
}
What are the situations which cause Flux::flatMap to listen to multiple sources (0...infinity) concurrently?
I found out, while experimenting, that when the upstream send signals to flatMap in thread thread-upstream-1 and there are N inner streams which flatMap will listen to and each of them send signals in different thread: thread-inner-stream-i for 1<=i<=N, than for every 1<=i<=N if thread-upstream-1 != thread-inner-stream-i, flatMap will listen concurrently to all the inner streams.
I think that it's not exactly true and I missed some other scenarios.
flatMap doesn't do any parallel work, as in: it doesn't change threads. The simplest example is
Flux.range(1, 5).hide()
.flatMap(v -> Flux.range(10 * v, 2))
.log()
.blockLast(); //for test purpose
This prints:
[main] INFO reactor.Flux.FlatMap.1 - onSubscribe(FluxFlatMap.FlatMapMain)
[main] INFO reactor.Flux.FlatMap.1 - request(unbounded)
[main] INFO reactor.Flux.FlatMap.1 - onNext(10)
[main] INFO reactor.Flux.FlatMap.1 - onNext(11)
[main] INFO reactor.Flux.FlatMap.1 - onNext(20)
[main] INFO reactor.Flux.FlatMap.1 - onNext(21)
[main] INFO reactor.Flux.FlatMap.1 - onNext(30)
[main] INFO reactor.Flux.FlatMap.1 - onNext(31)
[main] INFO reactor.Flux.FlatMap.1 - onNext(40)
[main] INFO reactor.Flux.FlatMap.1 - onNext(41)
[main] INFO reactor.Flux.FlatMap.1 - onNext(50)
[main] INFO reactor.Flux.FlatMap.1 - onNext(51)
[main] INFO reactor.Flux.FlatMap.1 - onComplete()
As you can see, only produces in main. If you add a publishOn after the initial range, flatMap produces everything in the same single thread publishOn will switch to.
What flatMap does however is subscribe to multiple inner Publisher, up to the concurrency parameter with a default of Queues.SMALL_BUFFER_SIZE (256).
That means that if you set it to 3, flatMap will map 3 source elements to their inner Publisher and subscribe to these publishers, but will wait for at least one to complete before it starts mapping more source elements.
If the inner Publisher use publishOn or subscribeOn, then flatMap will naturally let their events occur in the then-defined threads:
Flux.range(1, 5).hide()
.flatMap(v -> Flux.range(v * 10, 2)
.publishOn(Schedulers.newParallel("foo", 3)))
.flatMap(v -> Flux.range(10 * v, 2))
.log()
.blockLast(); //for test purpose
Which prints:
[main] INFO reactor.Flux.FlatMap.1 - onSubscribe(FluxFlatMap.FlatMapMain)
[main] INFO reactor.Flux.FlatMap.1 - request(unbounded)
[foo-1] INFO reactor.Flux.FlatMap.1 - onNext(10)
[foo-1] INFO reactor.Flux.FlatMap.1 - onNext(11)
[foo-1] INFO reactor.Flux.FlatMap.1 - onNext(20)
[foo-1] INFO reactor.Flux.FlatMap.1 - onNext(21)
[foo-1] INFO reactor.Flux.FlatMap.1 - onNext(30)
[foo-1] INFO reactor.Flux.FlatMap.1 - onNext(31)
[foo-4] INFO reactor.Flux.FlatMap.1 - onNext(50)
[foo-4] INFO reactor.Flux.FlatMap.1 - onNext(51)
[foo-4] INFO reactor.Flux.FlatMap.1 - onNext(40)
[foo-4] INFO reactor.Flux.FlatMap.1 - onNext(41)
[foo-4] INFO reactor.Flux.FlatMap.1 - onComplete()
I've setup a riak server on ubuntu.
http://192.168.0.102:8098/ping return "OK"
I'm trying to remotely connect to it using riak java client(2.1.1) using the following code. client.execute() never returns. I'm attaching the log also.
public class Testing {
public static void main(String[] args) throws ExecutionException,
InterruptedException, UnknownHostException {
RiakClient client = RiakClient.newClient(8098, "192.168.0.102");
// put some stuff
Namespace ns = new Namespace("TestBucket");
Location location = new Location(ns, "TestKey");
String myData = "TestValue";
StoreValue store = new StoreValue.Builder(myData)
.withLocation(location).build();
Response rv = client.execute(store); // << NEVER GETS PAST THIS
System.out.println("write done");
// get some stuff
FetchValue fv = new FetchValue.Builder(location).build();
FetchValue.Response response = client.execute(fv);
String obj = response.getValue(String.class);
System.out.println(obj);
System.out.println("fetch done");
}
}
Log on the console is...
17:19:40.841 [main] DEBUG i.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework
17:19:40.865 [main] DEBUG i.n.c.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 16
17:19:40.891 [main] DEBUG i.n.util.internal.PlatformDependent0 - java.nio.Buffer.address: available
17:19:40.892 [main] DEBUG i.n.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available
17:19:40.893 [main] DEBUG i.n.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available
17:19:40.894 [main] DEBUG i.n.util.internal.PlatformDependent0 - direct buffer constructor: available
17:19:40.894 [main] DEBUG i.n.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true
17:19:40.894 [main] DEBUG i.n.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.<init>(long, int): available
17:19:40.896 [main] DEBUG io.netty.util.internal.Cleaner0 - java.nio.ByteBuffer.cleaner(): available
17:19:40.896 [main] DEBUG i.n.util.internal.PlatformDependent - Platform: Windows
17:19:40.897 [main] DEBUG i.n.util.internal.PlatformDependent - Java version: 8
17:19:40.897 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.noUnsafe: false
17:19:40.897 [main] DEBUG i.n.util.internal.PlatformDependent - sun.misc.Unsafe: available
17:19:40.898 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.noJavassist: false
17:19:40.899 [main] DEBUG i.n.util.internal.PlatformDependent - Javassist: unavailable
17:19:40.899 [main] DEBUG i.n.util.internal.PlatformDependent - You don't have Javassist in your class path or you don't have enough permission to load dynamically generated classes. Please check the configuration for better performance.
17:19:40.899 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\Rakesh\AppData\Local\Temp (java.io.tmpdir)
17:19:40.900 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.bitMode: 32 (sun.arch.data.model)
17:19:40.900 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false
17:19:40.900 [main] DEBUG i.n.util.internal.PlatformDependent - io.netty.maxDirectMemory: 259522560 bytes
17:19:40.921 [main] DEBUG io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false
17:19:40.921 [main] DEBUG io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512
17:19:40.922 [main] DEBUG i.n.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available
17:19:41.039 [main] DEBUG io.netty.channel.DefaultChannelId - -Dio.netty.processId: 2924 (auto-detected)
17:19:41.041 [main] DEBUG io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false
17:19:41.041 [main] DEBUG io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false
17:19:41.162 [main] DEBUG io.netty.util.NetUtil - Loopback interface: lo (Software Loopback Interface 1, 127.0.0.1)
17:19:41.163 [main] DEBUG io.netty.util.NetUtil - \proc\sys\net\core\somaxconn: 200 (non-existent)
17:19:41.321 [main] DEBUG io.netty.channel.DefaultChannelId - -Dio.netty.machineId: e4:b3:18:ff:fe:6c:52:eb (auto-detected)
17:19:41.321 [main] DEBUG i.n.util.internal.ThreadLocalRandom - -Dio.netty.initialSeedUniquifier: 0xb620b93d4006e503
17:19:41.333 [main] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple
17:19:41.333 [main] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.maxRecords: 4
17:19:41.355 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 2
17:19:41.355 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 2
17:19:41.355 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192
17:19:41.355 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11
17:19:41.355 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216
17:19:41.355 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512
17:19:41.355 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256
17:19:41.355 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64
17:19:41.355 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768
17:19:41.355 [main] DEBUG i.n.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192
17:19:41.364 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled
17:19:41.365 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 65536
17:19:41.365 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384
17:19:41.406 [main] INFO com.basho.riak.client.core.RiakNode - RiakNode started; 192.168.0.102:8098
17:19:41.407 [main] INFO c.basho.riak.client.core.RiakCluster - RiakCluster is starting.
17:19:41.408 [main] INFO c.b.r.c.core.util.DefaultCharset - No desired charset found in system properties, the default charset 'windows-1252' will be used
17:19:41.408 [main] INFO c.b.r.c.core.util.DefaultCharset - Initializing client charset to: windows-1252
17:19:41.443 [main] DEBUG com.basho.riak.client.core.RiakNode - Attempting to acquire channel permit
17:19:41.445 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 32768
17:19:41.445 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2
17:19:41.445 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16
17:19:41.445 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8
17:19:41.447 [main] DEBUG com.basho.riak.client.core.RiakNode - Operation 28144878 being executed on RiakNode 192.168.0.102:8098
17:19:41.461 [nioEventLoopGroup-2-10] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.bytebuf.checkAccessible: true
17:19:41.463 [nioEventLoopGroup-2-10] DEBUG i.n.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector#1536e36
Call stack of suspended thread
Thread [main] (Suspended)
Unsafe.park(boolean, long) line: not available [native method]
LockSupport.park(Object) line: not available
CountDownLatch$Sync(AbstractQueuedSynchronizer).parkAndCheckInterrupt() line: not available
CountDownLatch$Sync(AbstractQueuedSynchronizer).doAcquireSharedInterruptibly(int) line: not available
CountDownLatch$Sync(AbstractQueuedSynchronizer).acquireSharedInterruptibly(int) line: not available
CountDownLatch.await() line: not available
StoreOperation(FutureOperation<T,U,S>).await() line: 387
GenericRiakCommand$1(CoreFutureAdapter<T2,S2,T,S>).await() line: 90
StoreValue(RiakCommand<T,S>).execute(RiakCluster) line: 92
RiakClient.execute(RiakCommand<T,S>) line: 355
Testing.main(String[]) line: 29
A simple code addition after the following line of your code should fix things for you:
response rv = client.execute(store);
add:
client.shutdown();
to release that connection and continue execution.
Note that you will need to create a new connection for your next request against the database since you closed client or use .executeAsync() in place of .execute().
It appears you are expecting the Riak java client to connect using HTTP API. The Riak java client only connects using protocol buffer; using the HTTP address and port will freeze.
Yoy have to use this, its works fine...
public static void main(String[] args) throws ExecutionException,
InterruptedException, UnknownHostException {
RiakClient client = RiakClient.newClient(8087,"192.168.0.65");
// put some stuff
Namespace ns = new Namespace("TestBucket");
Location location = new Location(ns, "TestKey");
String myData = "TestValue";
StoreValue store = new StoreValue.Builder(myData)
.withLocation(location).build();
client.execute(store); // << NEVER GETS PAST THIS
System.out.println("write done");
// get some stuff
FetchValue fv = new FetchValue.Builder(location).build();
FetchValue.Response response = client.execute(fv);
String obj = response.getValue(String.class);
System.out.println(obj);
System.out.println("fetch done");
}
hope you will also get... !!!
I'm using Storm Flux (0.10.0) DSL to deploy the following topology (simplified to keep only the relevant parts of it):
---
name: "my-topology"
components:
- id: "esConfig"
className: "java.util.HashMap"
configMethods:
- name: "put"
args:
- "es.nodes"
- "${es.nodes}"
bolts:
- id: "es-bolt"
className: "org.elasticsearch.storm.EsBolt"
constructorArgs:
- "myindex/docs"
- ref: "esConfig"
parallelism: 1
# ... other bolts, spouts and streams here
As you can see, one of the bolts I use is org.elasticsearch.storm.EsBolt which has the following constructors (see code):
public EsBolt(String target) { ... }
public EsBolt(String target, boolean writeAck) { ... }
public EsBolt(String target, Map configuration) { ... }
The last one should be called because I pass a String and a Map in the constructorArgs. But when I deploy the topology I get the following exception, as if Flux wasn't able to infer the right constructor from the types (String, Map):
storm jar mytopology-1.0.0.jar org.apache.storm.flux.Flux --local mytopology.yml --filter mytopology.properties
...
Version: 0.10.0
Parsing file: mytopology.yml
958 [main] INFO o.a.s.f.p.FluxParser - loading YAML from input stream...
965 [main] INFO o.a.s.f.p.FluxParser - Performing property substitution.
969 [main] INFO o.a.s.f.p.FluxParser - Not performing environment variable substitution.
1252 [main] INFO o.a.s.f.FluxBuilder - Detected DSL topology...
1431 [main] WARN o.a.s.f.FluxBuilder - Found multiple invokable constructors for class class org.elasticsearch.storm.EsBolt, given arguments [myindex/docs, {es.nodes=localhost}]. Using the last one found.
Exception in thread "main" java.lang.IllegalArgumentException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.apache.storm.flux.FluxBuilder.buildObject(FluxBuilder.java:291)
at org.apache.storm.flux.FluxBuilder.buildBolts(FluxBuilder.java:372)
at org.apache.storm.flux.FluxBuilder.buildTopology(FluxBuilder.java:88)
at org.apache.storm.flux.Flux.runCli(Flux.java:153)
at org.apache.storm.flux.Flux.main(Flux.java:98)
Any idea about what could be happening? Here is how Storm Flux finds a compatible constructor. The magic is in the canInvokeWithArgs method.
These are Flux debug logs, where you see how FluxBuilder finds the most appropriate constructor:
Version: 0.10.0
Parsing file: mytopology.yml
559 [main] INFO o.a.s.f.p.FluxParser - loading YAML from input stream...
566 [main] INFO o.a.s.f.p.FluxParser - Performing property substitution.
569 [main] INFO o.a.s.f.p.FluxParser - Not performing environment variable substitution.
804 [main] INFO o.a.s.f.FluxBuilder - Detected DSL topology...
org.apache.logging.slf4j.Log4jLogger#3b69e7d1
1006 [main] DEBUG o.a.s.f.FluxBuilder - Found constructor arguments in definition: java.util.ArrayList
1006 [main] DEBUG o.a.s.f.FluxBuilder - Checking arguments for references.
1010 [main] DEBUG o.a.s.f.FluxBuilder - Target class: org.elasticsearch.storm.EsBolt
1011 [main] DEBUG o.a.s.f.FluxBuilder - found constructor with same number of args..
1011 [main] DEBUG o.a.s.f.FluxBuilder - Comparing parameter class class java.lang.String to object class class java.lang.String to see if assignment is possible.
1011 [main] DEBUG o.a.s.f.FluxBuilder - Yes, they are the same class.
1012 [main] DEBUG o.a.s.f.FluxBuilder - ** invokable --> true
1012 [main] DEBUG o.a.s.f.FluxBuilder - found constructor with same number of args..
1012 [main] DEBUG o.a.s.f.FluxBuilder - Comparing parameter class class java.lang.String to object class class java.lang.String to see if assignment is possible.
1012 [main] DEBUG o.a.s.f.FluxBuilder - Yes, they are the same class.
1012 [main] DEBUG o.a.s.f.FluxBuilder - ** invokable --> true
1012 [main] DEBUG o.a.s.f.FluxBuilder - Skipping constructor with wrong number of arguments.
1012 [main] WARN o.a.s.f.FluxBuilder - Found multiple invokable constructors for class class org.elasticsearch.storm.EsBolt, given arguments [myindex/docs, {es.nodes=localhost}]. Using the last one found.
1014 [main] DEBUG o.a.s.f.FluxBuilder - Found something seemingly compatible, attempting invocation...
1044 [main] DEBUG o.a.s.f.FluxBuilder - Comparing parameter class class java.lang.String to object class class java.lang.String to see if assignment is possible.
1044 [main] DEBUG o.a.s.f.FluxBuilder - They are the same class.
1044 [main] DEBUG o.a.s.f.FluxBuilder - Comparing parameter class boolean to object class class java.util.HashMap to see if assignment is possible.
Exception in thread "main" java.lang.IllegalArgumentException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.apache.storm.flux.FluxBuilder.buildObject(FluxBuilder.java:291)
...
This issue has been fixed on Nov 18, 2015.
See this: https://github.com/apache/storm/commit/69b9cf581fd977f6c28b3a78a116deddadc44014
And the next version of Storm with this fix should be released within a month.
As a crappy workaround, I've finally extended EsBolt to expose only the constructors I need and avoid collisions.
package com.mypackage;
import java.util.Map;
import org.elasticsearch.storm.EsBolt;
public class EsBoltWrapper extends EsBolt {
public EsBoltWrapper(String target) {
super(target);
}
public EsBoltWrapper(String target, Map configuration) {
super(target, configuration);
}
}
Now my topology looks like this:
bolts:
- id: "es-bolt"
className: "com.mypackage.EsBoltWrapper" # THE NEW CLASS
constructorArgs:
- "myindex/docs"
- ref: "esConfig"
parallelism: 1
It seems to be a bug in Storm Flux.
I am trying to replace a simple 'Place Holderin MS Word 2007 usingDocx4J. I created the placeholder byReference > Insert Citation > Add New Placeholder`
Below is my Docx4J code
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBElement;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.wml.ContentAccessor;
import org.docx4j.wml.Text;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* #author Yohan
*/
public class Main {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
new Main();
}
public Main()
{
try
{
WordprocessingMLPackage template = getTemplate("C:/Users/Yohan/Desktop/Yohan.docx");
replacePlaceholder(template,"Plane","Placeholder1");
writeDocxToStream(template,"C:/Users/Yohan/Desktop/Yohan2.docx");
System.out.println("Operation Completed");
}
catch(Exception e)
{
e.printStackTrace();
}
}
private WordprocessingMLPackage getTemplate(String name) throws Docx4JException, FileNotFoundException {
WordprocessingMLPackage template = WordprocessingMLPackage.load(new FileInputStream(new File(name)));
return template;
}
private static List<Object> getAllElementFromObject(Object obj, Class<?> toSearch) {
List<Object> result = new ArrayList<Object>();
if (obj instanceof JAXBElement) obj = ((JAXBElement<?>) obj).getValue();
if (obj.getClass().equals(toSearch))
result.add(obj);
else if (obj instanceof ContentAccessor) {
List<?> children = ((ContentAccessor) obj).getContent();
for (Object child : children) {
result.addAll(getAllElementFromObject(child, toSearch));
}
}
return result;
}
private void replacePlaceholder(WordprocessingMLPackage template, String name, String placeholder ) {
List<Object> texts = getAllElementFromObject(template.getMainDocumentPart(), Text.class);
for (Object text : texts) {
Text textElement = (Text) text;
if (textElement.getValue().equals(placeholder)) {
textElement.setValue(name);
}
}
}
private void writeDocxToStream(WordprocessingMLPackage template, String target) throws IOException, Docx4JException {
File f = new File(target);
template.save(f);
}
}
This generated the below in Netbeans console.
[main] INFO org.docx4j.jaxb.Context - java.vendor=Oracle Corporation
[main] INFO org.docx4j.jaxb.Context - java.version=1.8.0_05
[main] INFO org.docx4j.jaxb.Context - No MOXy JAXB config found; assume not intended..
[main] INFO org.docx4j.jaxb.NamespacePrefixMapperUtils - Using NamespacePrefixMapperSunInternal, which is suitable for Java 6
[main] INFO org.docx4j.jaxb.Context - Using Java 6/7 JAXB implementation
[main] INFO org.docx4j.jaxb.Context - Not using MOXy; using com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl
[main] WARN org.docx4j.utils.ResourceUtils - Couldn't get resource: docx4j.properties
[main] WARN org.docx4j.Docx4jProperties - Couldn't find/read docx4j.properties; docx4j.properties not found via classloader.
[main] INFO org.docx4j.XmlUtils - Using com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
[main] INFO org.docx4j.XmlUtils - Using com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
[main] INFO org.docx4j.openpackaging.contenttype.ContentTypeManager - Detected WordProcessingML package
[main] INFO org.docx4j.openpackaging.io3.Load3 - Instantiated package of type org.docx4j.openpackaging.packages.WordprocessingMLPackage
[main] INFO org.docx4j.utils.XPathFactoryUtil - xpath implementation: org.apache.xpath.jaxp.XPathFactoryImpl
[main] INFO org.docx4j.openpackaging.io.Load - Found a CustomXmlPart, named /customXml/item1.xml
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - Lazily unmarshalling /customXml/itemProps1.xml
[main] INFO org.docx4j.openpackaging.io.Load - Identified/registered ds:itemId {2da45ade-e2fe-4251-9c73-a623aa57ebb0}
[main] INFO org.docx4j.openpackaging.io3.Load3 - package read; elapsed time: 10932 ms
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - Lazily unmarshalling /word/document.xml
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPartXPathAware - For org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart, unmarshall via binder
[main] INFO org.docx4j.openpackaging.contenttype.ContentTypeManager - marshalling org.docx4j.openpackaging.contenttype.ContentTypeManager ...
[main] INFO org.docx4j.jaxb.NamespacePrefixMapperUtils - Using NamespacePrefixMapperSunInternal, which is suitable for Java 6
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.relationships.RelationshipsPart
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.relationships.RelationshipsPart
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.WordprocessingML.BibliographyPart
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.relationships.RelationshipsPart
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.CustomXmlDataStoragePropertiesPart
[main] INFO org.docx4j.openpackaging.io3.Save - ...Done!
Operation Completed
However in Yohan2.docx, nothing is changed, it is a pure copy of Yohan.docx. What have I done wrong here?
UPDATE
I tested the MERGEFIELD example from the GITHUB but it also didn't work. Below is the output printed in console
[main] INFO org.docx4j.jaxb.Context - java.vendor=Oracle Corporation
[main] INFO org.docx4j.jaxb.Context - java.version=1.8.0_05
[main] INFO org.docx4j.jaxb.Context - No MOXy JAXB config found; assume not intended..
[main] INFO org.docx4j.jaxb.NamespacePrefixMapperUtils - Using NamespacePrefixMapperSunInternal, which is suitable for Java 6
[main] INFO org.docx4j.jaxb.Context - Using Java 6/7 JAXB implementation
[main] INFO org.docx4j.jaxb.Context - Not using MOXy; using com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl
[main] WARN org.docx4j.utils.ResourceUtils - Couldn't get resource: docx4j.properties
[main] WARN org.docx4j.Docx4jProperties - Couldn't find/read docx4j.properties; docx4j.properties not found via classloader.
[main] INFO org.docx4j.XmlUtils - Using com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
[main] INFO org.docx4j.XmlUtils - Using com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
[main] INFO org.docx4j.openpackaging.contenttype.ContentTypeManager - Detected WordProcessingML package
[main] INFO org.docx4j.openpackaging.io3.Load3 - Instantiated package of type org.docx4j.openpackaging.packages.WordprocessingMLPackage
[main] INFO org.docx4j.utils.XPathFactoryUtil - xpath implementation: org.apache.xpath.jaxp.XPathFactoryImpl
[main] WARN org.docx4j.openpackaging.contenttype.ContentTypeManager - DefaultPart used for part '/word/stylesWithEffects.xml' of content type 'application/vnd.ms-word.stylesWithEffects+xml'
[main] INFO org.docx4j.openpackaging.io3.Load3 - package read; elapsed time: 14766 ms
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - Lazily unmarshalling /word/document.xml
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPartXPathAware - For org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart, unmarshall via binder
[main] INFO org.docx4j.model.fields.merge.MailMerger - Found 9 fields
[main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'kundenname'
[main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'kundenname'
[main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'kundenname'
[main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'Kundenname'
[main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'KunDenName'
[main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'KUNDENNAME'
[main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'Kundenstrasse'
[main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'yourdate'
[main] INFO org.docx4j.model.fields.DateFormatInferencer - Infering dates based using International formats
[main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'yournumber'
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - Lazily unmarshalling /word/settings.xml
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPartXPathAware - For org.docx4j.openpackaging.parts.WordprocessingML.DocumentSettingsPart, unmarshall via binder
[main] INFO org.docx4j.openpackaging.contenttype.ContentTypeManager - marshalling org.docx4j.openpackaging.contenttype.ContentTypeManager ...
[main] INFO org.docx4j.jaxb.NamespacePrefixMapperUtils - Using NamespacePrefixMapperSunInternal, which is suitable for Java 6
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.relationships.RelationshipsPart
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.relationships.RelationshipsPart
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.WordprocessingML.DocumentSettingsPart
[main] WARN org.docx4j.openpackaging.parts.WordprocessingML.DocumentSettingsPart -
[main] INFO org.docx4j.openpackaging.io3.Save - ...Done!
[main] INFO org.docx4j.model.fields.merge.MailMerger - Found 9 fields
[main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'kundenname'
[main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'kundenname'
[main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'kundenname'
[main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'Kundenname'
[main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'KunDenName'
[main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'KUNDENNAME'
[main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'Kundenstrasse'
[main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'yourdate'
[main] INFO org.docx4j.model.fields.merge.MailMerger - Key: 'yournumber'
[main] INFO org.docx4j.openpackaging.contenttype.ContentTypeManager - marshalling org.docx4j.openpackaging.contenttype.ContentTypeManager ...
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.relationships.RelationshipsPart
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.relationships.RelationshipsPart
[main] INFO org.docx4j.openpackaging.parts.JaxbXmlPart - marshalling org.docx4j.openpackaging.parts.WordprocessingML.DocumentSettingsPart
[main] WARN org.docx4j.openpackaging.parts.WordprocessingML.DocumentSettingsPart -
[main] INFO org.docx4j.openpackaging.io3.Save - ...Done!
A placeholder inserted via Reference > Insert Citation > Add New Placeholder results in something like:
<w:sdt>
<w:sdtPr>
<w:id w:val="-963732549"/>
<w:citation/>
</w:sdtPr>
<w:sdtContent>
<w:r>
<w:fldChar w:fldCharType="begin"/>
</w:r>
<w:r>
<w:rPr>
<w:lang w:val="en-AU"/>
</w:rPr>
<w:instrText xml:space="preserve"> CITATION PL1 \l 3081 </w:instrText>
</w:r>
<w:r>
<w:fldChar w:fldCharType="separate"/>
</w:r>
<w:r>
<w:rPr>
<w:noProof/>
<w:lang w:val="en-AU"/>
</w:rPr>
<w:t>(PL1)</w:t>
</w:r>
<w:r>
<w:fldChar w:fldCharType="end"/>
</w:r>
</w:sdtContent>
</w:sdt>
ie a CITATION field wrapped in a content control.
docx4j has an API for replacing MERGEFIELD and DOCPROPERTY fields, but not CITATION fields.
Is there a particular reason you are trying to use a CITATION field?
If you can swap to MERGEFIELD or DOCPROPERTY field, I'd do that. Otherwise, you could examine docx4j's code for handling those, and adapt it to handling CITATION.
Place Holder in Insert > Quick Parts > Field
Select MergeField
Copy merge field name as appears in the document together with the arrow characters to your code.
replacePlaceholder(template,"Plane","placeholdernamewitharrowcharacters");