1818import java .io .BufferedReader ;
1919import java .io .IOException ;
2020import java .io .InputStreamReader ;
21- import java .lang .reflect .Constructor ;
22- import java .lang .reflect .InvocationTargetException ;
2321import java .net .URL ;
2422import java .util .ArrayList ;
2523import java .util .Collections ;
2927import java .util .Map ;
3028import java .util .concurrent .ConcurrentHashMap ;
3129
32- import io .seata .common .Constants ;
3330import io .seata .common .executor .Initialize ;
3431import io .seata .common .util .CollectionUtils ;
3532
@@ -105,48 +102,12 @@ public static <S> S load(Class<S> service, String activateName, ClassLoader load
105102 return loadFile (service , activateName , loader );
106103 }
107104
108- /**
109- * Load s.
110- *
111- * @param <S> the type parameter
112- * @param service the service
113- * @param activateName the activate name
114- * @param args the args
115- * @return the s
116- * @throws EnhancedServiceNotFoundException the enhanced service not found exception
117- */
118- public static <S > S load (Class <S > service , String activateName , Object [] args ) throws EnhancedServiceNotFoundException {
119- Class [] argsType = null ;
120- if (args != null && args .length > 0 ){
121- argsType = new Class [args .length ];
122- for (int i = 0 ; i < args .length ; i ++){
123- argsType [i ] = args [i ].getClass ();
124- }
125- }
126- return loadFile (service , activateName , findClassLoader (), argsType , args );
127- }
128-
129- /**
130- * Load s.
131- *
132- * @param <S> the type parameter
133- * @param service the service
134- * @param activateName the activate name
135- * @param argsType the args type
136- * @param args the args
137- * @return the s
138- * @throws EnhancedServiceNotFoundException the enhanced service not found exception
139- */
140- public static <S > S load (Class <S > service , String activateName , Class [] argsType , Object [] args ) throws EnhancedServiceNotFoundException {
141- return loadFile (service , activateName , findClassLoader (), argsType , args );
142- }
143-
144105 /**
145106 * get all implements
146107 *
147108 * @param <S> the type parameter
148109 * @param service the service
149- * @return list list
110+ * @return list
150111 */
151112 public static <S > List <S > loadAll (Class <S > service ) {
152113 List <S > allInstances = new ArrayList <>();
@@ -156,7 +117,7 @@ public static <S> List<S> loadAll(Class<S> service) {
156117 }
157118 try {
158119 for (Class clazz : allClazzs ) {
159- allInstances .add (initInstance (service , clazz , null , null ));
120+ allInstances .add (initInstance (service , clazz ));
160121 }
161122 } catch (Throwable t ) {
162123 throw new EnhancedServiceNotFoundException (t );
@@ -189,12 +150,8 @@ public static <S> List<Class> getAllExtensionClass(Class<S> service, ClassLoader
189150 return findAllExtensionClass (service , null , loader );
190151 }
191152
153+ @ SuppressWarnings ("rawtypes" )
192154 private static <S > S loadFile (Class <S > service , String activateName , ClassLoader loader ) {
193- return loadFile (service , activateName , loader , null , null );
194- }
195-
196- @ SuppressWarnings ("rawtypes" )
197- private static <S > S loadFile (Class <S > service , String activateName , ClassLoader loader , Class [] argTypes , Object [] args ) {
198155 try {
199156 boolean foundFromCache = true ;
200157 List <Class > extensions = providers .get (service );
@@ -216,7 +173,7 @@ private static <S> S loadFile(Class<S> service, String activateName, ClassLoader
216173 Class clz = extensions .get (i );
217174 @ SuppressWarnings ("unchecked" )
218175 LoadLevel activate = (LoadLevel )clz .getAnnotation (LoadLevel .class );
219- if (activate != null && activateName .equalsIgnoreCase (activate .name ())) {
176+ if (activate != null && activateName .equals (activate .name ())) {
220177 activateExtensions .add (clz );
221178 }
222179 }
@@ -230,7 +187,7 @@ private static <S> S loadFile(Class<S> service, String activateName, ClassLoader
230187 + "] and classloader : " + ObjectUtils .toString (loader ));
231188 }
232189 Class <?> extension = extensions .get (extensions .size () - 1 );
233- S result = initInstance (service , extension , argTypes , args );
190+ S result = initInstance (service , extension );
234191 if (!foundFromCache && LOGGER .isInfoEnabled ()) {
235192 LOGGER .info ("load " + service .getSimpleName () + "[" + activateName + "] extension by class[" + extension
236193 .getName () + "]" );
@@ -302,7 +259,7 @@ private static void loadFile(Class<?> service, String dir, ClassLoader classLoad
302259 java .net .URL url = urls .nextElement ();
303260 BufferedReader reader = null ;
304261 try {
305- reader = new BufferedReader (new InputStreamReader (url .openStream (), Constants . DEFAULT_CHARSET ));
262+ reader = new BufferedReader (new InputStreamReader (url .openStream (), "utf-8" ));
306263 String line = null ;
307264 while ((line = reader .readLine ()) != null ) {
308265 final int ci = line .indexOf ('#' );
@@ -335,26 +292,13 @@ private static void loadFile(Class<?> service, String dir, ClassLoader classLoad
335292 * @param <S> the type parameter
336293 * @param service the service
337294 * @param implClazz the impl clazz
338- * @param argTypes the arg types
339- * @param args the args
340- * @return s s
341- * @throws IllegalAccessException the illegal access exception
342- * @throws InstantiationException the instantiation exception
343- * @throws NoSuchMethodException the no such method exception
344- * @throws InvocationTargetException the invocation target exception
295+ * @return s
296+ * @throws IllegalAccessException the illegal access exception
297+ * @throws InstantiationException the instantiation exception
345298 */
346- protected static <S > S initInstance (Class <S > service , Class implClazz , Class [] argTypes , Object [] args )
347- throws IllegalAccessException , InstantiationException , NoSuchMethodException , InvocationTargetException {
348- S s = null ;
349- if (argTypes != null && args != null ){
350- // Constructor with arguments
351- Constructor <S > constructor = implClazz .getDeclaredConstructor (argTypes );
352- constructor .setAccessible (true );
353- s = service .cast (constructor .newInstance (args ));
354- }else {
355- // default Constructor
356- s = service .cast (implClazz .newInstance ());
357- }
299+ protected static <S > S initInstance (Class <S > service , Class implClazz )
300+ throws IllegalAccessException , InstantiationException {
301+ S s = service .cast (implClazz .newInstance ());
358302 if (s instanceof Initialize ) {
359303 ((Initialize )s ).init ();
360304 }
0 commit comments