Package org.astrogrid.samp.bridge
Class ProxyManager
- java.lang.Object
-
- org.astrogrid.samp.bridge.ProxyManager
-
class ProxyManager extends java.lang.ObjectTakes care of client connections for the SAMP Bridge. An instance of this class is associated with a given 'local' hub participating in the bridge, and makes the following connections:- On the local hub, one connection which is there to monitor client changes
- On each remote hub participating in the bridge, one 'proxy' connection for every client on this manager's local hub.
init(org.astrogrid.samp.bridge.ProxyManager[])).- Since:
- 15 Jul 2009
- Author:
- Mark Taylor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classProxyManager.ProxyCallableClientCallableClient implementation used by remote proxy connections on behalf of local clients.private classProxyManager.ProxyIconAdjusterClass which can turn a client's icon into the icon for the proxy of the same client.private classProxyManager.ProxyManagerClientSetTrackedClientSet implementation used by a Proxy Manager.
-
Field Summary
Fields Modifier and Type Field Description private java.util.MapconnectionMap_private UrlExporterexporter_private IconAdjustericonAdjuster_private ClientProfilelocalProfile_private static java.util.logging.Loggerlogger_private intnRemote_private HubConnectorpmConnector_private ProxyManager[]remoteManagers_private UtilServerserver_private java.util.MaptagMap_private booleanuseProxyHub_
-
Constructor Summary
Constructors Constructor Description ProxyManager(ClientProfile localProfile, UtilServer server)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HubConnectorgetManagerConnector()Returns the hub connector used by this manager for client monitoring on the local hub.private intgetManagerIndex(ProxyManager remoteManager)Returns the index by which this manager labels a given remote proxy manager.ClientProfilegetProfile()Returns the profile for this manager's local hub.private HubConnectiongetProxyConnection(ProxyManager remoteManager, java.lang.String localClientId)Returns the connection on the hub associated with a remote proxy manager which is the proxy for a given local client.private MetadatagetProxyMetadata(Client localClient)Returns the metadata to use for the remote proxy of a local client.private SubscriptionsgetProxySubscriptions(Client client)Returns the subscriptions to use for the remote proxy of a local client.voidinit(ProxyManager[] allManagers)Prepares this manager for use by informing it about all its sibling managers.private booleanisProxiedClient(Client client)Determines whether a local client is a genuine third party client which requires a remote proxy.private booleanisProxy(Client client, ProxyManager remoteManager)Determines whether a given local client is a proxy controlled by a given remote ProxyManager.private voidlocalClientAdded(Client client)Invoked when a client is added to the local hub.private voidlocalClientRemoved(Client client)Invoked when a client is removed from the local hub.private voidlocalClientUpdated(Client client, boolean metaChanged, boolean subsChanged)Invoked when information (metadata or subscriptions) have been updated for a client on the local hub.protected voidmanagerConnectionChanged(boolean isConnected)Called when this ProxyManager's connector has been disconnected (for whatever reason) from its local hub.private java.net.URLproxyIconUrl(java.net.URL localIconUrl)Returns the icon to be used for a proxy client given its local icon.private java.lang.StringproxyName(java.lang.String localName)Returns the name to be used for a proxy client given its local name.private voidremoveProxyConnection(ProxyManager remoteManager, java.lang.String localClientId)Deletes the record of the connection on the hub associated with a remote proxy manager which is the proxy for a given local client.voidsetExporter(UrlExporter exporter)Sets an object which is used to export SAMP data contents for use in remote contexts.voidsetUseProxyHub(boolean useProxyHub)Sets whether remote proxy should be generated for the local client representing the local hub.java.lang.StringtoString()
-
-
-
Field Detail
-
localProfile_
private final ClientProfile localProfile_
-
server_
private final UtilServer server_
-
pmConnector_
private final HubConnector pmConnector_
-
connectionMap_
private final java.util.Map connectionMap_
-
tagMap_
private final java.util.Map tagMap_
-
iconAdjuster_
private final IconAdjuster iconAdjuster_
-
remoteManagers_
private ProxyManager[] remoteManagers_
-
exporter_
private UrlExporter exporter_
-
useProxyHub_
private boolean useProxyHub_
-
nRemote_
private int nRemote_
-
logger_
private static final java.util.logging.Logger logger_
-
-
Constructor Detail
-
ProxyManager
public ProxyManager(ClientProfile localProfile, UtilServer server)
Constructor.- Parameters:
localProfile- profile for connection to this manager's local hubserver- server instance
-
-
Method Detail
-
getProfile
public ClientProfile getProfile()
Returns the profile for this manager's local hub.- Returns:
- profile
-
getManagerConnector
public HubConnector getManagerConnector()
Returns the hub connector used by this manager for client monitoring on the local hub.- Returns:
- hub connector
-
setExporter
public void setExporter(UrlExporter exporter)
Sets an object which is used to export SAMP data contents for use in remote contexts.- Parameters:
exporter- new exporter; may be null
-
setUseProxyHub
public void setUseProxyHub(boolean useProxyHub)
Sets whether remote proxy should be generated for the local client representing the local hub. Default is not, since they are not very interesting to talk to.- Parameters:
useProxyHub- true iff the client representing the local hub should be proxied remotely
-
init
public void init(ProxyManager[] allManagers)
Prepares this manager for use by informing it about all its sibling managers. This must be done before the bridge can start operations.- Parameters:
allManagers- array of ProxyManagers including this one, one for each hub participating in the bridge
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getProxyConnection
private HubConnection getProxyConnection(ProxyManager remoteManager, java.lang.String localClientId)
Returns the connection on the hub associated with a remote proxy manager which is the proxy for a given local client.- Parameters:
remoteManager- proxy manager for a remote bridged hublocalClientId- client ID of a client registered with this manager's local hub- Returns:
- proxy connection
-
removeProxyConnection
private void removeProxyConnection(ProxyManager remoteManager, java.lang.String localClientId)
Deletes the record of the connection on the hub associated with a remote proxy manager which is the proxy for a given local client. This proxy can no longer be used.- Parameters:
remoteManager- proxy manager for a remote bridged hublocalClientId- client ID of a client registered with this manager's local hub
-
getManagerIndex
private int getManagerIndex(ProxyManager remoteManager)
Returns the index by which this manager labels a given remote proxy manager.- Parameters:
remoteManager- manager to locate- Returns:
- index of
remoteManagerin the list
-
getProxyMetadata
private Metadata getProxyMetadata(Client localClient)
Returns the metadata to use for the remote proxy of a local client. This resembles the metadata of the local client itself, but may have some adjustments.- Parameters:
localClient- local client- Returns:
- metadata to use for client's remote proxy
-
proxyName
private java.lang.String proxyName(java.lang.String localName)
Returns the name to be used for a proxy client given its local name.- Parameters:
localName- local name- Returns:
- proxy name
-
proxyIconUrl
private java.net.URL proxyIconUrl(java.net.URL localIconUrl)
Returns the icon to be used for a proxy client given its local icon.- Parameters:
localIconUrl- URL for local icon- Returns:
- URL for proxy icon
-
getProxySubscriptions
private Subscriptions getProxySubscriptions(Client client)
Returns the subscriptions to use for the remote proxy of a local client. This resembles the subscriptions of the local client itself, but may have some adjustments.- Parameters:
localClient- local client- Returns:
- subscriptions to use for client's remote proxy
-
managerConnectionChanged
protected void managerConnectionChanged(boolean isConnected)
Called when this ProxyManager's connector has been disconnected (for whatever reason) from its local hub. It makes sure that any proxies from other ProxyManagers to the local hub are unregistered, so that no further bridge activity takes place on the local hub.- Parameters:
isConnected- true for a connection; false for a disconnection
-
localClientAdded
private void localClientAdded(Client client)
Invoked when a client is added to the local hub.- Parameters:
client- newly added client
-
localClientRemoved
private void localClientRemoved(Client client)
Invoked when a client is removed from the local hub.- Parameters:
client- recently removed client
-
localClientUpdated
private void localClientUpdated(Client client, boolean metaChanged, boolean subsChanged)
Invoked when information (metadata or subscriptions) have been updated for a client on the local hub.- Parameters:
client- updated clientmetaChanged- true if metadata may have changed (false if known unchanged)subsChanged- true if subscriptions may have changed (false if known unchanged)
-
isProxiedClient
private boolean isProxiedClient(Client client)
Determines whether a local client is a genuine third party client which requires a remote proxy. Will return false for clients which are operating on behalf of this bridge, including the ProxyManager's client tracking connection and any proxies controlled by remote ProxyManagers. Unless useProxyHub is true, will also return false for the hub client on remote hubs, since these are not very interesting to talk to.- Parameters:
client- local clienttrue- ifclienthas or should have a proxy; false if it's an organ of the bridge administration
-
isProxy
private boolean isProxy(Client client, ProxyManager remoteManager)
Determines whether a given local client is a proxy controlled by a given remote ProxyManager.- Parameters:
client- local clientremoteManager- remote proxy manager- Returns:
- true iff
clientis one ofremoteManager's proxies
-
-