00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00019 package cast.configuration;
00020
00021 import java.util.ArrayList;
00022 import java.util.Map;
00023
00024 import Ice.Communicator;
00025 import Ice.Identity;
00026 import cast.ComponentCreationException;
00027 import cast.cdl.ComponentDescription;
00028 import cast.cdl.ComponentLanguage;
00029 import cast.core.CASTUtils;
00030 import cast.interfaces.CASTComponentPrx;
00031 import cast.interfaces.ComponentManagerPrx;
00032 import cast.interfaces.ManagedComponentPrx;
00033 import cast.interfaces.TaskManagerPrx;
00034 import cast.interfaces.TimeServerPrx;
00035 import cast.interfaces.UnmanagedComponentPrx;
00036 import cast.interfaces.WorkingMemoryPrx;
00037
00041 public class SubarchitectureProxies implements CASTConnectionConfiguration {
00042
00043 private ArrayList<UnmanagedComponentPrx> m_unmanagedcomponents;
00044
00045 private ArrayList<ManagedComponentPrx> m_managedcomponents;
00046
00047 private TaskManagerPrx m_taskManager;
00048
00049 private WorkingMemoryPrx m_workingMemory;
00050
00051 private final String m_said;
00052
00053 private final Communicator m_ic;
00054
00055 private final ComponentManagerPrx m_manager;
00056
00057 private final Map<String, TimeServerPrx> m_timeServers;
00058
00059 void setWorkingMemory(ComponentDescription _config)
00060 throws ComponentCreationException {
00061 try {
00062 m_workingMemory = CASTUtils.createWorkingMemory(new Identity(
00063 _config.componentName, _config.className), m_ic,
00064 _config.hostName, CASTUtils
00065 .languageToPort(_config.language));
00066 configureComponent(_config, m_workingMemory);
00067
00068 } catch (ComponentCreationException e) {
00069 addComponentLanguageAndRethrow(e, _config.language);
00070 }
00071 }
00072
00073 void setTaskManager(ComponentDescription _config)
00074 throws ComponentCreationException {
00075 try {
00076 m_taskManager = CASTUtils.createTaskManager(new Identity(
00077 _config.componentName, _config.className), m_ic,
00078 _config.hostName, CASTUtils
00079 .languageToPort(_config.language));
00080 configureComponent(_config, m_taskManager);
00081 } catch (ComponentCreationException e) {
00082 addComponentLanguageAndRethrow(e, _config.language);
00083 }
00084 }
00085
00086 void addManagedComponent(ComponentDescription _config)
00087 throws ComponentCreationException {
00088 try {
00089 ManagedComponentPrx mcp = CASTUtils.createManagedComponent(
00090 new Identity(_config.componentName, _config.className),
00091 m_ic, _config.hostName, CASTUtils
00092 .languageToPort(_config.language));
00093 configureComponent(_config, mcp);
00094 m_managedcomponents.add(mcp);
00095 } catch (ComponentCreationException e) {
00096 addComponentLanguageAndRethrow(e, _config.language);
00097 }
00098 }
00099
00100 void addUnmanagedComponent(ComponentDescription _config)
00101 throws ComponentCreationException {
00102
00103 try {
00104 UnmanagedComponentPrx ucp = CASTUtils.createUnmanagedComponent(
00105 new Identity(_config.componentName, _config.className),
00106 m_ic, _config.hostName, CASTUtils
00107 .languageToPort(_config.language));
00108 configureComponent(_config, ucp);
00109 m_unmanagedcomponents.add(ucp);
00110
00111 } catch (ComponentCreationException e) {
00112 addComponentLanguageAndRethrow(e, _config.language);
00113 }
00114
00115 }
00116
00117 private void addComponentLanguageAndRethrow(ComponentCreationException _e,
00118 ComponentLanguage _language) throws ComponentCreationException {
00119 ComponentCreationException e = new ComponentCreationException(
00120 "While creating a " + _language
00121 + " component the following error occurred: "
00122 + _e.message);
00123 e.initCause(_e);
00124 throw e;
00125 }
00126
00131 private void configureComponent(ComponentDescription _config,
00132 CASTComponentPrx _cp) {
00133
00134 TimeServerPrx ts = m_timeServers.get(_config.hostName);
00135 assert (ts != null);
00136 _cp.setTimeServer(ts);
00137
00138 _cp.setComponentManager(m_manager);
00139 _cp.configure(_config.configuration);
00140 }
00141
00145 public TaskManagerPrx getTaskManager() {
00146 return m_taskManager;
00147 }
00148
00152 public String getID() {
00153 return m_said;
00154 }
00155
00163 public SubarchitectureProxies(SubarchitectureConfiguration _config,
00164 ComponentManagerPrx _man, Map<String, TimeServerPrx> _servers,
00165 Communicator _communicator) throws ComponentCreationException {
00166 m_said = _config.getID();
00167 m_manager = _man;
00168 m_timeServers = _servers;
00169 m_managedcomponents = new ArrayList<ManagedComponentPrx>(1);
00170 m_unmanagedcomponents = new ArrayList<UnmanagedComponentPrx>(1);
00171 m_ic = _communicator;
00172
00173 setWorkingMemory(_config.getWorkingMemoryConfig());
00174 setTaskManager(_config.getTaskManagerConfig());
00175 for (ComponentDescription config : _config.getManagedComponents()) {
00176 addManagedComponent(config);
00177 }
00178 for (ComponentDescription config : _config.getUnmanagedComponents()) {
00179 addUnmanagedComponent(config);
00180 }
00181 }
00182
00186 public ArrayList<UnmanagedComponentPrx> getUnmanagedComponents() {
00187 return m_unmanagedcomponents;
00188 }
00189
00193 public ArrayList<ManagedComponentPrx> getManagedComponents() {
00194 return m_managedcomponents;
00195 }
00196
00197 public WorkingMemoryPrx getWorkingMemory() {
00198 return m_workingMemory;
00199 }
00200
00201
00202
00203
00204
00205
00206 @Override
00207 public String toString() {
00208 return "subarchitecture config: " + m_said;
00209 }
00210
00211 }