Skip to content
Snippets Groups Projects
Commit 30068839 authored by amine.chbari.etu's avatar amine.chbari.etu
Browse files

refactoriser la methode connect() , organisation de la classe 'CoreHandler.java'

parent 7916b5bd
Branches
No related tags found
No related merge requests found
......@@ -47,6 +47,49 @@ public class CoreHandler implements IScopeHandler, CoreHandlerMXBean {
return connect(conn, scope, null);
}
/** Auxiliary function to connect
*
* Creates a client if needed then sets the client on the connection
*
* @param client
* the connected client
* @param clientRegistry
* the client's registry
* @param conn
* Client connection
* @param params
* Parameters passed from client side with connect call
* @return the connection with an updated client
*/
private IConnection connectionHandleClient(IClient client, IClientRegistry clientRegistry, IConnection conn, Object[] params) {
if (client == null) {
if (!clientRegistry.hasClient(conn.getSessionId())) {
if (conn instanceof RTMPTConnection) {
log.debug("Creating new client for RTMPT connection");
// create a new client using the session id as the client's id
client = new Client(conn.getSessionId(), (ClientRegistry) clientRegistry);
clientRegistry.addClient(client);
// set the client on the connection
conn.setClient(client);
} else if (conn instanceof RTMPConnection) {
log.debug("Creating new client for RTMP connection");
// this is a new connection, create a new client to hold it
client = clientRegistry.newClient(params);
// set the client on the connection
conn.setClient(client);
}
} else {
client = clientRegistry.lookupClient(conn.getSessionId());
conn.setClient(client);
}
} else {
// set the client on the connection
conn.setClient(client);
}
return conn;
}
/**
* Connects client to the scope
*
......@@ -80,30 +123,10 @@ public class CoreHandler implements IScopeHandler, CoreHandlerMXBean {
log.debug("Client registry: {}", (clientRegistry == null ? "is null" : "not null"));
if (clientRegistry != null) {
IClient client = conn.getClient();
if (client == null) {
if (!clientRegistry.hasClient(id)) {
if (conn instanceof RTMPTConnection) {
log.debug("Creating new client for RTMPT connection");
// create a new client using the session id as the client's id
client = new Client(id, (ClientRegistry) clientRegistry);
clientRegistry.addClient(client);
// set the client on the connection
conn.setClient(client);
} else if (conn instanceof RTMPConnection) {
log.debug("Creating new client for RTMP connection");
// this is a new connection, create a new client to hold it
client = clientRegistry.newClient(params);
// set the client on the connection
conn.setClient(client);
}
} else {
client = clientRegistry.lookupClient(id);
conn.setClient(client);
}
} else {
// set the client on the connection
conn.setClient(client);
}
// call connectionHandleClient to handle all the cases for this connection
conn = connectionHandleClient(client, clientRegistry, conn, params);
// assign connection to client
conn.initialize(client);
// we could checked for banned clients here
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment