Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

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                 r = new SctRepository(si.getPartition());
00095             } catch (NullPointerException npe) {
00096                 //Do nothing - this must have been caused by not being able to get the partition, which we've already logged
00097             }
00098         }
00099         return r;
00100     }
00101     
00102 
00108     public String subscribe(String server, String regex, boolean isRegex, InfoListener l) {        
00109         try {
00110             getRepository().subscribe(server, regex, isRegex, l);
00111         } catch (RepositoryNotFoundException rnfe) {
00112             return "Internal error while subscribing to server " +server +" for " + regex + " : " + rnfe; 
00113         } catch (InvalidExpressionException iee) {
00114             return "Internal error while subscribing to server " +server +" for " + regex + " : " + iee; 
00115         } catch (NullPointerException npe) {
00116             return "Couldn't get repository - see logs";
00117         }
00118         
00119         return "Subscribe to " + server + " successful";
00120     }
00121 
00122     public String subscribe(String server, InfoListener l) {
00123            return subscribe(server, ".*", true, l);
00124     }
00125     
00126     public String unsubscribe(String server) {
00127         return unsubscribe(server,".*");
00128     }
00129 
00130     public String unsubscribe(String server, String regex) {
00131         try {
00132             getRepository().unsubscribe(server, regex,  true);
00133         } catch (RepositoryNotFoundException rnfe) {
00134             return "Oops, internal error while unsubscribing: " + rnfe;
00135         } catch (SubscriptionNotFoundException snfe) {
00136             return "Ooop, internal error - subscription not found: " + snfe;
00137         } catch (NullPointerException npe) {
00138             return "Couldn't get repository - see logs";
00139         }
00140         
00141         return "Unsubscribe from " + server + " for " + regex + " successful";
00142     }
00143     
00144     public String remove(String object) {
00145         try {
00146             getRepository().remove(object);
00147         } catch (RepositoryNotFoundException rnfe) {
00148             return "Oops, internal error while unsubscribing: " + rnfe;
00149         } catch (InfoNotFoundException infe) {
00150             return "Object not found in repository: " + infe;
00151         } catch (NullPointerException npe) {
00152             return "Couldn't get repository - see logs";
00153         }
00154         
00155         return "Object" + object + " successfully removed";
00156     }
00157     
00159     private ISInterface() {        
00160         si = SystemInterface.getInstance();
00161         refresh();
00162     }
00163     
00164     private static ISInterface instance = new ISInterface();
00165     private Repository r;
00166     private SystemInterface si;
00167 }

Generated on Thu Jul 15 09:55:43 2004 for SCT DAQ/DCS Software - Java by doxygen 1.3.5