PJP Documentation > Reference Manual Menu

 

Phantom Job Processor Reference Manual

Notes for Application Programmers

 

There are a few things about the PJP operating environment which require the attention of programmers who are writing processes which will be executed under that environment.  Here are some explanations.

 

Program initialization:

As a developer, I try to write code which will work equally well under both of my target environments, UniVerse and jBase.  Phantoms are implemented somewhat differently between those 2 environments.  The following initialization code works all the time, regardless of which platform is executing it:

 

RUN.COMMAND = SENTENCE()

HOW.MANY.WORDS = DCOUNT(RUN.COMMAND, " ")

IF FIELD(RUN.COMMAND, " ", (HOW.MANY.WORDS - 1)) EQ "PHANTOM" THEN

  * This process is being run from a phantom

  PHANTOM.ID = FIELD(RUN.COMMAND, " ", HOW.MANY.WORDS)

  CURRENT.LOGON = FIELD(PHANTOM.ID, "*", 1)

  CALL PHANTOM.GET.PORT.PID(PHANTOM.ID, CURRENT.PORT, PID)

END ELSE

  PHANTOM.ID = ""

  OPEN "AGENCY" TO AGENT ELSE CALL NO.FILE("","AGENCY",0)

  CALL OPERATING.RELEASE (0,AGENT,OP.REL)

  CALL WHO.CUBS ('',WHO,OP.REL)

  CURRENT.LOGON = FIELD(WHO,' ',2)

  CURRENT.PORT = FIELD(WHO,' ',1)

END

 

The reason that the above code works is that when the PHANTOM.DRIVER program executes a run instruction, it appends some more data to the run instruction.  Let’s say that the run instruction is “RUN PL MY.PROGRAM” and it is being run by the “AUTO” named phantom in the “ABC” logon.  Here is the actual run instruction that PHANTOM.DRIVER will execute to run that process:

 

RUN PL MY.PROGRAM PHANTOM ABC*AUTO

 

Writing a program for continuous execution:

In some situations, you may want to have a phantom process executing continually.  Typically, it will sleep for a short period of time, wake up and do what needs to be done, and then go back to sleep again, in an almost endless loop.  However, that program needs to interact with the PJP database to fulfill 2 functions:

1.      Check in so that it doesn’t seem to be hung.

2.      See if a stop has been requested for its host phantom.

Here’s how you do it:

 

TIME.TO.STOP = FALSE

LOOP

  READ JUNK FROM CONTROL.FILE, "XXX.STOP" THEN

    TIME.TO.STOP = TRUE

    DELETE CONTROL.FILE, "XXX.STOP"

  END

  IF PHANTOM.ID NE "" THEN

    CALL PHANTOM.STOP.REQUESTED (PHANTOM.ID, TIME.TO.STOP)

  END

UNTIL TIME.TO.STOP DO

  GOSUB DO.WHATEVER.NEEDS.TO.BE.DONE

  SLEEP 1

REPEAT

STOP

 

Remember, it’s not necessarily the case that the program will be executed within the PJP environment.  It could be taking up a terminal port, and then how would you stop it?  You might have another program which will write the XXX.STOP item and give this endless loop a graceful way to terminate.

 

The PHANTOM.STOP.REQUESTED program serves both of the 2 functions listed above.

 

Troubleshooting:

All programs meant to be run by the PJP should also be able to be run from TCL on a terminal screen.  This is important for preliminary testing and for later troubleshooting.  If a program seems to not be working within the PJP environment, the first strategy to find out what’s going wrong is to run it from TCL.  In most cases, the problem becomes quickly obvious.

 

If your program works fine from TCL, but not from PJP, troubleshooting becomes more tricky.  You might ask yourself if the program executes some Cubs programs which require port security checks (i.e. BLIB POST).  Since the PJP phantom port has evaded Cubs front-end logon dance, port security will sometimes stop execution.  Other than that, since you can’t use the interactive debugger, you may want to create an internal program log to find out where things are going wrong.

 

 

Home              Back                Next

 

 

Copyright 2011, Cubs Consulting, Inc.