-
Notifications
You must be signed in to change notification settings - Fork 1
HubManagement
A hub is a remote entity that allows peer encounter of long wide area networks and routed protocols, e.g. IP, see ASAPHub wiki.
In ASAPHub terms: We are on peer side. We want our peer establish a new connection to another peer over a hub. First, we need a connection to a hub.
SharkPeer sharkPeer = …; // discussed previous sections
HubConnectorDescription hubDescription = TCPHubConnectorDescription(“localhost”, 7070, true);
sharkPeer.addHubDescription(HubConnectorDescription hubDescription);
We introduced a concept of hub descriptions. It describes how to connect to a hub.
A hub is provides an open port 7070 via TCP in our example. The final true
set the multichannel option on. A new TCP connection is established for each peer encounter. This peer can communicate with more than one peer. There are more than one connection to the hub. You decide in your application context if either of both is an advantage, a disadvantage or neither.
Descriptions can be removed yb calling removeHubDescription(hubDescription)
.
Hub connections are described with a SharkPeer instance. Connections can establish in any subclass of ASAPActivity:
YourActivity extends ASAPActivity {
...
// connect all described hubs
this.connectASAPHubs();
...
// disconnect from all hubs
this.disconnectASAPHubs();
...
}
Note: Adding and removing hub descriptions can have an effect on open hub descriptions:
Hub descriptions are defined on application side and are transmitted to service side of this library. A synchronization is performed whenever a change occurs. It is tested of each open hub connections is still in our hub description list. Connection is closed if this is not the case.
To establish a connection to the ASAPHub, ASAPAndroid utilizes the HubConnectionManager interface provided by the hub. The ASAPAndroid library is divided into a service and an app layer. At the service layer, the HubConnectionManagerService class is responsible for the connection to the ASAPHub. Connection management to the hub occurs at the service layer. Since the service layer is controlled by messages from the app layer, the HubConnectionManagerService class must additionally implement the HubConnectionManagerMessageHandler interface. At the application level, essentially only the commands that should be executed on the service side are received. The Hub connection at the application level is managed by the HubConnectionManagerApplicationSide class.
If Alice wants to establish a connection to the ASAPHub from any app that uses the ASAPAndroid library, she calls the connectHub
method of the HubConnectionManagerApplicationSide
class with the connection parameters to the hub. Now, the app layer needs to notify the service layer of the ASAPAndroid library. To do this, the connection parameters are serialized, and the serialized message is sent to the service layer using the sendMessage2Service
method. Once the message is received on the service layer by the ASAPMessageHandler
, the connection parameters are deserialized. Then, the HubConnectionManagerServiceSide
is notified that a new connection request exists. The connection parameters of the connection request are stored in a list. This is done by calling the connectHub
method in the BasicHubConnectionManager
class. Finally, the connectASAPHubs
method of the HubConnectionManagerImpl
class is called. This method is responsible for the actual connection establishment. The method iterates through the list of all connection requests and establishes a connection to each hub listed there.