Handler创建Dispatcher请求调用执行Utility

爱被打了一巴掌 2022-02-03 01:55 232阅读 0赞

文章目录

  • 应用场景
  • Handler创建Dispatcher请求
  • 创建响应
    • 1、创建响应工程
    • 2、书写响应代码
    • 3、打成jar包
    • 4、将导出的jar包放入DispatcherClient\lib下。
    • 5、修改DispatcherClient\conf下Service.properties文件
    • 6、修改Module\conf下translator.xml文件
    • 7、书写bomchange.bat,并放在Translators下bomchange文件夹内。

应用场景

在Handler中执行耗时较久的程序时,等待执行过程中,客户端界面无法进行其他操作,只能等待,而通过dispatcher调度可以解决这种问题。

Handler创建Dispatcher请求

  1. char ProviderName[128]="SIEMENS", //Provider名称
  2. ServiceName[128]="bomchange"; //服务名称
  3. int request_args_num= 4; //参数数量
  4. //request_args为参数值 键值对形式 "key=value",例如"prop=xxx"
  5. const char** request_args = (const char**)MEM_alloc(request_args_num * sizeof(char*));
  6. tag_t trans_rqst=NULLTAG;
  7. logical flag;
  8. int isFinalState =0;
  9. ITKCALL(DISPATCHER_create_request(
  10. ProviderName,//the name of the provider that will process this request
  11. ServiceName,//the name of the service that will process this request
  12. 3, //the priority to assign to the request(0 LOW to 3 HIGH)
  13. 0, //the time at which to start this request
  14. 0, //the time at which no more repeating requests of this same type will be processed.
  15. //If the interval option for repeating is NOT selected, then this paramater is unused
  16. 0, //the number of times to repeat this request
  17. // 0 - no repeating
  18. // 1 2 3 ... - number of times to repeat this task
  19. 1,// the length of the primary and secondary object arrays
  20. &attachments[i],// the array of primary objects 请求对象
  21. NULL,//the array of related secondary objects
  22. request_args_num, //the number of request arguments
  23. request_args,//the array of request arguments in the format of
  24. NULL, // a string for use by the application creating the request for use in defining a type for the request (i.e. SYSTEM, THINCLIENT, etc.)
  25. 0, //the number of datafiles you would like to upload
  26. 0,
  27. 0,
  28. &trans_rqst));

创建响应

1、创建响应工程

1、创建一个普通的java工程,导入依赖包,依赖包存在于DispatcherClient\lib。
2、创建下图所示的java文件
在这里插入图片描述

2、书写响应代码

1、com.origin.bomchange.response.DatabaseOperation.java 代码

  1. package com.origin.bomchange.response;
  2. import java.util.List;
  3. import com.teamcenter.ets.load.DefaultDatabaseOperation;
  4. import com.teamcenter.translationservice.task.TranslationDBMapInfo;
  5. public class DatabaseOperation extends DefaultDatabaseOperation{
  6. /**
  7. * Stores translation result data on the source dataset. If there are
  8. * existing translation result data files, they may be replaced depending
  9. * upon the value of the UpdateExistingVisualizationData TaskPrep instance
  10. * variable.
  11. *
  12. * @param zDbMapInfo DB mapper info object.
  13. * @param zFileList List of files mapped to the source file.
  14. *
  15. * @throws Exception
  16. */
  17. public void load( ) throws Exception
  18. {
  19. super.load();
  20. System.out.println("load....");
  21. } // end load()
  22. }

