Package org.astrogrid.samp.xmlrpc
Class StandardHubProfile
- java.lang.Object
-
- org.astrogrid.samp.xmlrpc.StandardHubProfile
-
- All Implemented Interfaces:
HubProfile,ProfileToken
public class StandardHubProfile extends java.lang.Object implements HubProfile
HubProfile implementation for the SAMP Standard Profile.- Since:
- 31 Jan 2011
- Author:
- Mark Taylor
-
-
Field Summary
Fields Modifier and Type Field Description private HubXmlRpcHandlerhubHandler_private java.io.Filelockfile_private LockInfolockInfo_private java.net.URLlockUrl_private static java.util.logging.Loggerlogger_private static java.util.Randomrandom_private java.lang.Stringsecret_private SampXmlRpcServerserver_private SampXmlRpcClientFactoryxClientFactory_private SampXmlRpcServerFactoryxServerFactory_
-
Constructor Summary
Constructors Constructor Description StandardHubProfile()Constructs a hub profile with default configuration.StandardHubProfile(SampXmlRpcClientFactory xClientFactory, SampXmlRpcServerFactory xServerFactory, java.io.File lockfile, java.lang.String secret)Constructs a hub profile with given configuration information.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.StringcreateSecret()Returns a string suitable for use as a Standard Profile Secret.LockInfogetLockInfo()Returns the lockfile information associated with this object.MessageRestrictiongetMessageRestriction()Returns a MessageRestriction object which controls what messages may be sent by clients registering under ths profile.java.lang.StringgetProfileName()Returns the name of this profile.private static booleanisHubAlive(SampXmlRpcClientFactory xClientFactory, java.io.File lockfile)Attempts to determine whether a given lockfile corresponds to a hub which is still alive.booleanisRunning()Indicates whether this profile is currently running.java.net.URLpublishLockfile()Returns an HTTP URL at which the lockfile for this hub can be found.private static LockInforeadLockFile(java.io.File lockFile)Reads lockinfo from a file.voidstart(ClientProfile profile)Starts this profile's activity allowing access to a given supplier of hub connections.voidstop()Ends this profile's activity on behalf of the hub.private static voidwriteLockInfo(LockInfo info, java.io.OutputStream out)Writes lockfile information to a given output stream.
-
-
-
Field Detail
-
xClientFactory_
private final SampXmlRpcClientFactory xClientFactory_
-
xServerFactory_
private final SampXmlRpcServerFactory xServerFactory_
-
lockfile_
private final java.io.File lockfile_
-
secret_
private final java.lang.String secret_
-
lockUrl_
private java.net.URL lockUrl_
-
server_
private SampXmlRpcServer server_
-
hubHandler_
private volatile HubXmlRpcHandler hubHandler_
-
lockInfo_
private LockInfo lockInfo_
-
logger_
private static final java.util.logging.Logger logger_
-
random_
private static final java.util.Random random_
-
-
Constructor Detail
-
StandardHubProfile
public StandardHubProfile(SampXmlRpcClientFactory xClientFactory, SampXmlRpcServerFactory xServerFactory, java.io.File lockfile, java.lang.String secret)
Constructs a hub profile with given configuration information. If the suppliedlockfileis null, no lockfile will be written at hub startup.- Parameters:
xClientFactory- XML-RPC client factory implementationxServerFactory- XML-RPC server implementationlockfile- location to use for hub lockfile, or nullsecret- value for samp.secret lockfile key
-
StandardHubProfile
public StandardHubProfile() throws java.io.IOExceptionConstructs a hub profile with default configuration.- Throws:
java.io.IOException
-
-
Method Detail
-
getProfileName
public java.lang.String getProfileName()
Description copied from interface:HubProfileReturns the name of this profile.- Specified by:
getProfileNamein interfaceHubProfile- Specified by:
getProfileNamein interfaceProfileToken- Returns:
- profile name, usually one word
-
getMessageRestriction
public MessageRestriction getMessageRestriction()
Description copied from interface:ProfileTokenReturns a MessageRestriction object which controls what messages may be sent by clients registering under ths profile. If null is returned, any messages may be sent.- Specified by:
getMessageRestrictionin interfaceProfileToken- Returns:
- message restriction, or null
-
start
public void start(ClientProfile profile) throws java.io.IOException
Description copied from interface:HubProfileStarts this profile's activity allowing access to a given supplier of hub connections.- Specified by:
startin interfaceHubProfile- Parameters:
profile- object which can provide hub connections- Throws:
java.io.IOException
-
isRunning
public boolean isRunning()
Description copied from interface:HubProfileIndicates whether this profile is currently running.- Specified by:
isRunningin interfaceHubProfile- Returns:
- true iff profile is running
-
stop
public void stop()
Description copied from interface:HubProfileEnds this profile's activity on behalf of the hub. Any resources associated with the profile should be released. This does not include messaging registered clients about profile termination; that should be taken care of by the user of this profile.- Specified by:
stopin interfaceHubProfile
-
getLockInfo
public LockInfo getLockInfo()
Returns the lockfile information associated with this object. Only present when running.- Returns:
- lock info
-
publishLockfile
public java.net.URL publishLockfile() throws java.io.IOExceptionReturns 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 static java.lang.String createSecret()
Returns a string suitable for use as a Standard Profile Secret.- Returns:
- new secret
-
isHubAlive
private static boolean isHubAlive(SampXmlRpcClientFactory xClientFactory, java.io.File lockfile)
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
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
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
-
-