Ejemplo n.º 1
0
 /**
  * Connect to scope with parameters. To successfully connect to scope it must have handler that
  * will accept this connection with given set of parameters. Client associated with connection is
  * added to scope clients set, connection is registered as scope event listener.
  *
  * @param conn Connection object
  * @param params Parameters passed with connection
  * @return
  *     <pre>
  * true
  * </pre>
  *     on success,
  *     <pre>
  * false
  * </pre>
  *     otherwise
  */
 public boolean connect(IConnection conn, Object[] params) {
   log.debug("Connect - scope: {} connection: {}", this, conn);
   if (enabled) {
     if (hasParent() && !parent.connect(conn, params)) {
       log.debug("Connection to parent failed");
       return false;
     }
     if (hasHandler() && !getHandler().connect(conn, this, params)) {
       log.debug("Connection to handler failed");
       return false;
     }
     if (!conn.isConnected()) {
       log.debug("Connection is not connected");
       // timeout while connecting client
       return false;
     }
     final IClient client = conn.getClient();
     // we would not get this far if there is no handler
     if (hasHandler() && !getHandler().join(client, this)) {
       return false;
     }
     // checking the connection again? why?
     if (!conn.isConnected()) {
       // timeout while connecting client
       return false;
     }
     // add the client and event listener
     if (clients.add(client) && addEventListener(conn)) {
       log.debug("Added client");
       // increment conn stats
       connectionStats.increment();
       // get connected scope
       IScope connScope = conn.getScope();
       log.trace("Connection scope: {}", connScope);
       if (this.equals(connScope)) {
         final IServer server = getServer();
         if (server instanceof Server) {
           ((Server) server).notifyConnected(conn);
         }
       }
       return true;
     }
   } else {
     log.debug("Connection failed, scope is disabled");
   }
   return false;
 }