2、com.origin.bomchange.response.TaskPrep.java

  1. package com.origin.bomchange.response;
  2. //import com.origin.log.WriteLogUtil;
  3. import java.io.File;
  4. import java.io.FileOutputStream;
  5. import java.io.PrintStream;
  6. import java.util.Arrays;
  7. import java.util.List;
  8. import com.teamcenter.ets.extract.DefaultTaskPrep;
  9. import com.teamcenter.ets.request.TranslationRequest;
  10. import com.teamcenter.soa.client.model.ModelObject;
  11. import com.teamcenter.translationservice.task.TranslationTask;
  12. public class TaskPrep extends DefaultTaskPrep {
  13. public TranslationTask prepareTask() throws Exception {
  14. System.out.println("=================response=================");
  15. TranslationTask transTask = new TranslationTask();
  16. //获取请求对象
  17. ModelObject primary_objs[] = request.getPropertyObject(
  18. TranslationRequest.PRIMARY_OBJS).getModelObjectArrayValue();
  19. //获取输入参数值的键
  20. String[] argKeys = request.getPropertyObject(
  21. TranslationRequest.TRANSLATION_ARGS_KEYS).getStringArrayValue();
  22. //获取输入参数值的值
  23. String[] argValues = request.getPropertyObject(
  24. TranslationRequest.TRANSLATION_ARGS_DATA).getStringArrayValue();
  25. List<String> argKeyList = Arrays.asList(argKeys);
  26. List<String> argValueList = Arrays.asList(argValues);
  27. System.out.println(argKeyList);
  28. System.out.println(argValueList);
  29. String root_uid = "";
  30. String prop_BFR = "";
  31. String prop_AFR = "";
  32. String prop_form = "";
  33. if (argKeys != null && argKeys.length > 0) {
  34. for (int i = 0; i < argKeys.length; i++) {
  35. if (argKeys[i].equals("task_uid") == true) {
  36. root_uid = argValues[i];
  37. }else if(argKeys[i].equals("prop_BFR") == true){
  38. prop_BFR = argValues[i];
  39. }else if(argKeys[i].equals("prop_AFR") == true){
  40. prop_AFR = argValues[i];
  41. }else if(argKeys[i].equals("prop_form") == true){
  42. prop_form = argValues[i];
  43. }
  44. }
  45. }
  46. if (primary_objs.length > 0) {
  47. FileOutputStream output_file = new FileOutputStream(this.stagingLoc
  48. + File.separator + "EBOMFileList.txt");
  49. PrintStream uids_print_stream = new PrintStream(output_file);
  50. System.out.println("path-->" + this.stagingLoc + File.separator+ "EBOMFileList.txt");
  51. StringBuffer sb = new StringBuffer("");
  52. sb.append("object_uid="+primary_objs[0].getUid()+";");
  53. if (!root_uid.equals("")) {
  54. sb.append("root_uid="+root_uid+";");
  55. }
  56. if(!prop_BFR.equals("")){
  57. sb.append("prop_BFR="+prop_BFR+";");
  58. }
  59. if(!prop_AFR.equals("")){
  60. sb.append("prop_AFR="+prop_AFR+";");
  61. }
  62. if(!prop_form.equals("")){
  63. sb.append("prop_form="+prop_form+";");
  64. }
  65. String s = sb.toString();
  66. System.out.println("s--->" + s);
  67. uids_print_stream.print(s.substring(0,s.length() - 1));
  68. uids_print_stream.close();
  69. output_file.close();
  70. transTask = prepTransTask(null, null, null, "EBOMFileList.txt",
  71. false, false, null, 0, null);
  72. }
  73. this.m_zTaskLogger.info("end prepareTask ebomlist ");
  74. return addRefIdToTask(transTask, 0);
  75. }
  76. }

响应时,将EBOMFileList.txt生成在Stage相对应的任务文件夹中,将Utility所需要的参数写入txt中。

3、打成jar包

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

4、将导出的jar包放入DispatcherClient\lib下。

5、修改DispatcherClient\conf下Service.properties文件

1、在import中加入jar包名称”BOMchange”
2、在文件最后加入

  1. Translator.SIEMENS.bomchange.Prepare=com.origin.bomchange.response.TaskPrep
  2. Translator.SIEMENS.bomchange.Duplicate=false

SIEMENS是Handler请求中ProviderName,bomchange是Handler请求中服务名,等号后面是TaskPrep类的全限定名。

6、修改Module\conf下translator.xml文件

1、在标签内加入

  1. <!-- Configuration of the bomchange -->
  2. <BOMchange provider="SIEMENS" service="bomchange" isactive="true" >
  3. <TransExecutable dir="&MODULEBASE;/Translators/bomchange" name="bomchange.bat"/>
  4. <Options>
  5. <Option name="taskid" string=""
  6. description="Task ID from Dispatcher Client."/>
  7. </Options>
  8. </BOMchange>

BOMchange为jar包名称,SIEMENS为ProviderName,bomchange为ServiceName,dir指定bomchange.bat文件的路径为Translators下bomchange文件夹。

7、书写bomchange.bat,并放在Translators下bomchange文件夹内。

  1. @echo on
  2. set MODULE_PATH=D:\Siemens\DC\Module
  3. set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_45
  4. set DC_PATH=D:\Siemens\DC\Stage\DC
  5. SET TC_ROOT=D:\Siemens\Teamcenter10
  6. SET TC_DATA=D:\Siemens\tcdata
  7. call D:\Siemens\tcdata\tc_profilevars
  8. %MODULE_PATH%\Translators\bomchange\bom_change.exe %1 %DC_PATH%
  9. @echo off

需根据实际情况修改路径,bat调用exe文件去执行程序。

发表评论

表情:
评论列表 (有 0 条评论,232人围观)

还没有评论,来说两句吧...

相关阅读