This interface is the gateway to spawning third party applications and establishing a socket connection with them, or connecting to and communicating with servers (ex. Database servers).
The HWMCommMgr can:
• | Spawn another application and create a socket connection (for communication), and send/receive strings. |
• | Connect to another application that has created a server socket and communicate with that application using strings. |
• | Connect and send SQL queries to a relational database server using JDBC drivers. |
• | Connect to servers that use SOAP protocols to communicate (ex. eCompute server). |
The instance of the CommManager can be obtained from the IHWMFrameWork handle. Any bean can make calls into the CommManager and spawn and/or connect to an external application. Every connection is identified by a session name, which will be one of the arguments in any method associated with the HWMCommMgr class. The HWMCommMgr maintains a list of all the connections to external applications.
public void DoSomething()
HWMCommMgr hwmCommMgr = m_hwmFrameWork.GetCommMgr();
HWMClientComm hwmComm =
hwmCommMgr.StartApp(strExec, //The full path to the exec
arrszArgs, //Commad line args
null, //Working directory
"MY_SESSION" /*The session name*/ );
}
Starting any generic application returns an instance of HWMClientComm. The HWMClientComm provides methods such as SendCommand and SendQuery public void DoSomething().
HWMCommMgr hwmCommMgr = m_hwmFrameWork.GetCommMgr();
HWMClientComm hwmComm =
hwmCommMgr.StartApp(strExec, //The full path to the exec
arrszArgsUG, //Commad line args
null, //Working directory*/
"MY_SESSION" /*The session name*/ );
hwmComm.SendCommand("*readfile D:/altair/demo/hm/bumper.hm");
HWMResponseHandle response =
hwmComm.SendQuery("hm_info hm_info templatefilename");
The SendQuery will return an instance of HWMResponseHandle.
Response.IsSuccess() will return whether the SendQuery was executed successfully.
• | Response.toString() will return the result of the query as a string. |
• | Response.toVector() will parse the result and convert it to a vector. |
If the response is "ABC DEF "My name is Jay" XYZ", the vector will have 4 items:
- ABC
- DEF
- My name is Jay
- XYZ
public void DoSomething()
HWMCommMgr hwmCommMgr = m_hwmFrameWork.GetCommMgr();
HWMClientComm hwmComm =
hwmCommMgr.StartApp(strExec, //The full path to the exec
arrszArgsUG, //Commad line args
null, /*Working directory*/
"MY_SESSION" /*The session name*/ );
hwmComm.SendCommand("*readfile D:/altair/demo/hm/bumper.hm");
HWMResponseHandle response =
hwmComm.SendQuery("hm_info hm_info templatefilename");
String strResponse;
if (response.IsSuccess())
strResponse = response.toString();
}
}
The following is an example of how one bean gets the instance of the HWMClientComm created via a call to StartApp by another bean:
HWMClientComm hwmComm =
hwmCommMgr. GetClientComm("MY_SESSION" /*The session name*/);
Spawning HyperMesh/HyperWorks application and establishing a socket connection:
public void DoSomething()
HWMCommMgr hwmCommMgr = m_hwmFrameWork.GetCommMgr();
HWMCommHM commHM =
hwmCommMgr.StartHM(strExec, //The full path to HM exec
null, /*Commad line args, if any*/
null, /*Working directory*/
"MY_SESSION" /*The session name*/ );
commHM.SendCommand("*readfile D:/altair/demo/hm/bumper.hm");
HWMResponseHandle response =
commHM.SendQuery("hm_info hm_info templatefilename");
}
The StartHM method returns a special class instance (HWMCommHM). This class is actually derived from HWMClientComm, and provides additional methods to send a Tcl procedure through the socket and execute it.
public void DoSomething()
HWMCommMgr hwmCommMgr = m_hwmFrameWork.GetCommMgr();
HWMCommHM commHM =
hwmCommMgr.StartHM(strExec,/*The full path to HM exec*/
null, /*Commad line args, if any*/
null, /*Working directory*/
"MY_SESSION" /*The session name*/ );
String strProc = ""
+"proc GetPropertyCollectorNames {} {"
+" *clearmark properties 1;"
+" *createmark properties 1 \"all\";"
+" set listProps [hm_getmark properties 1];"
+" set nNumofProps [llength $listProps];"
+" set listPropNames \"\";"
+" for {set j 0} {$j<$nNumofProps} {incr j} {"
+" set nPropID [lindex $listProps $j];"
+" set strPropName [hm_getcollectorname props $nPropID];"
+" lappend listPropNames $strPropName;"
+" };" //THE SEMI COLON HERE IS VERY IMPORTANT
+" return $listPropNames;"
+"};";
//Send the TCL procedure through the socket and execute it
commHM.CreateFunction(strProc);
HWMResponseHandle response =
commHM.SendQuery("GetPropertyCollectorNames");
}
|
The following illustrates how to get the instance of the HWMCommHM created via a call to StartHM by another bean:
HWMCommHM hwmCommHM =
hwmCommMgr. GetHM("MY_SESSION" /*The session name*/);