Class ProxyManager


  • class ProxyManager
    extends java.lang.Object
    Takes 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:
    1. On the local hub, one connection which is there to monitor client changes
    2. On each remote hub participating in the bridge, one 'proxy' connection for every client on this manager's local hub.
    Callbacks from the hub to the proxy clients can be tunnelled by this proxy manager to their true destination on the local hub. Note that each proxy manager needs the cooperation of all the other proxy managers (the ones associated with the other bridged hubs) to make this work, so each instance of this class must be made aware of the other ProxyMangers before use (see init(org.astrogrid.samp.bridge.ProxyManager[])).
    Since:
    15 Jul 2009
    Author:
    Mark Taylor
    • Field Detail

      • connectionMap_

        private final java.util.Map connectionMap_
      • tagMap_

        private final java.util.Map tagMap_
      • 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 hub
        server - 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:
        toString in class java.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 hub
        localClientId - 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 hub
        localClientId - 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 remoteManager in 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 client
        metaChanged - 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 client
        true - if client has 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 client
        remoteManager - remote proxy manager
        Returns:
        true iff client is one of remoteManager's proxies