Handler创建Dispatcher请求调用执行Utility
文章目录
- 应用场景
- 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请求
char ProviderName[128]="SIEMENS", //Provider名称 ServiceName[128]="bomchange"; //服务名称 int request_args_num= 4; //参数数量 //request_args为参数值 键值对形式 "key=value",例如"prop=xxx" const char** request_args = (const char**)MEM_alloc(request_args_num * sizeof(char*)); tag_t trans_rqst=NULLTAG; logical flag; int isFinalState =0; ITKCALL(DISPATCHER_create_request( ProviderName,//the name of the provider that will process this request ServiceName,//the name of the service that will process this request 3, //the priority to assign to the request(0 LOW to 3 HIGH) 0, //the time at which to start this request 0, //the time at which no more repeating requests of this same type will be processed. //If the interval option for repeating is NOT selected, then this paramater is unused 0, //the number of times to repeat this request // 0 - no repeating // 1 2 3 ... - number of times to repeat this task 1,// the length of the primary and secondary object arrays &attachments[i],// the array of primary objects 请求对象 NULL,//the array of related secondary objects request_args_num, //the number of request arguments request_args,//the array of request arguments in the format of 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.) 0, //the number of datafiles you would like to upload 0, 0, &trans_rqst));
创建响应
1、创建响应工程
1、创建一个普通的java工程,导入依赖包,依赖包存在于DispatcherClient\lib。
2、创建下图所示的java文件
2、书写响应代码
1、com.origin.bomchange.response.DatabaseOperation.java 代码
package com.origin.bomchange.response; import java.util.List; import com.teamcenter.ets.load.DefaultDatabaseOperation; import com.teamcenter.translationservice.task.TranslationDBMapInfo; public class DatabaseOperation extends DefaultDatabaseOperation{ /** * Stores translation result data on the source dataset. If there are * existing translation result data files, they may be replaced depending * upon the value of the UpdateExistingVisualizationData TaskPrep instance * variable. * * @param zDbMapInfo DB mapper info object. * @param zFileList List of files mapped to the source file. * * @throws Exception */ public void load( ) throws Exception { super.load(); System.out.println("load...."); } // end load() }
2、com.origin.bomchange.response.TaskPrep.java
package com.origin.bomchange.response; //import com.origin.log.WriteLogUtil; import java.io.File; import java.io.FileOutputStream; import java.io.PrintStream; import java.util.Arrays; import java.util.List; import com.teamcenter.ets.extract.DefaultTaskPrep; import com.teamcenter.ets.request.TranslationRequest; import com.teamcenter.soa.client.model.ModelObject; import com.teamcenter.translationservice.task.TranslationTask; public class TaskPrep extends DefaultTaskPrep { public TranslationTask prepareTask() throws Exception { System.out.println("=================response================="); TranslationTask transTask = new TranslationTask(); //获取请求对象 ModelObject primary_objs[] = request.getPropertyObject( TranslationRequest.PRIMARY_OBJS).getModelObjectArrayValue(); //获取输入参数值的键 String[] argKeys = request.getPropertyObject( TranslationRequest.TRANSLATION_ARGS_KEYS).getStringArrayValue(); //获取输入参数值的值 String[] argValues = request.getPropertyObject( TranslationRequest.TRANSLATION_ARGS_DATA).getStringArrayValue(); List<String> argKeyList = Arrays.asList(argKeys); List<String> argValueList = Arrays.asList(argValues); System.out.println(argKeyList); System.out.println(argValueList); String root_uid = ""; String prop_BFR = ""; String prop_AFR = ""; String prop_form = ""; if (argKeys != null && argKeys.length > 0) { for (int i = 0; i < argKeys.length; i++) { if (argKeys[i].equals("task_uid") == true) { root_uid = argValues[i]; }else if(argKeys[i].equals("prop_BFR") == true){ prop_BFR = argValues[i]; }else if(argKeys[i].equals("prop_AFR") == true){ prop_AFR = argValues[i]; }else if(argKeys[i].equals("prop_form") == true){ prop_form = argValues[i]; } } } if (primary_objs.length > 0) { FileOutputStream output_file = new FileOutputStream(this.stagingLoc + File.separator + "EBOMFileList.txt"); PrintStream uids_print_stream = new PrintStream(output_file); System.out.println("path-->" + this.stagingLoc + File.separator+ "EBOMFileList.txt"); StringBuffer sb = new StringBuffer(""); sb.append("object_uid="+primary_objs[0].getUid()+";"); if (!root_uid.equals("")) { sb.append("root_uid="+root_uid+";"); } if(!prop_BFR.equals("")){ sb.append("prop_BFR="+prop_BFR+";"); } if(!prop_AFR.equals("")){ sb.append("prop_AFR="+prop_AFR+";"); } if(!prop_form.equals("")){ sb.append("prop_form="+prop_form+";"); } String s = sb.toString(); System.out.println("s--->" + s); uids_print_stream.print(s.substring(0,s.length() - 1)); uids_print_stream.close(); output_file.close(); transTask = prepTransTask(null, null, null, "EBOMFileList.txt", false, false, null, 0, null); } this.m_zTaskLogger.info("end prepareTask ebomlist "); return addRefIdToTask(transTask, 0); } }
响应时,将EBOMFileList.txt生成在Stage相对应的任务文件夹中,将Utility所需要的参数写入txt中。
3、打成jar包
4、将导出的jar包放入DispatcherClient\lib下。
5、修改DispatcherClient\conf下Service.properties文件
1、在import中加入jar包名称”BOMchange”
2、在文件最后加入
Translator.SIEMENS.bomchange.Prepare=com.origin.bomchange.response.TaskPrep Translator.SIEMENS.bomchange.Duplicate=false
SIEMENS是Handler请求中ProviderName,bomchange是Handler请求中服务名,等号后面是TaskPrep类的全限定名。
6、修改Module\conf下translator.xml文件
1、在标签内加入
<!-- Configuration of the bomchange --> <BOMchange provider="SIEMENS" service="bomchange" isactive="true" > <TransExecutable dir="&MODULEBASE;/Translators/bomchange" name="bomchange.bat"/> <Options> <Option name="taskid" string="" description="Task ID from Dispatcher Client."/> </Options> </BOMchange>
BOMchange为jar包名称,SIEMENS为ProviderName,bomchange为ServiceName,dir指定bomchange.bat文件的路径为Translators下bomchange文件夹。
7、书写bomchange.bat,并放在Translators下bomchange文件夹内。
@echo on set MODULE_PATH=D:\Siemens\DC\Module set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_45 set DC_PATH=D:\Siemens\DC\Stage\DC SET TC_ROOT=D:\Siemens\Teamcenter10 SET TC_DATA=D:\Siemens\tcdata call D:\Siemens\tcdata\tc_profilevars %MODULE_PATH%\Translators\bomchange\bom_change.exe %1 %DC_PATH% @echo off
需根据实际情况修改路径,bat调用exe文件去执行程序。
感谢链接
https://www.dandelioncloud.cn/article/details/1489054828394565633#google_vignette
本文来自博客园,作者:一个小笨蛋,转载请注明原文链接:https://www.cnblogs.com/paylove/p/17947207
分类:
Teamcenter
标签:
Teamcenter
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效