public class serverSwitch
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
java.io.File |
appPath |
private java.lang.String |
configComment |
private java.io.File |
configFile |
private java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.String> |
configProps |
private java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.String> |
configRemoved |
java.io.File |
dataPath |
protected boolean |
firstInit |
private YaCyHttpServer |
httpserver |
private boolean |
isConnectedViaUpnp |
ConcurrentLog |
log |
private static java.util.Random |
pwGenerator |
protected int |
serverJobs |
private java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Integer> |
upnpPortMap |
private java.util.NavigableMap<java.lang.String,BusyThread> |
workerThreads |
Constructor and Description |
---|
serverSwitch(java.io.File dataPath,
java.io.File appPath,
java.lang.String initPath,
java.lang.String configPath) |
Modifier and Type | Method and Description |
---|---|
java.util.Iterator<java.lang.String> |
configKeys() |
void |
deployThread(java.lang.String threadName,
java.lang.String threadShortDescription,
java.lang.String threadLongDescription,
java.lang.String threadMonitorURL,
BusyThread newThread,
long startupDelay) |
void |
deployThread(java.lang.String threadName,
java.lang.String threadShortDescription,
java.lang.String threadLongDescription,
java.lang.String threadMonitorURL,
BusyThread newThread,
long startupDelay,
long initialIdleSleep,
long initialBusySleep,
long initialMemoryPreRequisite,
double initialLoadPreRequisite) |
java.lang.String |
genRandomPassword()
Generates a random password.
|
java.lang.String |
genRandomPassword(int length)
Generates a random password of a given length.
|
java.io.File |
getAppPath() |
java.io.File |
getAppPath(java.lang.String key,
java.lang.String dflt)
return file at path from config entry "key", or fallback to default dflt
|
java.lang.String |
getConfig(java.lang.String key,
java.lang.String dflt)
Gets a configuration parameter from the properties.
|
java.lang.String[] |
getConfigArray(java.lang.String key,
java.lang.String dflt)
get a configuration parameter list
|
boolean |
getConfigBool(java.lang.String key,
boolean dflt)
Gets a configuration parameter from the properties.
|
java.io.Reader |
getConfigFileFromWebOrLocally(java.lang.String uri,
java.lang.String rootPath,
java.io.File file)
Retrieve text data (e.
|
float |
getConfigFloat(java.lang.String key,
float dflt)
Gets a configuration parameter from the properties.
|
int |
getConfigInt(java.lang.String key,
int dflt)
Gets a configuration parameter from the properties.
|
long |
getConfigLong(java.lang.String key,
long dflt)
Gets a configuration parameter from the properties.
|
java.util.Set<java.lang.String> |
getConfigSet(java.lang.String key)
get a configuration parameter set
|
java.io.File |
getDataPath() |
java.io.File |
getDataPath(java.lang.String key,
java.lang.String dflt)
Create a File instance for a configuration setting specifying a path.
|
private java.io.File |
getFileByPath(java.lang.String key,
java.lang.String dflt,
java.io.File prefix) |
YaCyHttpServer |
getHttpServer() |
int |
getLocalPort()
Wrapper for
getConfigInt(String, int) to have a more consistent
API. |
ConcurrentLog |
getLog() |
int |
getPublicPort(java.lang.String key,
int dflt)
Gets public port.
|
java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.String> |
getRemoved()
Gets configuration parameters which have been removed during
initialization.
|
BusyThread |
getThread(java.lang.String threadName) |
void |
handleBusyState(int jobs) |
void |
intermissionAllThreads(long pause) |
boolean |
isConnectedViaUpnp() |
java.lang.String |
myPublicIP()
Deprecated.
|
java.util.Set<java.lang.String> |
myPublicIPs()
Get all my public IPs.
|
void |
removeConfig(java.lang.String key) |
void |
removeUpnpPort(java.lang.String key) |
private void |
saveConfig()
write the changes to permanent storage (File)
|
void |
setConfig(java.util.Map<java.lang.String,java.lang.String> otherConfigs)
add whole map of key-value pairs to config
|
void |
setConfig(java.lang.String key,
boolean value) |
void |
setConfig(java.lang.String key,
double value) |
void |
setConfig(java.lang.String key,
float value) |
void |
setConfig(java.lang.String key,
long value) |
void |
setConfig(java.lang.String key,
java.util.Set<java.lang.String> value) |
void |
setConfig(java.lang.String key,
java.lang.String value) |
void |
setConfig(java.lang.String key,
java.lang.String[] value) |
void |
setConnectedViaUpnp(boolean isConnectedViaUpnp) |
void |
setHttpServer(YaCyHttpServer jettyserver)
set/remember jetty server
|
void |
setLog(ConcurrentLog log) |
void |
setThreadPerformance(java.lang.String threadName,
long idleMillis,
long busyMillis,
long memprereqBytes,
double loadprereq) |
void |
setUpnpPorts(java.lang.String key,
int port) |
void |
terminateAllThreads(boolean waitFor) |
void |
terminateThread(java.lang.String threadName,
boolean waitFor) |
java.util.Iterator<java.lang.String> |
threadNames() |
java.lang.String |
toString() |
private final java.io.File configFile
private final java.lang.String configComment
public final java.io.File dataPath
public final java.io.File appPath
protected boolean firstInit
public ConcurrentLog log
protected int serverJobs
private java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.String> configProps
private final java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.String> configRemoved
private final java.util.NavigableMap<java.lang.String,BusyThread> workerThreads
private YaCyHttpServer httpserver
private java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Integer> upnpPortMap
private boolean isConnectedViaUpnp
private static java.util.Random pwGenerator
public serverSwitch(java.io.File dataPath, java.io.File appPath, java.lang.String initPath, java.lang.String configPath)
@Deprecated public java.lang.String myPublicIP()
public java.util.Set<java.lang.String> myPublicIPs()
public int getPublicPort(java.lang.String key, int dflt)
key
- original key from config (for example "port" or "port.ssl")dflt
- default value which will be used if no value is found#getLocalPort(String, int)
public int getLocalPort()
getConfigInt(String, int)
to have a more consistent
API.
Default value 8090 will be used if no value is foundgetPublicPort(String, int)
public void setLog(ConcurrentLog log)
public ConcurrentLog getLog()
public void setConfig(java.util.Map<java.lang.String,java.lang.String> otherConfigs)
otherConfigs
- public void setConfig(java.lang.String key, boolean value)
public void setConfig(java.lang.String key, long value)
public void setConfig(java.lang.String key, float value)
public void setConfig(java.lang.String key, double value)
public void setConfig(java.lang.String key, java.lang.String value)
public void setConfig(java.lang.String key, java.lang.String[] value)
public void setConfig(java.lang.String key, java.util.Set<java.lang.String> value)
public void removeConfig(java.lang.String key)
public java.lang.String getConfig(java.lang.String key, java.lang.String dflt)
key
- name of the configuration parameterdflt
- default value which will be used in case parameter can not be
found or if it is invalidpublic long getConfigLong(java.lang.String key, long dflt)
key
- name of the configuration parameterdflt
- default value which will be used in case parameter can not be
found or if it is invalidpublic float getConfigFloat(java.lang.String key, float dflt)
key
- name of the configuration parameterdflt
- default value which will be used in case parameter can not be
found or if it is invalidpublic boolean isConnectedViaUpnp()
public void setConnectedViaUpnp(boolean isConnectedViaUpnp)
public void setUpnpPorts(java.lang.String key, int port)
public void removeUpnpPort(java.lang.String key)
public int getConfigInt(java.lang.String key, int dflt)
key
- name of the configuration parameterdflt
- default value which will be used in case parameter can not be
found or if it is invalidpublic boolean getConfigBool(java.lang.String key, boolean dflt)
key
- name of the configuration parameterdflt
- default value which will be used in case parameter can not be
found or if it is invalidpublic java.lang.String[] getConfigArray(java.lang.String key, java.lang.String dflt)
key
- dflt
- a default listpublic java.util.Set<java.lang.String> getConfigSet(java.lang.String key)
key
- dflt
- a default listpublic java.io.File getDataPath(java.lang.String key, java.lang.String dflt)
key
- config keydflt
- default path value, that is used when there is no value
key
in the configuration.public java.io.File getAppPath(java.lang.String key, java.lang.String dflt)
key
- dflt
- private java.io.File getFileByPath(java.lang.String key, java.lang.String dflt, java.io.File prefix)
public java.util.Iterator<java.lang.String> configKeys()
private void saveConfig()
public java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.String> getRemoved()
public void deployThread(java.lang.String threadName, java.lang.String threadShortDescription, java.lang.String threadLongDescription, java.lang.String threadMonitorURL, BusyThread newThread, long startupDelay)
public void deployThread(java.lang.String threadName, java.lang.String threadShortDescription, java.lang.String threadLongDescription, java.lang.String threadMonitorURL, BusyThread newThread, long startupDelay, long initialIdleSleep, long initialBusySleep, long initialMemoryPreRequisite, double initialLoadPreRequisite)
public BusyThread getThread(java.lang.String threadName)
public void setThreadPerformance(java.lang.String threadName, long idleMillis, long busyMillis, long memprereqBytes, double loadprereq)
public void terminateThread(java.lang.String threadName, boolean waitFor)
public void intermissionAllThreads(long pause)
public void terminateAllThreads(boolean waitFor)
public java.util.Iterator<java.lang.String> threadNames()
public java.io.File getDataPath()
public java.io.File getAppPath()
public java.lang.String toString()
toString
in class java.lang.Object
public void handleBusyState(int jobs)
public java.io.Reader getConfigFileFromWebOrLocally(java.lang.String uri, java.lang.String rootPath, java.io.File file) throws java.io.IOException, java.io.FileNotFoundException
file
- url or filenamerootPath
- searchpath for filefile
- file to use when remote fetching fails (null if unused)java.io.IOException
java.io.FileNotFoundException
public java.lang.String genRandomPassword()
public java.lang.String genRandomPassword(int length)
length
- length o passwordpublic void setHttpServer(YaCyHttpServer jettyserver)
jettyserver
- public YaCyHttpServer getHttpServer()