ALMA Computing Group

Client.java

Go to the documentation of this file.
00001 package alma.demo.dyncomp; 00002 00003 import java.util.logging.Logger; 00004 import alma.acs.component.client.ComponentClient; 00005 import alma.ACS.ACSComponent; 00006 import alma.ACS.ACSComponentHelper; 00007 import alma.JavaContainerError.wrappers.AcsJContainerServicesEx; 00008 00009 import si.ijs.maci.ComponentSpec; 00010 import si.ijs.maci.ComponentInfo; 00011 00017 public class Client extends ComponentClient { 00018 00019 private final int MAXCOMPONENTS=32; 00020 // The two lists with the acivated components and their URLs 00021 // When a component is freed the items are not reordered (so a hole will exist in the 00022 // position of the freed element) 00023 // Free slots contain null 00024 ACSComponent m_components[]; 00025 String m_cURLs[]; 00026 00029 public Client(Logger logger, String managerLoc, String clientName) 00030 throws Exception 00031 { 00032 super(logger,managerLoc,clientName); 00033 m_components = new ACSComponent[MAXCOMPONENTS]; 00034 m_cURLs= new String[MAXCOMPONENTS]; 00035 for (int t=0; t<MAXCOMPONENTS; t++) { 00036 m_components[t]=null; 00037 m_cURLs[t]=null; 00038 } 00039 } 00040 00045 public boolean hasFreeSlot() { 00046 boolean ret=false; 00047 for (int t=0; t<MAXCOMPONENTS; t++) 00048 if (m_components[t]==null) ret=true; 00049 return ret; 00050 } 00051 00057 public String getDynamicComponent(ComponentSpec cs, boolean markAsDefault) 00058 throws AcsJContainerServicesEx 00059 { 00060 // Search for the first free slot in the array 00061 int freeSlot=0; 00062 while (freeSlot<MAXCOMPONENTS && m_components[freeSlot]!=null) freeSlot++; 00063 if (freeSlot<MAXCOMPONENTS) { 00064 m_components[freeSlot]=ACSComponentHelper.narrow(getContainerServices().getDynamicComponent(cs,markAsDefault)); 00065 if (m_components[freeSlot]!=null) { 00066 m_cURLs[freeSlot]=m_components[freeSlot].name(); 00067 return m_cURLs[freeSlot]; 00068 } else { 00069 m_cURLs[freeSlot]=null; 00070 return null; 00071 } 00072 } 00073 return null; 00074 } 00075 00081 public boolean releaseComponent(String url) { 00082 // Search if the given url exists 00083 int t; 00084 for (t=0; t<MAXCOMPONENTS; t++) { 00085 if (m_cURLs[t]!=null) 00086 if (url.compareTo(m_cURLs[t])==0) break; 00087 } 00088 if (t<MAXCOMPONENTS && url.compareTo(m_cURLs[t])==0) { 00089 getContainerServices().releaseComponent(url); 00090 m_components[t]=null; 00091 m_cURLs[t]=null; 00092 return true; 00093 } else return false; 00094 } 00095 00098 public void cleanExit() { 00099 String cURLs[]; 00100 for (int t=0; t<MAXCOMPONENTS; t++) { 00101 if (m_cURLs[t]!=null && m_components[t]!=null) 00102 getContainerServices().releaseComponent(m_cURLs[t]); 00103 m_components[t]=null; 00104 m_cURLs[t]=null; 00105 } 00106 } 00107 } 00108