12
12
13
13
import com .sun .istack .NotNull ;
14
14
import com .sun .istack .logging .Logger ;
15
+ import com .sun .xml .ws .api .server .Container ;
15
16
import com .sun .xml .ws .assembler .dev .ClientTubelineAssemblyContext ;
16
17
import com .sun .xml .ws .assembler .dev .ServerTubelineAssemblyContext ;
17
18
import com .sun .xml .ws .resources .TubelineassemblyMessages ;
23
24
import java .net .URISyntaxException ;
24
25
import java .util .Collection ;
25
26
import java .util .LinkedList ;
27
+ import java .util .Map ;
28
+ import java .util .concurrent .ConcurrentHashMap ;
29
+ import java .util .concurrent .locks .ReentrantLock ;
26
30
27
31
/**
28
32
*
@@ -32,6 +36,11 @@ final class TubelineAssemblyController {
32
36
33
37
private final MetroConfigName metroConfigName ;
34
38
39
+ private static final Map <Container , TubeFactoryList > tubeFactoryListCache = new ConcurrentHashMap <>();
40
+ private static final ReentrantLock cacheLock = new ReentrantLock ();
41
+ private static final int MAX_CACHE_SIZE = 100 ;
42
+
43
+
35
44
TubelineAssemblyController (MetroConfigName metroConfigName ) {
36
45
this .metroConfigName = metroConfigName ;
37
46
}
@@ -59,8 +68,21 @@ Collection<TubeCreator> getTubeCreators(ClientTubelineAssemblyContext context) {
59
68
endpointUri = null ;
60
69
}
61
70
62
- MetroConfigLoader configLoader = new MetroConfigLoader (context .getContainer (), metroConfigName );
63
- return initializeTubeCreators (configLoader .getClientSideTubeFactories (endpointUri ));
71
+ TubeFactoryList tubeFactoryList = tubeFactoryListCache .get (context .getContainer ());
72
+ if (tubeFactoryList == null ) {
73
+ MetroConfigLoader configLoader = new MetroConfigLoader (context .getContainer (), metroConfigName );
74
+ tubeFactoryList = configLoader .getClientSideTubeFactories (endpointUri );
75
+ cacheLock .lock ();
76
+ try {
77
+ if (tubeFactoryListCache .size () >= MAX_CACHE_SIZE ) {
78
+ tubeFactoryListCache .remove (tubeFactoryListCache .keySet ().iterator ().next ());
79
+ }
80
+ tubeFactoryListCache .put (context .getContainer (), tubeFactoryList );
81
+ } finally {
82
+ cacheLock .unlock ();
83
+ }
84
+ }
85
+ return initializeTubeCreators (tubeFactoryList );
64
86
}
65
87
66
88
/**
0 commit comments