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

Generated on Fri Dec 16 19:46:19 2005 for SCT DAQ/DCS Software - Java by doxygen 1.3.5