00001 package DisplayGUI;
00002
00003 import java.util.regex.*;
00004 import java.util.*;
00005 import is.*;
00006 import Sct.Serializable;
00007 import Sct.IS.*;
00008 import Sct_CalibrationController.TestData;
00009
00010
00011
00012
00013
00014
00019 public class ISCounter {
00020 final java.util.regex.Pattern objectPattern = java.util.regex.Pattern.compile(".*TestData\\.[0-9]+\\.[0-9]+");
00021 List masterList = new ArrayList();
00022 String[] serverNames = {SctNames.getEventISServer(),SctNames.getFitISServer(),SctNames.getTestISServer(),
00023 "RetrievedData","RetrievedData","RetrievedData"};
00024 String[] serverRegexs = {
00025 SctNames.getEventISServer()+".*SctData",
00026 SctNames.getFitISServer()+".*SctData",
00027 SctNames.getTestISServer()+".*SctData",
00028 "RetrievedData.*SctData::RawScanResult",
00029 "RetrievedData.*SctData::FitScanResult",
00030 "RetrievedData.*SctData.*TestResult"
00031 };
00032
00033
00034 HashMap m;
00035 Pattern oPattern = Pattern.compile("(.*)\\.SctData::.*\\.(\\d+\\.\\d+)\\.(\\d{14})");
00036
00037 private boolean requestUpdate=false;
00038
00039 public ISCounter() {
00040 m = new HashMap();
00041 masterList = new ArrayList();
00042 }
00043 public void refresh(String regex) {
00044 m = new HashMap();
00045 masterList = new ArrayList();
00046 readIS(regex);
00047 }
00048
00049 public synchronized void readIS(String regex) {
00050
00051
00052 GuiComponents.System.ISInterface is = GuiComponents.System.ISInterface.getInstance();
00053
00054
00055 String[] objects;
00056
00057
00058
00059 for(int j=0;j<serverRegexs.length;j++) {
00060 m.put(serverRegexs[j]+regex+"(\\d{14})", new HashMap());
00061 }
00062
00063
00064
00065
00066 for(int j=0;j<serverNames.length;j++) {
00067 switch(j) {
00068 case 3:
00069 objects = is.getISObjects(serverNames[j],".*RawScanResult.*"+regex+".*");
00070 break;
00071 case 4:
00072 objects = is.getISObjects(serverNames[j],".*FitScanResult.*"+regex+".*");
00073 break;
00074 case 5:
00075 objects = is.getISObjects(serverNames[j],".*TestResult.*"+regex+".*");
00076 break;
00077 default:
00078 objects = is.getISObjects(serverNames[j],regex+".*");
00079 }
00080 for(int o=0;o<objects.length;o++) {
00081 Matcher matcher2 = oPattern.matcher(objects[o]);
00082 if(!matcher2.matches()) continue;
00083 masterList.add(objects[o]);
00084 String regexKey=null;
00085 String sn=null;
00086 ILOOP:
00087 for (Iterator i=m.entrySet().iterator(); i.hasNext(); ) {
00088 Map.Entry e = (Map.Entry)i.next();
00089 String thisRegex = (String)e.getKey();
00090 Pattern rPattern = Pattern.compile(thisRegex);
00091 Matcher matcher = rPattern.matcher(objects[o]);
00092 if(matcher.matches()) {
00093 sn=objects[o].substring(matcher.start(2),matcher.end(2));
00094 regexKey = thisRegex;
00095 break ILOOP;
00096 }
00097 }
00098 if(regexKey==null || sn==null) {
00099 System.out.println("SctGUI::ISCounter: No key/sn found for "+objects[o]+" !!!");
00100 continue;
00101 }
00102 Map sm = (HashMap)m.get(regexKey);
00103 List snList = (List)sm.get(sn);
00104 if(snList==null) snList = new ArrayList();
00105 snList.add(objects[o]);
00106
00107 sm.put(sn,snList);
00108 masterList.add(objects[o]);
00109 }
00110 }
00111
00112
00113 }
00114
00115 public synchronized Map getModuleMap(int serverIndex,String regex, boolean isRetrievedData) {
00116 if(regex==null) return null;
00117 if(isRetrievedData) serverIndex+=3;
00118 String mRegex = serverRegexs[serverIndex]+regex+"(\\d{14})";
00119 return (Map)m.get(mRegex);
00120
00121 }
00122 public synchronized List getModuleList(int serverIndex, String regex, String sn, boolean isRetrievedData) {
00123 if(regex==null) return null;
00124 if(isRetrievedData) serverIndex+=3;
00125 String mRegex = serverRegexs[serverIndex]+regex+"(\\d{14})";
00126
00127 Map sm = (HashMap)m.get(mRegex);
00128 if(sm==null) return null;
00129 return (List)sm.get(sn);
00130 }
00131
00132 public synchronized void addObject(String objectName) {
00133
00134 Matcher matcher2 = oPattern.matcher(objectName);
00135 if(!matcher2.matches()) return;
00136 if(masterList.contains(objectName)) return;
00137 String regexKey=null,sn=null;
00138 for (Iterator i=m.entrySet().iterator(); i.hasNext(); ) {
00139 Map.Entry e = (Map.Entry)i.next();
00140 String regex = (String)e.getKey();
00141 Pattern rPattern = Pattern.compile(regex);
00142 Matcher matcher = rPattern.matcher(objectName);
00143 if(matcher.matches()) {
00144 sn=objectName.substring(matcher.start(2),matcher.end(2));
00145 regexKey = regex;
00146 break;
00147 }
00148 }
00149 if(regexKey==null || sn==null) {
00150
00151 return;
00152 }
00153 Map sm = (Map)m.get(regexKey);
00154 List snList = (List)sm.get(sn);
00155 if(snList==null) snList = new ArrayList();
00156 snList.add(objectName);
00157 sm.put(sn,snList);
00158 masterList.add(objectName);
00159 }
00160
00161 public synchronized boolean archivedObjectsRetrievedOk(int serverIndex, String regex) {
00162
00163 GuiComponents.System.ISInterface is = GuiComponents.System.ISInterface.getInstance();
00164
00165 if(!m.containsKey(serverRegexs[serverIndex+3]+regex+"(\\d{14})")) {
00166 System.out.println("SctGUI::IsCounter - ERROR No key for "+serverRegexs[serverIndex+3]+regex+"(\\d{14})");
00167 return false;
00168 }
00169 Map sm = (HashMap)m.get(serverRegexs[serverIndex+3]+regex+"(\\d{14})");
00170 return (sm.size()>0);
00171 }
00172
00173
00174 }
00175
00176
00177
00178
00179
00180
00181