12
12
import org .fugerit .java .core .function .SafeFunction ;
13
13
import org .fugerit .java .core .io .StreamIO ;
14
14
import org .fugerit .java .core .lang .helpers .StringUtils ;
15
+ import org .fugerit .java .core .util .checkpoint .SimpleCheckpoint ;
15
16
import org .fugerit .java .doc .base .config .DocInput ;
16
17
import org .fugerit .java .doc .base .config .DocOutput ;
17
18
import org .fugerit .java .doc .base .config .DocTypeHandler ;
@@ -49,9 +50,11 @@ public class GenerateFacade {
49
50
50
51
private void doHandle ( DocTypeHandler handler , String type , int sourceType , Reader reader , ByteArrayOutputStream baos ) {
51
52
SafeFunction .apply ( () -> {
53
+ SimpleCheckpoint checkpoint = new SimpleCheckpoint ();
52
54
DocInput docInput = DocInput .newInput ( type , reader , sourceType );
53
55
DocOutput docOutput = DocOutput .newOutput ( baos );
54
56
handler .handle (docInput , docOutput );
57
+ log .info ( "actual render, handler : {}, type : {}, sourceType : {}, time : {}" , handler .getClass ().getSimpleName (), type , sourceType , checkpoint .getFormatTimeDiffMillis () );
55
58
} );
56
59
}
57
60
@@ -83,23 +86,30 @@ private void handleConfiguration( Configuration configuration, JsonNode node, St
83
86
configuration .setTemplateExceptionHandler ( TemplateExceptionHandler .RETHROW_HANDLER );
84
87
configuration .setTemplateLoader ( loader );
85
88
}
86
-
89
+
87
90
private void handleFtlx ( DocTypeHandler handler , String type , int sourceType , Reader reader , ByteArrayOutputStream baos , String freemarkerJsonData ) {
88
91
SafeFunction .apply ( () -> {
92
+ SimpleCheckpoint checkpoint = new SimpleCheckpoint ();
89
93
// volatile FreeMarker Template configuration
90
94
String chainId = "current_" +System .currentTimeMillis ();
91
95
Configuration configuration = new Configuration ( new Version ( FreeMarkerConfigStep .ATT_FREEMARKER_CONFIG_KEY_VERSION_LATEST ) );
96
+ log .info ( "ftlx create configuration : {}" , checkpoint .getFormatTimeDiffMillis () );
92
97
ObjectMapper mapper = new ObjectMapper ();
93
98
try ( StringReader jsonReader = new StringReader (freemarkerJsonData ) ) {
94
99
JsonNode node = mapper .readTree ( jsonReader ); // parse json node to sanitize input
100
+ log .info ( "read json : {}" , checkpoint .getFormatTimeDiffMillis () );
95
101
this .handleConfiguration (configuration , node , StreamIO .readString ( reader ), chainId );
102
+ log .info ( "ftlx handle configuration : {}" , checkpoint .getFormatTimeDiffMillis () );
96
103
Template currentChain = configuration .getTemplate ( chainId );
104
+ log .info ( "ftlx get template : {}" , checkpoint .getFormatTimeDiffMillis () );
97
105
Map <Object , Object > data = new HashMap <>();
98
106
data .put ( "messageFormat" , new SimpleMessageFun () );
99
107
try ( StringWriter writer = new StringWriter () ) {
100
108
currentChain .process ( data , writer );
109
+ log .info ( "ftlx process chain : {}" , checkpoint .getFormatTimeDiffMillis () );
101
110
try ( StringReader ftlReader = new StringReader ( writer .toString () ) ) {
102
111
this .doHandle (handler , type , sourceType , ftlReader , baos );
112
+ log .info ( "ftlx render document : {}" , checkpoint .getFormatTimeDiffMillis () );
103
113
}
104
114
}
105
115
}
@@ -109,18 +119,27 @@ private void handleFtlx( DocTypeHandler handler, String type, int sourceType, Re
109
119
110
120
private void handleKts ( DocTypeHandler handler , String type , Reader reader , ByteArrayOutputStream baos , String ktsJsonData ) {
111
121
SafeFunction .apply ( () -> {
122
+ SimpleCheckpoint checkpoint = new SimpleCheckpoint ();
112
123
ScriptEngineManager manager = new ScriptEngineManager ();
124
+ log .info ( "kts create script manager : {}" , checkpoint .getFormatTimeDiffMillis () );
113
125
ScriptEngine engine = manager .getEngineByExtension ( "kts" );
126
+ log .info ( "kts create script engine : {}" , checkpoint .getFormatTimeDiffMillis () );
114
127
Bindings bindings = engine .createBindings ();
128
+ log .info ( "kts create script bindings : {}" , checkpoint .getFormatTimeDiffMillis () );
115
129
ObjectMapper mapper = new ObjectMapper ();
116
130
try ( StringReader jsonReader = new StringReader (ktsJsonData ) ) {
117
131
LinkedHashMap data = mapper .readValue ( jsonReader , LinkedHashMap .class );
132
+ log .info ( "kts read json data : {}" , checkpoint .getFormatTimeDiffMillis () );
118
133
bindings .put ( "data" , data );
119
134
engine .setBindings ( bindings , ScriptContext .ENGINE_SCOPE );
135
+ log .info ( "kts set bindings : {}" , checkpoint .getFormatTimeDiffMillis () );
120
136
Object obj = engine .eval ( StreamIO .readString ( reader ) );
137
+ log .info ( "kts eval script : {}" , checkpoint .getFormatTimeDiffMillis () );
121
138
String xml = obj .toString ();
139
+ log .info ( "kts toXml : {}" , checkpoint .getFormatTimeDiffMillis () );
122
140
try ( StringReader xmlReader = new StringReader ( xml ) ) {
123
141
this .doHandle (handler , type , DocFacadeSource .SOURCE_TYPE_XML , xmlReader , baos );
142
+ log .info ( "kts render document : {}" , checkpoint .getFormatTimeDiffMillis () );
124
143
}
125
144
}
126
145
} );
0 commit comments