1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.miloss.fgsms.agentcore;
23
24 import java.util.ArrayList;
25 import java.util.List;
26 import org.miloss.fgsms.common.Logger;;
27 import org.miloss.fgsms.plugins.agents.IEndpointDiscovery;
28
29
30
31
32
33 public abstract class HelperBase {
34
35 static ConfigLoader cfg = null;
36
37 private static void Init() throws ConfigurationException {
38 if (cfg == null) {
39 cfg = new ConfigLoader();
40 }
41
42 }
43 static Logger log = Logger.getLogger(org.miloss.fgsms.common.Constants.LoggerName);
44 static List<IEndpointDiscovery> endpointproviders=null;
45
46
47
48
49
50
51 public static void discoverEndpoints() throws ConfigurationException {
52 Init();
53 if (cfg == null || cfg.prop == null) {
54 throw new NullPointerException("fgsms properties file is not available.");
55 }
56 if (endpointproviders == null) {
57 endpointproviders = DataPusher.LoadEndpointProviders(cfg);
58 }
59 List<String> endpointspcs = new ArrayList<String>();
60 List<String> endpointsdcs = new ArrayList<String>();
61 List<String> endpointsss = new ArrayList<String>();
62 boolean ran = false;
63 for (int i = 0; i < endpointproviders.size(); i++) {
64 if ((System.currentTimeMillis() - cfg.discoveryInterval) > endpointproviders.get(i).GetLastLookup()) {
65 if (endpointproviders.get(i).IsEnabled()) {
66 endpointspcs.addAll(endpointproviders.get(i).GetPCSURLs());
67 endpointsdcs.addAll(endpointproviders.get(i).GetDCSURLs());
68 endpointsss.addAll(endpointproviders.get(i).GetSSURLs());
69 ran = true;
70 endpointproviders.get(i).SetLastLookup(System.currentTimeMillis());
71 }
72 }
73
74 }
75 if (ran) {
76 for (int i = 0; i < endpointspcs.size(); i++) {
77 if (!cfg.PCS_URLS.contains(endpointspcs.get(i))) {
78 cfg.PCS_URLS.add(endpointspcs.get(i));
79 }
80 }
81 for (int i = 0; i < endpointspcs.size(); i++) {
82 if (!cfg.DCS_URLS.contains(endpointsdcs.get(i))) {
83 cfg.DCS_URLS.add(endpointsdcs.get(i));
84 }
85 }
86 for (int i = 0; i < endpointsss.size(); i++) {
87 if (!cfg.SS_URLS.contains(endpointsss.get(i))) {
88 cfg.SS_URLS.add(endpointsss.get(i));
89 }
90 }
91 }
92
93 }
94 }