Staf Java 接口

Staf Java 接口 编程


Step1:

   创建STAFHandle

STAFHandle handle = new STAFHandle("MyApplication");

 

 

Step 2:

 

组建命令然后提交

 

 

 

 String machine = this.ip;      
 STAFResult result = handle.submit2(machine, service, request);
 String service = "PROCESS";
 String request = "START SHELL COMMAND " +
	                    STAFUtil.wrapData(command) +
	                    " WAIT RETURNSTDOUT STDERRTOSTDOUT
STAFResult result = handle.submit2(machine, service, request);

 

Step 3

分析结果:

 

 

                        Map resultMap = (Map)result.resultObj;
	                String processRC = (String)resultMap.get("rc");

	                if (!processRC.equals("0"))
	                {
	                  
	                    logger.error( "ERROR: Process RC is not 0.\n" + result.resultContext);
	                    return stdoutData;
	                }

	                // Print the stdout/stderr data for the command

	                List returnedFileList = (List)resultMap.get("fileList");
	                Map stdoutMap = (Map)returnedFileList.get(0);
	                stdoutData = (String)stdoutMap.get("data");
	                logger.info( "the get data:" + stdoutData);
 

一个完整的例子

import com.ibm.staf.*;
import java.io.*;
 
public class STAFTest
{
    public static void main(String argv[])
    {
        try
        {
            // Create a STAFHandle

            STAFHandle handle = new STAFHandle("MyApplication");
            System.out.println("My handle is: " + handle.getHandle());

            try
            {
                // Submit a synchronous request to the ECHO service on
                // the local machine

                STAFResult result = handle.submit2(
                    "local", "ECHO", "ECHO Hello");

                if (result.rc != 0)
                {
                    System.out.println(
                        "ERROR: STAF local ECHO ECHO Hello failed. RC: " +
                        result.rc + ", Result: " + result.result);
                }
                else
                {
                    System.out.println("ECHO Result: " + result.result);
                }

                // Or submit an asynchronous request to the ECHO service on
                // the local machine

                result = handle.submit2(
                    STAFHandle.ReqRetain, "local", "ECHO", "ECHO Hello");

                if (result.rc != 0)
                {
                    System.out.println(
                        "ERROR: STAF local ECHO ECHO Hello failed. RC: " +
                        result.rc + ", Result: " + result.result);
                }
                else
                {
                    System.out.println(
                        "Asynchronous ECHO Request number: " + result.result);
                }
            }
            finally
            {
                handle.unRegister();
            }
        }
        catch (STAFException e)
        {
            System.out.println(
                "Error (un)registering with STAF, RC:" + e.rc);
            System.exit(1);
        }
 
    }   // End of main()
 
}  // End of STAFTest
 

更多的refer to

http://staf.sourceforge.net/current/STAFJava.htm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值