File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed
PluginCore/src/com/plugin/core/localservice Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .plugin .core .localservice ;
2
+
3
+ /**
4
+ * Created by cailiming on 16/1/1.
5
+ *
6
+ * 所有context公用
7
+ *
8
+ */
9
+ public abstract class LocalServiceFetcher {
10
+ int mServiceId ;
11
+ private Object mCachedInstance ;
12
+
13
+ public final Object getService () {
14
+ synchronized (LocalServiceFetcher .this ) {
15
+ Object service = mCachedInstance ;
16
+ if (service != null ) {
17
+ return service ;
18
+ }
19
+ return mCachedInstance = createService (mServiceId );
20
+ }
21
+ }
22
+
23
+ public abstract Object createService (int serviceId );
24
+
25
+ }
Original file line number Diff line number Diff line change
1
+ package com .plugin .core .localservice ;
2
+
3
+ import java .util .HashMap ;
4
+
5
+ /**
6
+ * Created by cailiming on 16/1/1.
7
+ */
8
+ public class LocalServiceManager {
9
+
10
+ private static final HashMap <String , LocalServiceFetcher > SYSTEM_SERVICE_MAP =
11
+ new HashMap <String , LocalServiceFetcher >();
12
+
13
+ private LocalServiceManager () {
14
+ }
15
+
16
+ public static void registerService (String serviceName , LocalServiceFetcher fetcher ) {
17
+ fetcher .mServiceId ++;
18
+ SYSTEM_SERVICE_MAP .put (serviceName , fetcher );
19
+ }
20
+
21
+ public static Object getService (String name ) {
22
+ LocalServiceFetcher fetcher = SYSTEM_SERVICE_MAP .get (name );
23
+ return fetcher == null ? null : fetcher .getService ();
24
+ }
25
+
26
+ }
You can’t perform that action at this time.
0 commit comments