Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: INHB

INHB.m

Go to the documentation of this file.
  1. INHB ; cmi/flag/maw - JSH,KAC 18 Apr 97 11:03 Background Process Control ; [ 05/14/2002 1:31 PM ]
  1. ;;3.01;BHL IHS Interfaces with GIS;**1**;JUN 01, 2002
  1. ;COPYRIGHT 1991-2000 SAIC
  1. ;
  1. STARTUP ;Full interface startup
  1. D START
  1. Q
  1. ;
  1. STOPALL ;Stop all processes
  1. N INDA,X
  1. I '$D(IOF) S (%ZIS,IOP)="" D ^%ZIS
  1. W @IOF,!
  1. S X=$$YN^UTSRD("Do you really want to shut down all Interface processes? ;1","") Q:'X
  1. ; Signal all background processes to quit
  1. F X=1:1:100 K ^INRHB("RUN")
  1. ; If process opened as server & is active, shut down "hung" active servers
  1. S INDA=0
  1. F S INDA=$O(^INTHPC("ACT",1,INDA)) Q:'INDA I +$P(^INTHPC(INDA,0),U,8),$$VER(INDA) S X=$$SRVRHNG(INDA)
  1. W !!,"All processes have been signalled to quit."
  1. Q
  1. ;
  1. START ;Start all background processes
  1. N AVJ,DA,I,VER,CT S AVJ=^%ZOSF("AVJ"),U="^"
  1. S (CT,DA)=0
  1. F S DA=$O(^INTHPC("ACT",1,DA)) Q:'DA D
  1. .S DA(0)=$P(^INTHPC(DA,0),U) X AVJ W:Y<1&'$D(ZTSK) !,DA(0)_"NOT Started - not enough available jobs." I Y>0 S VER=1 D I VER S X=$$A(DA) W:'$D(ZTSK) !,DA(0)_$S(X:"",1:" NOT")_" Started." S:X CT=CT+1
  1. ..Q:$D(ZTSK) I $$VER(DA) W !,*7 S X=$$YN^UTSRD("NOTE: "_DA(0)_" appears to be running - continue? ;0","") S:'X VER=0
  1. Q:$D(ZTSK)
  1. W !,CT_" processes were started."
  1. Q
  1. ;
  1. A(DA) ;Startup a process
  1. ;DA = entry # in file 4004
  1. ;Returns 1 if started, 0 otherwise
  1. ;
  1. N INERR
  1. S INERR=$$OKTR(DA) I 'INERR W:'$D(ZTSK) !,?10,*7,INERR Q 0
  1. N JOB S JOB=$$REPLACE^UTIL(^INTHOS(1,1),"*","^INHB1("_DA_")")
  1. K ^INRHB("RUN",DA) X JOB F I=1:1:15 L +^INRHB("RUN",DA):0,-^INRHB("RUN",DA) Q:$D(^INRHB("RUN",DA)) H 2 W:'$D(ZTSK) "."
  1. H 1 Q ''$D(^INRHB("RUN",DA))
  1. ;
  1. OKTR(X) ;See if OK to run process #X
  1. ;Returns 1 if OK, 0 otherwise
  1. Q:'$G(^INRHSITE(1,"ACT")) "Interface system not active - NO ACTION TAKEN."
  1. Q:'$P($G(^INTHPC(X,0)),"^",2) "Process not active - NO ACTION TAKEN."
  1. Q:+$G(^INTHPC(X,7)) "Process cannot be started manually - NO ACTION TAKEN."
  1. Q 1
  1. ;
  1. START1 ;Restart individual processes
  1. N DIC,INDA,X,Y
  1. S DIC="^INTHPC(",DIC(0)="QAE",DIC("S")="I $P(^(0),U,2)",DIC("A")="Select PROCESS to Start: " D ^DIC Q:Y<0
  1. S INDA=+Y I $$VER(INDA) W !,*7 S X=$$YN^UTSRD("This process appears to be running already - continue? ;0","") G:'X START1
  1. X ^%ZOSF("AVJ") I Y<1 W !,*7,"No available partitions." Q
  1. W !?5 S X=$$A(INDA)
  1. W:X " Started" W:'X !,*7," PROCESS DID NOT START!"
  1. G START1
  1. ;
  1. VER(DA) ;Verify entry DA is running
  1. ;Return 1 if running, 0 if not running, -1 if running but signaled to quit
  1. G:$G(^INTHOS(1,4))]"" VER1
  1. L +^INRHB("RUN",DA):1 I L -^INRHB("RUN",DA) Q 0
  1. Q:'$D(^INRHB("RUN",DA)) -1
  1. Q 1
  1. ;
  1. VER1 ;Come here when OS file has code to do the checking
  1. N X S X=$P(^INTHPC(DA,0),"^",4) Q:'X 0
  1. X "N DA "_^INTHOS(1,4) Q:'X 0
  1. Q:'$D(^INRHB("RUN",DA)) -1
  1. Q 1
  1. ;
  1. VERIFY ;Verify if all active processes are running
  1. D EN^INHOV Q
  1. ;
  1. ;Deactivated 2/23/95 by jmb
  1. N I,OK,S,H S U="^"
  1. S I=0,OK=1 F S I=$O(^INTHPC("ACT",1,I)) Q:'I S S=$$VER(I) W !?5,$P(^INTHPC(I,0),"^")," ",$S('S:"appears to be *NOT* running!",S=-1:"has been signaled to quit.",1:"appears to be running.") S H=$$LAST(I) W:H]"" !?10,"Last run update: "_H
  1. W !,$$CR^INHU1
  1. Q
  1. ;
  1. LAST(I) ;Returns last run update date/time for process #I
  1. N H S H=$G(^INRHB("RUN",I)) Q:H="" "" Q $$DATEFMT^UTDT(H,"DD MMM YY@HH:II:SS")
  1. ;
  1. STOP ;Stop a process
  1. N DIC,INDA,INRUN,INSRVR,X,Y
  1. S DIC="^INTHPC(",DIC(0)="QAE",DIC("S")="I $P(^(0),U,2)",DIC("A")="Select PROCESS to Stop: " D ^DIC Q:Y<0
  1. S INDA=+Y
  1. S INRUN=$$VER(INDA)
  1. S INSRVR=+$P(^INTHPC(INDA,0),U,8) ; opened as client=0 or server=1
  1. I 'INRUN!((INRUN=-1)&('INSRVR)) W !,*7 S X=$$YN^UTSRD("This process does not appear to be running - continue? ;0","") Q:'X
  1. F X=1:1:100 K ^INRHB("RUN",INDA)
  1. S:$$VER(INDA)&INSRVR X=$$SRVRHNG(INDA) ; shut down "hung" active server
  1. U 0 W !,"Process has been signaled to terminate."
  1. Q
  1. ;
  1. SRVRHNG(INBPN) ; $$function - If a receiver opens a TCP/IP socket, but no
  1. ; transmitter makes a connection, the receiver will hang on the
  1. ; OPEN^%INET command. As a result, signalling such a receiver
  1. ; background process to shutdown will fail since %INET retains
  1. ; control until a connection is received. The purpose of this
  1. ; routine is to supply the awaited connection, at which time the
  1. ; background process will receive control, detect the flag to
  1. ; shutdown and quit.
  1. ;
  1. ; Input:
  1. ; INBPN - BACKGROUND PROCESS CONTROL IEN for process to shut down
  1. ;
  1. ; Variables:
  1. ; INCHNL - TCP channel assigned to this server when connection is opened
  1. ; INMEM - memory variable used by %INET
  1. ; INPADIE - IEN of "well-known" IP port multiple for this server
  1. ; INPORT - "well-known" IP port(s) for this server background process
  1. ;
  1. ; Output:
  1. ; 0 = successful attempt to connect to potentially "hung" server
  1. ; 1 = attempt to connect to potentially "hung" server was NOT successful
  1. ;
  1. N INCHNL,INMEM,INPADIE,INPORT
  1. ;
  1. Q:'+$P(^INTHPC(INBPN,0),U,8) 1 ; quit if process opened as client
  1. Q:'$D(^INTHPC(INBPN,5)) 1 ; quit if no port data for this server
  1. K ^INRHB("RUN",INBPN) ; signal process to shutdown
  1. ;
  1. ; Find/connect to any port(s) associated with this background process
  1. ; on which a "hung" server may be listening
  1. S INPADIE=0
  1. F S INPADIE=$O(^INTHPC(INBPN,5,INPADIE)) Q:'INPADIE D
  1. . S INPORT=$P(^INTHPC(INBPN,5,INPADIE,0),U) Q:'INPORT
  1. .; Attempt to open as a client to this server on this port
  1. . D OPEN^%INET(.INCHNL,.INMEM,"0.0.0.0",INPORT,1)
  1. . ;D OPEN^%INET(.INCHNL,.INMEM,"0.0.0.0",INPORT,1,$G(INBPN)) ;maw cache
  1. . D:INCHNL CLOSE^%INET(INCHNL)
  1. . ;D:INCHNL CLOSE^%INET(INCHNL,$G(INBPN)) ;maw cache
  1. Q 0
  1. ;