| 1 |
package org.astrogrid.samp.xmlrpc; |
| 2 |
|
| 3 |
import java.io.IOException; |
| 4 |
import java.util.Collections; |
| 5 |
import org.astrogrid.samp.client.CallableClient; |
| 6 |
import org.astrogrid.samp.client.SampException; |
| 7 |
|
| 8 |
/** |
| 9 |
* HubConnection implementation for the Standard Profile. |
| 10 |
* |
| 11 |
* @author Mark Taylor |
| 12 |
* @since 27 Oct 2010 |
| 13 |
*/ |
| 14 |
class StandardHubConnection extends XmlRpcHubConnection { |
| 15 |
|
| 16 |
private final SampXmlRpcServerFactory serverFactory_; |
| 17 |
private final String clientKey_; |
| 18 |
private CallableClientServer callableServer_; |
| 19 |
|
| 20 |
/** |
| 21 |
* Constructor. |
| 22 |
* |
| 23 |
* @param xClient XML-RPC client |
| 24 |
* @param serverFactory XML-RPC server factory implementation |
| 25 |
* @param secret samp.secret registration password |
| 26 |
*/ |
| 27 |
public StandardHubConnection( SampXmlRpcClient xClient, |
| 28 |
SampXmlRpcServerFactory serverFactory, |
| 29 |
String secret ) |
| 30 |
throws SampException { |
| 31 |
super( xClient, "samp.hub.", Collections.singletonList( secret ) ); |
| 32 |
clientKey_ = getRegInfo().getPrivateKey(); |
| 33 |
serverFactory_ = serverFactory; |
| 34 |
} |
| 35 |
|
| 36 |
public Object getClientKey() { |
| 37 |
return clientKey_; |
| 38 |
} |
| 39 |
|
| 40 |
public void setCallable( CallableClient callable ) throws SampException { |
| 41 |
if ( callableServer_ == null ) { |
| 42 |
try { |
| 43 |
callableServer_ = |
| 44 |
CallableClientServer.getInstance( serverFactory_ ); |
| 45 |
} |
| 46 |
catch ( IOException e ) { |
| 47 |
throw new SampException( "Can't start client XML-RPC server", |
| 48 |
e ); |
| 49 |
} |
| 50 |
} |
| 51 |
callableServer_.addClient( this, callable ); |
| 52 |
exec( "setXmlrpcCallback", |
| 53 |
new Object[] { callableServer_.getUrl().toString() } ); |
| 54 |
} |
| 55 |
|
| 56 |
public void unregister() throws SampException { |
| 57 |
if ( callableServer_ != null ) { |
| 58 |
callableServer_.removeClient( this ); |
| 59 |
} |
| 60 |
super.unregister(); |
| 61 |
} |
| 62 |
} |