ISInterface.java

00001 /*
00002  * ISInterface.java
00003  *
00004  * Created on 06 November 2003, 17:16
00005  */
00006 
00007 package GuiComponents.System;
00008 
00009 import ipc.*;
00010 import is.*;
00011 
00021 public class ISInterface {
00022     
00026     public static ISInterface getInstance() {
00027         return instance;
00028     }
00029         
00033     public void refresh() {
00034         r = null;
00035     }
00036     
00041     public String[] getISServers() {
00042         try {
00043             is.ServerIterator sit = new is.ServerIterator(si.getPartition());
00044             String[] servers = new String[sit.entries()];
00045             for (int i=0; i<sit.entries(); ++i) {
00046                 servers[i] = sit.nextServerName();
00047             }
00048             return servers;
00049         } catch (NullPointerException npe) { //Caused by partition not available
00050             return new String[0];
00051         }
00052     }
00053     
00058     public String[] getISObjects(String server) {
00059         try {
00060             InfoList l = new InfoList(si.getPartition(), server);
00061             String[] objects = new String[l.getSize()];
00062             AnyInfo info;
00063             for (int i=0; i<l.getSize(); i++) {
00064                 info = l.getInfo(i);
00065                 objects[i] = new String(info.getName()); 
00066             }
00067             return objects;
00068         } catch (NullPointerException npe) { //Caused by partition not available
00069             return new String[0];
00070         }
00071     }
00072     
00073     public int getNumberOfISObjects(String server, String pattern) {
00074         if (si.getPartition()==null) return 0;
00075         InfoList l = new InfoList(si.getPartition(), server, pattern);
00076         return l.getSize();
00077     }
00078     
00079     public String[] getISObjects(String server, String pattern) {
00080         if (si.getPartition()==null) return new String[0];
00081         InfoList l = new InfoList(si.getPartition(), server, pattern);
00082         String[] objects = new String[l.getSize()];
00083         AnyInfo info;
00084         for (int i=0; i<l.getSize(); i++) {
00085             info = l.getInfo(i);
00086             objects[i] = new String(info.getName()); 
00087         }
00088         return objects;
00089     }
00090     
00091     public Repository getRepository() {
00092         if (r == null) {
00093             try {
00094                 Partition p = si.getPartition();
00095                 r = new SctRepository(p);
00096             } catch (NullPointerException npe) {
00097                 //Do nothing - this must have been caused by not being able to get the partition, which we've already logged
00098             }
00099         }
00100         return r;
00101     }
00102     
00103 
00110     public String subscribe(String server, String regex, InfoListener l) {
00111         try {
00112             getRepository().subscribe(server, new Criteria(regex), l);
00113         } catch (RepositoryNotFoundException rnfe) {
00114             return "Internal error while subscribing to server " +server +" for " + regex + " : " + rnfe;
00115         } catch (InvalidCriteriaException iee) {
00116             return "Internal error while subscribing to server " +server +" for " + regex + " : " + iee;
00117         } catch (NullPointerException npe) {
00118             return "Couldn't get repository - see logs";
00119         }
00120 
00121         return "Subscribe to " + server + " with regex " + regex + " successful";
00122     }
00123 
00124    public String subscribe(String infoName, InfoListener l) {
00125         try {
00126             getRepository().subscribe(infoName, l);
00127         } catch (RepositoryNotFoundException rnfe) {
00128             return "Internal error while subscribing to "+ infoName + " : " + rnfe;
00129         } catch (InvalidNameException iee) {
00130             return "InvalidName error while subscribing to " + infoName + " : " + iee;
00131         } catch (NullPointerException npe) {
00132             return "Couldn't get repository - see logs";
00133         }
00134 
00135         return "Subscribe to " + infoName + " successful";
00136     }
00137 
00138     public String subscribe(String server, String regex, boolean isRegex, InfoListener l) {        
00139         try {
00140             getRepository().subscribe(server, regex, isRegex, l);
00141         } catch (RepositoryNotFoundException rnfe) {
00142             return "Internal error while subscribing to server " +server +" for " + regex + " : " + rnfe;
00143         } catch (InvalidCriteriaException iee) {
00144             return "Internal error while subscribing to server " +server +" for " + regex + " : " + iee;
00145         } catch (NullPointerException npe) {
00146             return "Couldn't get repository - see logs";
00147         }
00148 
00149         return "Subscribe to " + server + " with regex " + regex + " successful";
00150     }
00151 
00152 //    public String subscribe(String server, InfoListener l) {
00153 //           return subscribe(server, ".*", l);
00154 //    }
00155     
00156     public String unsubscribe(String infoName) {
00157         try {
00158             getRepository().unsubscribe(infoName);
00159         } catch (RepositoryNotFoundException rnfe) {
00160             return "Oops, internal error while unsubscribing: " + rnfe;
00161         } catch (SubscriptionNotFoundException snfe) {
00162             return "Ooops, internal error - subscription not found: " + snfe;
00163         } catch (InvalidNameException npe) {
00164             return "Ooops, InvalidName error : " + npe;
00165         }
00166 
00167         return "Unsubscribe from " + infoName + " successful";
00168     }
00169 
00170     public String unsubscribe(String server, String regex) {
00171         try {
00172             getRepository().unsubscribe(server, new Criteria(regex));
00173         } catch (RepositoryNotFoundException rnfe) {
00174             return "Oops, internal error while unsubscribing: " + rnfe;
00175         } catch (SubscriptionNotFoundException snfe) {
00176             return "Ooop, internal error - subscription not found: " + snfe;
00177         } catch (NullPointerException npe) {
00178             return "Couldn't get repository - see logs";
00179         }
00180 
00181         return "Unsubscribe from " + server + " for " + regex + " successful";
00182     }
00183     
00184     public String remove(String object) {
00185         try {
00186             getRepository().remove(object);
00187         } catch (RepositoryNotFoundException rnfe) {
00188             return "Oops, internal error while unsubscribing: " + rnfe;
00189         } catch (InfoNotFoundException infe) {
00190             return "Object not found in repository: " + infe;
00191         } catch (NullPointerException npe) {
00192             return "Couldn't get repository - see logs";
00193         }
00194         
00195         return "Object" + object + " successfully removed";
00196     }
00197     
00199     private ISInterface() {        
00200         si = SystemInterface.getInstance();
00201         refresh();
00202     }
00203     
00204     private static ISInterface instance = new ISInterface();
00205     private Repository r;
00206     private SystemInterface si;
00207 }

Generated on Mon Feb 6 14:12:13 2006 for SCT DAQ/DCS Software - Java by  doxygen 1.4.6