import java.io.File;
import java.io.FileOutputStream;
import java.util.Collection;
import java.util.Hashtable;
import java.util.Properties;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import com.sap.conn.jco.JCoContext;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoFunctionTemplate;
import com.sap.conn.jco.ext.DestinationDataProvider;
import com.sap.conn.jco.ext.Environment;
import com.sap.conn.jco.ext.JCoSessionReference;
import com.sap.conn.jco.ext.SessionException;
import com.sap.conn.jco.ext.SessionReferenceProvider;
/**
* MultiThreadedExample is a bit too complex. It shows how to use the SessionReferenceProvider
* defined in the packaged com.sap.conn.jco.ext.
*
* Before discussion issues require SessionReferenceProvider, we provide a short
* description, how JCo Runtime handles the stateful and stateless calls by default.
* By default all RFC calls (JCoFunction.execute(JCoDestination)) are stateless. That means
* the ABAP context associated with the connection will be destroyed. Some RFC modules saves
* a particular state/data in the ABAP context's area. In order to keep a JCo connection
* and use it for the subsequent (stateful) calls, JCoConext.begin(JCoDestination) API can be used.
* In case of multithreaded applications some calls to a destination can be executed concurrently, so
* JCo Runtime needs to associate a particular call or connection to an internal session. By default
* JCo Runtime associate each thread to its own session, so the most application, that executes
* all stateful requests en bloc or at least in the same thread, will run correctly.
*
* The applications like to execute calls belongs to a stateful sequences from different
* threads have to implement and register the SessionReferenceProvider. The main goal of
* the implementation is to explain to which session belongs the calls executing in the current thread.
*
* This example defines MultiStepJob having several execution steps. The test start a
* defined count of threads (see runJobs), which takes a job, executes one step and puts the
* job back to the shared job list. There are 2 job as example: StatelessMultiStepExample and
* StatefulMultiStepExample. Both invoke the same RFC modules, but StatefulMultiStepExample
* uses JCoContext.begin and JCoContext.end to specify the stateful calls.
*
* To be able to execute a stateful call sequence continues over several steps, we register
* a custom implementation of SessionReferenceProvider MySessionReferenceProvider.
* The idea behind of MySessionReferenceProvider is simple: each thread
* holds the current session reference in its local storage. To achieve that WorkerThread.run
* sets this session reference before execution of the next step and removes it after
* step was finished.
*/
public class MultiThreadedExample
{
static String DESTINATION_NAME1 = "ABAP_AS_WITHOUT_POOL";
static String DESTINATION_NAME2 = "ABAP_AS_WITH_POOL";
static
{
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "binmain");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "53");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "000");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "JCOTEST");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "JCOTEST");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");
createDataFile(DESTINATION_NAME1, "jcoDestination", connectProperties);
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10");
createDataFile(DESTINATION_NAME2, "jcoDestination", connectProperties);
}
static void createDataFile(String name, String suffix, Properties properties)
{
File cfg = new File(name+"."+suffix);
if(!cfg.exists())
{
try
{
FileOutputStream fos = new FileOutputStream(cfg, false);
properties.store(fos, "for tests only !");
fos.close();
}
catch (Exception e)
{
throw new RuntimeException("Unable to create the destination file " + cfg.getName(), e);
}
}
}
static void createDestinationDataFile(String destinationName, Properties connectProperties)
{
File destCfg = new File(destinationName+".jcoDestination");
try
{
FileOutputStream fos = new FileOutputStream(destCfg, false);
connectProperties.store(fos, "for tests only !");
fos.close();
}
catch (Exception e)
{
throw new RuntimeException("Unable to create the destination files", e);
}
}
interface MultiStepJob
{
boolean isFinished();
public void runNextStep();
String getName();
public void cleanUp();
}
static class StatelessMultiStepExample implements MultiStepJob
{
static AtomicInteger JOB_COUNT = new AtomicInteger(0);
int jobID = JOB_COUNT.addAndGet(1);
int calls;
JCoDestination destination;
int executedCalls = 0;
Exception ex = null;
int remoteCounter;
StatelessMultiStepExample(JCoDestination destination, int calls)
{
this.calls = calls;
this.destination = destination;
}
public boolean isFinished() { return executedCalls == calls || ex != null; }
public String getName() { return "stateless Job-"+jobID; }
public void runNextStep()
{
try
{
JCoFunction incrementCounter = incrementCounterTemplate.getFunction();
incrementCounter.execute(destination);
JCoFunction getCounter = getCounterTemplate.getFunction();
executedCalls++;
if(isFinished())
{
getCounter.execute(destination);
remoteCounter = getCounter.getExportParameterList().getInt("GET_VALUE");
}
}
catch(JCoException je)
{
ex = je;
}
catch(RuntimeException re)
{
ex = re;
}
}
public void cleanUp()
{
StringBuilder sb = new StringBuilder("Task ").append(getName()).append(" is finished ");
if(ex!=null)
sb.append("with exception ").append(ex.toString());
else
sb.append("successful. Counter is ").append(remoteCounter);
System.out.println(sb.toString());
}
}
static class StatefulMultiStepExample extends StatelessMultiStepExample
{
StatefulMultiStepExample(JCoDestination destination, int calls)
{
super(destination, calls);
}
@Override
public String getName() { return "stateful Job-"+jobID; }
@Override
public void runNextStep()
{
if(executedCalls == 0)
JCoContext.begin(destination);
super.runNextS
没有合适的资源?快使用搜索试试~ 我知道了~
SAP JCO JAVA程序通过RFC远程连接SAP RFC函数
共224个文件
html:212个
java:6个
css:1个
5星 · 超过95%的资源 需积分: 10 58 下载量 134 浏览量
2011-06-27
14:30:00
上传
评论 2
收藏 3.13MB ZIP 举报
温馨提示
SAP JCO JAVA程序通过RFC远程连接SAP RFC函数 sapjco3.jar包
资源推荐
资源详情
资源评论
收起资源包目录
SAP JCO JAVA程序通过RFC远程连接SAP RFC函数 (224个子文件)
sap.css 4KB
sapjco3.dll 3.66MB
inherit.gif 57B
index-all.html 332KB
JCoRecord.html 125KB
JCo.html 73KB
constant-values.html 65KB
JCoMetaData.html 65KB
DestinationDataProvider.html 59KB
JCoException.html 57KB
JCoServer.html 52KB
JCoDestination.html 51KB
JCoField.html 47KB
JCoListMetaData.html 43KB
JCoTable.html 34KB
JCoRepository.html 34KB
Environment.html 33KB
JCoClassMetaData.html 33KB
ServerDataProvider.html 30KB
JCoRecordMetaData.html 30KB
JCoAttributes.html 29KB
overview-tree.html 29KB
JCoException.html 27KB
package-use.html 26KB
AbapClassException.html 26KB
releasenotes.html 25KB
JCoConnectionData.html 24KB
JCoRequest.html 24KB
JCoParameterList.html 23KB
JCoFunction.html 23KB
JCoServerContext.html 22KB
JCoCustomDestination.html 21KB
JCoDestinationManager.html 20KB
package-summary.html 20KB
AbapException.html 20KB
JCoRuntimeException.html 19KB
DefaultServerHandlerFactory.html 19KB
JCoCustomRepository.html 19KB
JCoStructure.html 19KB
JCoRecordMetaData.html 18KB
JCoFunctionTemplate.html 18KB
JCoServerUnitIDHandler.html 18KB
package-tree.html 17KB
JCoListMetaData.html 17KB
JCoResponse.html 17KB
JCoAbapObject.html 17KB
JCoUnitIdentifier.html 17KB
DefaultServerHandlerFactory.FunctionHandlerFactory.html 17KB
DefaultServerHandlerFactory.RequestHandlerFactory.html 17KB
JCoDestination.html 17KB
SessionReferenceProvider.html 17KB
AbapException.html 17KB
JCoParameterField.html 16KB
JCoFunctionUnit.html 16KB
JCoRequestUnit.html 16KB
JCoRuntimeException.html 16KB
JCoServerState.html 16KB
JCoRemoteContext.html 16KB
SessionException.Type.html 16KB
JCoDestinationMonitor.html 15KB
JCoServerFactory.html 15KB
JCoServerContextInfo.html 15KB
JCoBackgroundUnitAttributes.html 15KB
JCoFunctionUnitState.html 15KB
package-use.html 15KB
JCoClassMetaData.JCoAttributeKind.html 15KB
JCoCustomRepository.QueryMode.html 15KB
JCoCustomDestination.UserData.html 15KB
JCoServerAuthorizationData.html 15KB
AbapClassException.Mode.html 15KB
JCoRepositoryMonitor.html 14KB
JCoContext.html 14KB
JCoServerCallType.html 14KB
JCoServerMonitor.html 14KB
JCoTraceListener.html 14KB
JCoThroughput.html 14KB
package-summary.html 14KB
JCoRecordField.html 14KB
allclasses-frame.html 14KB
JCoRepository.html 14KB
JCoUnitIdentifier.Type.html 14KB
JCoServerTIDHandler.html 14KB
SessionException.html 14KB
JCoExtendedFieldMetaData.html 14KB
JCoAbapObject.html 14KB
serialized-form.html 13KB
JCoRequest.html 13KB
JCoFunction.html 13KB
JCoFunctionTemplate.html 13KB
JCoApplicationAuthorizationException.html 13KB
JCoClassMetaData.html 13KB
useful.html 12KB
JCoDestinationMonitor.html 12KB
JCoServer.html 12KB
JCoStructure.html 12KB
JCoServerCallHandlerFactory.html 12KB
JCoServerState.html 12KB
allclasses-noframe.html 12KB
JCoTable.html 12KB
JCoParameterFieldIterator.html 12KB
共 224 条
- 1
- 2
- 3
资源评论
- qq_212165432015-12-29感谢,有用
- 陈大神2017-08-09暂时用不上,等以后再使用。
- liudaojin882013-01-21这个是3.0.5的版本,版本下高了
- corel2015-03-26感谢上传资料的兄弟,这个范例代码对我帮助很大,终于成功实现RFC接口调用,谢谢!
- gavinSteele2019-02-28很好,对我有帮助!
ucpvfengan
- 粉丝: 2
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功