Пример #1
0
  @Override
  public Connection createConnection() {
    if (InVMConnector.failOnCreateConnection) {
      InVMConnector.incFailures();

      ActiveMQServerLogger.LOGGER.debug("Returning null on InVMConnector for tests");
      // For testing only
      return null;
    }

    if (acceptor == null) {
      return null;
    }

    if (acceptor.getConnectionsAllowed() == -1
        || acceptor.getConnectionCount() < acceptor.getConnectionsAllowed()) {
      Connection conn =
          internalCreateConnection(
              acceptor.getHandler(), new Listener(), acceptor.getExecutorFactory().getExecutor());

      acceptor.connect((String) conn.getID(), handler, this, executorFactory.getExecutor());
      return conn;
    } else {
      if (ActiveMQServerLogger.LOGGER.isDebugEnabled()) {
        ActiveMQServerLogger.LOGGER.debug(
            new StringBuilder()
                .append("Connection limit of ")
                .append(acceptor.getConnectionsAllowed())
                .append(" reached. Refusing connection."));
      }
      return null;
    }
  }
Пример #2
0
 private static synchronized void incFailures() {
   InVMConnector.failures++;
   if (InVMConnector.failures == InVMConnector.numberOfFailures) {
     InVMConnector.resetFailures();
   }
 }