Class HubRunner
- java.lang.Object
-
- org.astrogrid.samp.xmlrpc.HubRunner
-
public class HubRunner extends java.lang.ObjectDeprecated.useHubinsteadRuns a SAMP hub using the SAMP Standard Profile. Thestart()method must be called to start it up.The
main(java.lang.String[])method can be used to launch a hub from the command line. Use the-helpflag for more information.- Since:
- 15 Jul 2008
- Author:
- Mark Taylor
-
-
Field Summary
Fields Modifier and Type Field Description private HubServicehub_Deprecated.private HubXmlRpcHandlerhubHandler_Deprecated.private java.io.Filelockfile_Deprecated.private LockInfolockInfo_Deprecated.private java.net.URLlockUrl_Deprecated.private static java.util.logging.Loggerlogger_Deprecated.private static java.util.Randomrandom_Deprecated.private SampXmlRpcServerserver_Deprecated.private booleanshutdown_Deprecated.private static ProfileTokenSTANDARD_PROFILEDeprecated.private SampXmlRpcClientFactoryxClientFactory_Deprecated.private SampXmlRpcServerFactoryxServerFactory_Deprecated.
-
Constructor Summary
Constructors Constructor Description HubRunner(SampXmlRpcClientFactory xClientFactory, SampXmlRpcServerFactory xServerFactory, HubService hub, java.io.File lockfile)Deprecated.Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidcheckExternalHubAvailability()Deprecated.Attempts to determine whether an external hub can be started usingrunExternalHub(org.astrogrid.samp.xmlrpc.HubMode).java.lang.StringcreateSecret()Deprecated.Used to generate the registration password.private static voiddiscardBytes(java.io.InputStream in)Deprecated.Ensures that any bytes from a given input stream are discarded.private static voidexecBackground(java.lang.String[] cmdarray)Deprecated.Executes a command in a separate process, and discards any stdout or stderr output generated by it.HubServicegetHub()Deprecated.Returns the HubService object used by this runner.LockInfogetLockInfo()Deprecated.Returns the lockfile information associated with this object.private static booleanisHubAlive(SampXmlRpcClientFactory xClientFactory, java.io.File lockfile)Deprecated.Attempts to determine whether a given lockfile corresponds to a hub which is still alive.static voidmain(java.lang.String[] args)Deprecated.Main method.java.net.URLpublishLockfile()Deprecated.Returns an HTTP URL at which the lockfile for this hub can be found.private static LockInforeadLockFile(java.io.File lockFile)Deprecated.Reads lockinfo from a file.static voidrunExternalHub(HubMode hubMode)Deprecated.Static method which will attempt to start a hub running in an external JVM.static HubRunnerrunHub(HubMode hubMode, XmlRpcKit xmlrpc)Deprecated.Static method which may be used to start a SAMP hub programmatically.static HubRunnerrunHub(HubMode hubMode, XmlRpcKit xmlrpc, java.lang.String secret, java.io.File lockfile)Deprecated.Static method which may be used to start a SAMP hub programmatically, with a supplied samp.secret string.static intrunMain(java.lang.String[] args)Deprecated.Does the work for running themain(java.lang.String[])method.voidshutdown()Deprecated.Shuts down the hub and tidies up.voidstart()Deprecated.Starts the hub and writes the lockfile.private static voidwriteLockInfo(LockInfo info, java.io.OutputStream out)Deprecated.Writes lockfile information to a given output stream.
-
-
-
Field Detail
-
xClientFactory_
private final SampXmlRpcClientFactory xClientFactory_
Deprecated.
-
xServerFactory_
private final SampXmlRpcServerFactory xServerFactory_
Deprecated.
-
hub_
private final HubService hub_
Deprecated.
-
lockfile_
private final java.io.File lockfile_
Deprecated.
-
lockUrl_
private java.net.URL lockUrl_
Deprecated.
-
lockInfo_
private LockInfo lockInfo_
Deprecated.
-
server_
private SampXmlRpcServer server_
Deprecated.
-
hubHandler_
private HubXmlRpcHandler hubHandler_
Deprecated.
-
shutdown_
private boolean shutdown_
Deprecated.
-
STANDARD_PROFILE
private static final ProfileToken STANDARD_PROFILE
Deprecated.
-
logger_
private static final java.util.logging.Logger logger_
Deprecated.
-
random_
private static final java.util.Random random_
Deprecated.
-
-
Constructor Detail
-
HubRunner
public HubRunner(SampXmlRpcClientFactory xClientFactory, SampXmlRpcServerFactory xServerFactory, HubService hub, java.io.File lockfile)
Deprecated.Constructor. If the suppliedlockfileis null, no lockfile will be written at hub startup.- Parameters:
xClientFactory- XML-RPC client factory implementationxServerFactory- XML-RPC server implementationhub- object providing hub serviceslockfile- location to use for hub lockfile, or null
-
-
Method Detail
-
start
public void start() throws java.io.IOExceptionDeprecated.Starts the hub and writes the lockfile.- Throws:
java.io.IOException- if a hub is already running or an error occurs
-
shutdown
public void shutdown()
Deprecated.Shuts down the hub and tidies up. May harmlessly be called multiple times.
-
getHub
public HubService getHub()
Deprecated.Returns the HubService object used by this runner.- Returns:
- hub service
-
getLockInfo
public LockInfo getLockInfo()
Deprecated.Returns the lockfile information associated with this object. Only present afterstart()has been called.- Returns:
- lock info
-
publishLockfile
public java.net.URL publishLockfile() throws java.io.IOExceptionDeprecated.Returns an HTTP URL at which the lockfile for this hub can be found. The first call to this method causes the lockfile to be published in this way; subsequent calls return the same value.Use this with care; publishing your lockfile means that other people can connect to your hub and potentially do disruptive things.
- Returns:
- lockfile information URL
- Throws:
java.io.IOException
-
createSecret
public java.lang.String createSecret()
Deprecated.Used to generate the registration password. May be overridden.- Returns:
- pasword
-
isHubAlive
private static boolean isHubAlive(SampXmlRpcClientFactory xClientFactory, java.io.File lockfile)
Deprecated.Attempts to determine whether a given lockfile corresponds to a hub which is still alive.- Parameters:
xClientFactory- XML-RPC client factory implementationlockfile- lockfile location- Returns:
- true if the hub described at
lockfileappears to be alive and well
-
readLockFile
private static LockInfo readLockFile(java.io.File lockFile) throws java.io.IOException
Deprecated.Reads lockinfo from a file.- Parameters:
lockFile- file- Returns:
- info from file
- Throws:
java.io.IOException
-
writeLockInfo
private static void writeLockInfo(LockInfo info, java.io.OutputStream out) throws java.io.IOException
Deprecated.Writes lockfile information to a given output stream. The stream is not closed.- Parameters:
info- lock info to writeout- destination stream- Throws:
java.io.IOException
-
main
public static void main(java.lang.String[] args) throws java.io.IOExceptionDeprecated.Main method. Starts a hub. Use "-help" flag for more information.- Parameters:
args- command-line arguments- Throws:
java.io.IOException
-
runMain
public static int runMain(java.lang.String[] args) throws java.io.IOExceptionDeprecated.Does the work for running themain(java.lang.String[])method. System.exit() is not called from this method. Use "-help" flag for more information.- Parameters:
args- command-line arguments- Returns:
- 0 means success, non-zero means error status
- Throws:
java.io.IOException
-
runHub
public static HubRunner runHub(HubMode hubMode, XmlRpcKit xmlrpc) throws java.io.IOException
Deprecated.Static method which may be used to start a SAMP hub programmatically. The returned hub is running (starthas been called).If the hub mode corresponds to one of the GUI options, one of two things will happen. An attempt will be made to install an icon in the "system tray"; if this is successful, the attached popup menu will provide options for displaying the hub window and for shutting it down. If no system tray is available, the hub window will be posted directly, and the hub will shut down when this window is closed. System tray functionality is only available when running under Java 1.6 or later, and when using a suitable display manager.
- Parameters:
hubMode- hub modexmlrpc- XML-RPC implementation; automatically determined if null- Returns:
- running hub
- Throws:
java.io.IOException
-
runHub
public static HubRunner runHub(HubMode hubMode, XmlRpcKit xmlrpc, java.lang.String secret, java.io.File lockfile) throws java.io.IOException
Deprecated.Static method which may be used to start a SAMP hub programmatically, with a supplied samp.secret string. The returned hub is running (starthas been called).If the hub mode corresponds to one of the GUI options, one of two things will happen. An attempt will be made to install an icon in the "system tray"; if this is successful, the attached popup menu will provide options for displaying the hub window and for shutting it down. If no system tray is available, the hub window will be posted directly, and the hub will shut down when this window is closed. System tray functionality is only available when running under Java 1.6 or later, and when using a suitable display manager.
- Parameters:
hubMode- hub modexmlrpc- XML-RPC implementation; automatically determined if nullsecret- samp.secret string to be used for hub connection; chosen at random if nulllockfile- location of lockfile to write, or null for lock to be provided by HTTP- Returns:
- running hub
- Throws:
java.io.IOException
-
runExternalHub
public static void runExternalHub(HubMode hubMode) throws java.io.IOException
Deprecated.Static method which will attempt to start a hub running in an external JVM. The resulting hub can therefore outlast the lifetime of the current application. Because of the OS interaction required, it's hard to make this bulletproof, and it may fail without an exception, but we do our best.- Parameters:
hubMode- hub mode- Throws:
java.io.IOException- See Also:
checkExternalHubAvailability()
-
checkExternalHubAvailability
public static void checkExternalHubAvailability() throws java.io.IOExceptionDeprecated.Attempts to determine whether an external hub can be started usingrunExternalHub(org.astrogrid.samp.xmlrpc.HubMode). If it can be determined that such an attempt would fail, this method will throw an exception with an informative message. This method succeeding is not a guarantee that an external hub can be started successfullly. The behaviour of this method is not expected to change over the lifetime of a given JVM.- Throws:
java.io.IOException
-
execBackground
private static void execBackground(java.lang.String[] cmdarray) throws java.io.IOExceptionDeprecated.Executes a command in a separate process, and discards any stdout or stderr output generated by it. Simply callingRuntime.execcan block the process until its output is consumed.- Parameters:
cmdarray- array containing the command to call and its args- Throws:
java.io.IOException
-
discardBytes
private static void discardBytes(java.io.InputStream in)
Deprecated.Ensures that any bytes from a given input stream are discarded.- Parameters:
in- input stream
-
-