public class Hub extends Object
main()
method is provided for
use from the command line.
Some of the static methods allow you to indicate which hub profiles
should be used, others use a default. The default list can be set
programmatically by using the setDefaultProfileClasses(java.lang.Class[], boolean)
method
or externally by using the
"jsamp.hub.profiles" and "jsamp.hub.profiles.extra"
system properties.
So, for instance, running an application with
-Djsamp.hub.profiles=web,std
will cause it to run hubs
using both the Standard and Web profiles if it does not explicitly choose
profiles.
Modifier and Type | Field and Description |
---|---|
static String |
EXTRAHUBPROFILES_PROP
System property name for supplying default profiles ("jsamp.hub.profiles.extra")
additional to those in
HUBPROFILES_PROP which will be
supported by the hub but switched off at hub startup time. |
static String |
HUBPROFILES_PROP
System property name for supplying default profiles ("jsamp.hub.profiles")
available at hub startup.
|
Constructor and Description |
---|
Hub(HubService service)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static void |
checkExternalHubAvailability()
Attempts to determine whether an external hub can be started using
runExternalHub . |
static HubProfile[] |
createDefaultProfiles(boolean extra)
Returns an array of default Hub Profiles.
|
static Class[] |
getDefaultProfileClasses(boolean extra)
Returns a copy of the default set of HubProfile classes used
when a hub is run and the list of profiles is not set explicitly.
|
HubService |
getHubService()
Returns the hub service associated with this hub.
|
static HubProfileFactory[] |
getKnownHubProfileFactories()
Returns a standard list of known HubProfileFactories.
|
static Hub[] |
getRunningHubs()
Returns an array of all the instances of this class which are
currently running.
|
HubProfile[] |
getRunningProfiles()
Returns the hub profiles currently running on behalf of this hub.
|
JFrame |
getWindow()
Returns a window for user monitoring and control of this hub,
if available.
|
static void |
main(String[] args)
Main method, which allows configuration of which profiles will run
and configuration of those individual profiles.
|
static HubProfileFactory[] |
parseProfileList(String listTxt)
Parses a string representing a list of hub profiles.
|
static void |
runExternalHub(HubServiceMode hubMode)
Attempts to run a hub in a new JVM with a default set of profiles.
|
static void |
runExternalHub(HubServiceMode hubMode,
Class[] profileClasses,
Class[] extraProfileClasses)
Attempts to start a hub in a new JVM with a given set
of profiles.
|
static Hub |
runHub(HubServiceMode hubMode)
Starts a SAMP hub with a default set of profiles.
|
static Hub |
runHub(HubServiceMode hubMode,
HubProfile[] profiles,
HubProfile[] extraProfiles)
Starts a SAMP hub with given sets of profiles.
|
static int |
runMain(String[] args)
Invoked by main.
|
static void |
setDefaultProfileClasses(Class[] clazzes,
boolean extra)
Sets the default set of HubProfile classes.
|
void |
shutdown()
Stops this hub and its profiles running.
|
void |
startProfile(HubProfile profile)
Starts a profile running on behalf of this hub.
|
void |
stopProfile(HubProfile profile)
Stops a profile running on behalf of this hub, and disconnects
all clients registered with it.
|
public static final String HUBPROFILES_PROP
parseProfileList(java.lang.String)
.public static final String EXTRAHUBPROFILES_PROP
HUBPROFILES_PROP
which will be
supported by the hub but switched off at hub startup time.
The value of this property, if any, will be fed to
parseProfileList(java.lang.String)
.public Hub(HubService service)
service
- hub servicepublic void shutdown()
public void startProfile(HubProfile profile) throws IOException
profile
- to startIOException
public void stopProfile(HubProfile profile)
profile
- profile to stoppublic HubService getHubService()
public HubProfile[] getRunningProfiles()
public JFrame getWindow()
public static HubProfileFactory[] getKnownHubProfileFactories()
parseProfileList(java.lang.String)
to supply the well-known named profiles.public static Class[] getDefaultProfileClasses(boolean extra)
HubProfile
with a no-arg constructor.extra
- false for starting classes, true for additional onespublic static void setDefaultProfileClasses(Class[] clazzes, boolean extra)
clazzes
- array to be returned by getDefaultProfileClassesextra
- false for starting classes, true for additional onespublic static HubProfileFactory[] parseProfileList(String listTxt)
name
of a HubProfileFactory
or the classname of a HubProfile
implementation
with a suitable no-arg constructor.listTxt
- comma-separated listIllegalArgumentException
- if unknownpublic static HubProfile[] createDefaultProfiles(boolean extra)
getDefaultProfileClasses(boolean)
.extra
- false for starting profiles, true for additional onespublic static Hub runHub(HubServiceMode hubMode, HubProfile[] profiles, HubProfile[] extraProfiles) throws IOException
The profiles
argument gives the profiles which will
be started initially, and the extraProfiles
argument
lists more that can be started under user control later.
If either or both list is given as null, suitable defaults will be used.
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.
hubMode
- hub modeprofiles
- SAMP profiles to support on hub startup;
if null a default set will be usedextraProfiles
- SAMP profiles to offer for later startup under
user control; if null a default set will be usedIOException
public static Hub runHub(HubServiceMode hubMode) throws IOException
runHub(hubMode,null,null)
.hubMode
- hub modeIOException
runHub(HubServiceMode,HubProfile[],HubProfile[])
public static void runExternalHub(HubServiceMode hubMode, Class[] profileClasses, Class[] extraProfileClasses) throws IOException
The classes specified by the profileClasses
and
extraProfileClasses
arguments must implement
HubProfile
and must have a no-arg constructor.
If null is given in either case suitable defaults, taken from the
current JVM, are used.
hubMode
- hub modeprofileClasses
- hub profile classes to start on hub startupextraProfileClasses
- hub profile classes which may be started
later under user controlIOException
checkExternalHubAvailability()
public static void runExternalHub(HubServiceMode hubMode) throws IOException
runExternalHub(hubMode,null,null)
.hubMode
- hub modeIOException
runExternalHub(HubServiceMode,java.lang.Class[],java.lang.Class[])
public static Hub[] getRunningHubs()
public static void checkExternalHubAvailability() throws IOException
runExternalHub
.
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.IOException
public static void main(String[] args)
-h
flag for usage.public static int runMain(String[] args) throws IOException
args
- command-line argument arrayIOException
Copyright © 2008–2024. All rights reserved.