@MinDoc(copyright="Copyright 2004 - 2009, 2015 A. Weinert", author="Albrecht Weinert", version="V.38", lastModified="16.04.2021", usage="Hold a singleton object", purpose="Basic services for applications") public final class AppBase extends Object implements ComVar
App
automatically have a common
AppBase
object. It provides, also by an associated
AppIO
object, the following services and
utilities:AppIO.out
) for normal output,AppIO.err
) for error messagesAppIO.log
) with optional branching to
normal output and a file,AppIO.in
) for normal input,ComVar.Impl
Modifier and Type | Field and Description |
---|---|
boolean |
askGraf
Graphical question on files instead of console question.
|
Object |
baseApp
The generating application object /
the "mother" application.
|
AppIO |
baseAppIO
The one common AppIO object.
|
boolean |
isBaseApp
The generating application object is of type App.
|
int |
killJVMdelay
Delay before stopping JVM in ms.
|
AUTHOR, BLANK_STRING, cons, CONSOL_ENCODING, COPYRIGHT, D, D_NaN, D_NegInf, D_PosInf, EMPTY_INT_A, EMPTY_STRING, FILE_ENCODING, FRW_CLLD, FS, FSS, H, hasCons, HOST_IP, HOST_IPv4, HOST_NAME, INIT_ERROR, JAR_ENCODING, JH, JOB_DONE_OK, JRL, LOG_OUT_ERROR, M, MAIN_THREAD_EXC, NO_BYTES, NO_CLASSES, NO_DOUBLES, NO_OBJECTS, NO_PARS_ERROR, NO_STRINGS, NOT_WINDOWS, ON_PI, ONE_DAY, ONE_HOUR, ONE_LEAP_YEAR, ONE_MINUTE, ONE_SECOND, ONE_WEEK, ONE_YEAR, OS, PROG_NAME, PROG_SHORT, PS, RUNTIME, S, SHY, UD, UL, UL_UR_da, UR
Modifier and Type | Method and Description |
---|---|
void |
errorExit(Object theApp,
int errNum,
String errText)
Error exit.
|
static void |
exit(Exception excp,
int errNum)
Static Exit — helper method.
|
static AppBase |
getAppBase()
The one /singleton) AppBase object.
|
static AppBase |
getAppBase(Object baseApp,
int outBuffLen,
int logBuffLen,
String codePage)
Fetching or making the one AppBase object.
|
static AppBase |
getAppBase(Object baseApp,
String codePage)
Fetching or making the one AppBase object.
|
AppIO |
getAppIO(Object theApp,
int outBuffLen,
int logBuffLen,
String codePage)
Fetching or making the one fitting AppIO object.
|
static boolean |
isCommonRun()
Common flag: the applications shall / might run on.
|
void |
normalExit(Object theApp,
int returnCode)
Normal exit.
|
static Instant |
setActTime()
Update the commonly used actual (platform based) Time.
|
static boolean |
sleep(long millis)
Delay the applications running by waiting.
|
static int |
start(App app,
String[] args)
Comfortable start of an application extending App.
|
public final Object baseApp
de.frame4j.util.App
, which is then signalled
by isBaseApp
being true.baseApp
is the first requester for which this singleton / common
infrastructure object was made.public final AppIO baseAppIO
public final boolean isBaseApp
public volatile int killJVMdelay
errorExit()
or
normalExit()
and the killing of the JVM.isCommonRun()
public volatile boolean askGraf
public static boolean isCommonRun()
baseApp
that is running (or shall do so).errorExit()
or
normalExit()
), this has to be used by all
running threads and plug-ins as a "stop ASAP!" signal.baseApp
)
runFlag
being reciprocative reset.killJVMdelay
milliseconds will interleave, to allow all threads
applications and plug-ins to end well-behaved.App.isRunFlag()
public void errorExit(Object theApp, int errNum, String errText)
commonRun
will be reset (to false) at
once.theApp
is of type App
the following will
be done:theApp
's runFlag
will be reset to false.errNum
is not 0 or errText
not empty, a multi-line
report will be generated (by errMeld()
)
and output on log
.errNum
is
>= App
.INIT_ERROR
the text
getUsage()
will be output to
baseAppIO.log
.theApp
is the base or mother application
the following will be done:killJVMdelay
in the allowed range (0,1 .. 30 s), the
caller (the calling thread) will be delayed by this grace period.ComVar.NOT_WINDOWS
(i.e. probably Windows), System.exit(-errNum)
is used, as negative process return codes are immoral there.baseApp
or if called on commonRun
already
false, will not return to the caller. In this sense it's like
calling System.exit(), that no other framework based software ever
shall do (!).theApp
- the calling application (may be null).errNum
- !=0 : error (or special case) codeerrText
- supplemental (error) textpublic void normalExit(Object theApp, int returnCode)
errorExit(Object, int, String)
.theApp
- the calling application (may be null).returnCode
- !=0 : error or special case codepublic static void exit(Exception excp, int errNum)
App
's or the AppBase
object's exit
methods are to be used.BaseAppIO.log
is used, if that is available and else System.err:excp
exists and errNum is not 0, the
textexcp
the call stack is output in the
case of a RunTimeException but no IllegalArgumentException. (If this
condition holds, there's often a programming error where the call
stack is helpful.)excp
only the message text is
output. If that is empty, the stack trace is output.excp
- the given exception (or null).errNum
- >0 : the error numberpublic static final AppBase getAppBase()
getAppBase(Object, String)
,
getAppBase(Object, int, int, String)
public static AppBase getAppBase(Object baseApp, String codePage) throws IllegalArgumentException
IllegalArgumentException
.baseApp
- The (first) using application; it will be normally of type
App
, must not be nullcodePage
- The code page for in, out and err (oder null)IllegalArgumentException
- if any used parameter values are illegalgetAppIO(Object, int, int, String)
public static AppBase getAppBase(Object baseApp, int outBuffLen, int logBuffLen, String codePage) throws IllegalArgumentException
IllegalArgumentException
.baseApp
- The (first) using application; it will be normally of type
App
, must not be nulloutBuffLen
- the out TeeWriter's buffer size,
1024 to 400000 characters, default 20KlogBuffLen
- the log TeeWriter's buffer size,
1024 to 400000 characters, default 10KcodePage
- encoding for console I/O, null will act as
CONSOL_ENCODING
,
"defaultEncoding" or specifying unimplemented encodings
will default to the system's file encoding
(ComVar.FILE_ENCODING
)IllegalArgumentException
- if any used parameter values are illegalpublic AppIO getAppIO(Object theApp, int outBuffLen, int logBuffLen, String codePage) throws IllegalArgumentException
AppIO
object fitting
for a given application. Applications of type App
this method is
used accordingly in App
's constructors (as the one AppIO
object associated with an App
is final).AppIO
object
will be returned. All other parameters are then irrelevant.App
, the already associated
AppIO
object is returned, if it is already
made. (This will be so for all calls outside / after App
constructors). All other parameters are then irrelevant.AppIO
object
can be determined, one is made according to the parameters. The free
outputs of the log and out TeeWriter
s will
be forwarded / connected to log and out of this AppBase object's
AppIO
object.theApp
- The using application; it will be normally of type
App
, must not be nulloutBuffLen
- the out TeeWriter's buffer size,
1024 to 400000 characters, default 20KlogBuffLen
- the log TeeWriter's buffer size,
1024 to 400000 characters, default 10KcodePage
- encoding for console I/O, null will act as
CONSOL_ENCODING
,
"defaultEncoding" or specifying unimplemented encodings
will default to the system's file encoding
(ComVar.FILE_ENCODING
)IllegalArgumentException
- if any used parameter values are illegalpublic static final Instant setActTime()
time (stamp)
will be
updated
to platform time and fetched. public static boolean sleep(long millis)
Thread.sleep(long)
(used). de.frame4j.util.ComVar
.millis
- (>0 !) the delay / sleep in msAppHelper.sleep()
public static final int start(App app, String[] args)
App
object. It may of course be used from
an application extending App
itself. The started
App
lication's main thread (doIt()
) does
run in the thread of this method's caller.ComVar.NO_PARS_ERROR
, if app
or
args
is null. It is ComVar.INIT_ERROR
on errors while
evaluating .properties files or the arguments supplied.App
's method app
.doIt()
.App.verbose
and app.App.help
will be set according to
the " mother application" baseApp
. Besides that this
methods effect is mostly that of:app.go(args, false, null);
.App
are written in a way
that they require (default) initialising their object variables by
constructor or initialisers. This is of course perfectly in order. But
if that is so, the same object app
may not be started multiple
times by this method. In that case do notapp
- the application to startargs
- start parameterComVar.INIT_ERROR
etc.: start error, 0:
OK (return by doIt())App.go(String[], String, CharSequence)