Download SIMPROCESS User`s Manual Part B

Transcript
Defining a More Complex Generate Activity
External Application Example
The code below is a simple example of an external application communicating with SIMPROCESS.
In this example, Remote is the name of the model (Remote.spm). The for loop runs from 1 to 10.
For 1 and 2, the generateEntity method specifies all the parameters except quantity. The
generateEntity method for 3, 4, and 5 specifies all the parameters. The generateEntity
method for 6 through 10 only specifies the model, generate, and schedule parameters. The
remaining parameters are set for defaults. The generateEntity method after the for loop calls
the StopSim schedule. This schedule is set to generate a StopSim entity, which enters a Dispose Activity
with a maximum entity count of 1, thus stopping the simulation. See “Demonstration and Reference
Models” for instructions on running this example. The code (ExternalApp.java) is in the
SPUser\SampleFiles directory. Also, in the SPUser\SampleFiles directory is
ExternalApp2.java. This application is exactly the same as ExternalApp.java, but it uses
stopSimulation to end the simulation. ExternalAttributes.java is the same as
ExternalApp.java, but it sets the value of four Entity Attributes when Entities are generated.
The Attribute values are displayed using OUTPUT statements in the Release Entity Expression
of the Generate Activity in Remote.spm.
package com.caci.demo;
import com.caci.remote.*;
import java.rmi.*;
import java.rmi.server.*;
public class ExternalApp {
public static void main(String args[]) {
SPServerFactoryInterface spServer = null;
boolean goodEvent = false;
try {
spServer =
(SPServerFactoryInterface)Naming.lookup("rmi://localhost/SPServer");
}
catch (Exception e) {
e.printStackTrace(System.out);
}
try {
if (spServer != null) {
for (int i = 1; i < 11; i++) {
double time = spServer.getSimTime("Remote");
SIMPROCESS User’s Manual
143