com.rathravane.till.console.DaemonConsole Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of silt Show documentation
Show all versions of silt Show documentation
A small collection of classes used in various Rathravane systems.
/*
* Copyright 2006-2012, Rathravane LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rathravane.till.console;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.rathravane.till.legal.CopyrightGenerator;
import com.rathravane.till.nv.rrNvReadable;
/**
* A daemon program base class. It sets up commonly used program arguments, etc.
*
* The actual class must implement daemonStillRunning. (If it doesn't, the system
* will shutdown.)
*
* @author peter
*
*/
public class DaemonConsole extends ConfiguredConsole
{
protected DaemonConsole ( String programName )
{
this ( programName, programName );
}
protected DaemonConsole ( String programName, String logName )
{
super ( logName );
fName = programName;
fLogName = logName;
fCopy = new CopyrightGenerator ();
}
public static final String kLogLocation = "log";
protected String getProgramName ()
{
return fName;
}
@Override
protected DaemonConsole setupOptions ( CmdLineParser p )
{
super.setupOptions ( p );
p.registerOptionWithValue ( kLogLocation, null, null, null );
return this;
}
protected DaemonConsole registerCopyrightHolder ( String holder, int startYear )
{
fCopy.addHolder ( holder, startYear );
return this;
}
protected String getDefaultLogName ()
{
return "logs/" + fLogName + ".log";
}
@Override
protected looper init ( rrNvReadable p, CmdLinePrefs clp ) throws rrNvReadable.missingReqdSetting, rrNvReadable.invalidSettingValue, startupFailureException
{
System.out.println ( fName );
for ( String notice : fCopy.getCopyrightNotices () )
{
System.out.println ( notice );
}
return new BackgroundLooper ( 1000 * 3 )
{
@Override
public boolean stillRunning ()
{
return daemonStillRunning ();
}
};
}
protected boolean daemonStillRunning ()
{
log.warn ( "The daemon class must implement daemonStillRunning(). (And don't call the base class implementation.)" );
return false;
}
private final String fName;
private final String fLogName;
private final CopyrightGenerator fCopy;
private static final Logger log = LoggerFactory.getLogger ( DaemonConsole.class );
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy