private void setupServer(final JournalType journalType) throws Exception {
    Configuration config =
        createDefaultNettyConfig()
            .setJournalType(journalType)
            .setJournalFileSize(ActiveMQDefaultConfiguration.getDefaultJournalFileSize())
            .setJournalMinFiles(ActiveMQDefaultConfiguration.getDefaultJournalMinFiles())
            .setJournalCompactMinFiles(2)
            .setJournalCompactPercentage(50);

    server = createServer(true, config);

    server.start();

    ServerLocator locator =
        createNettyNonHALocator()
            .setBlockOnDurableSend(false)
            .setBlockOnNonDurableSend(false)
            .setBlockOnAcknowledge(false);

    sf = createSessionFactory(locator);

    ClientSession sess = sf.createSession();

    try {
      sess.createQueue(ADDRESS, QUEUE, true);
    } catch (Exception ignored) {
    }

    sess.close();
    locator.close();
    locator = createInVMNonHALocator();
    sf = createSessionFactory(locator);
  }
  protected void startServer() throws Exception {
    Configuration config =
        createDefaultInVMConfig()
            .setJournalFileSize(ActiveMQDefaultConfiguration.getDefaultJournalFileSize())
            .setJournalCompactMinFiles(
                ActiveMQDefaultConfiguration.getDefaultJournalCompactMinFiles())
            .setJournalCompactPercentage(
                ActiveMQDefaultConfiguration.getDefaultJournalCompactPercentage())
            .setJournalMinFiles(2);

    server = super.createServer(true, config);

    server.start();
    locator = createInVMNonHALocator();
    factory = createSessionFactory(locator);
  }
  /** @throws Exception */
  private void printJournal() throws Exception {
    NIOSequentialFileFactory factory = new NIOSequentialFileFactory(new File(getJournalDir()), 100);
    JournalImpl journal =
        new JournalImpl(
            ActiveMQDefaultConfiguration.getDefaultJournalFileSize(),
            2,
            2,
            0,
            0,
            factory,
            "activemq-data",
            "amq",
            100);

    ArrayList<RecordInfo> records = new ArrayList<>();
    ArrayList<PreparedTransactionInfo> transactions = new ArrayList<>();

    journal.start();
    journal.load(records, transactions, null);

    //      System.out.println("===============================================");
    //      System.out.println("Journal records at the end:");
    //
    //      for (RecordInfo record : records)
    //      {
    //         System.out.println(record.id + ", update = " + record.isUpdate);
    //      }
    journal.stop();
  }
  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();

    Configuration config = createDefaultInVMConfig().setSecurityEnabled(true);
    server = addServer(ActiveMQServers.newActiveMQServer(config, false));
    server.start();

    notifQueue = RandomUtil.randomSimpleString();

    ActiveMQJAASSecurityManager securityManager =
        (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("admin", "admin");
    securityManager.getConfiguration().addUser("guest", "guest");
    securityManager.getConfiguration().setDefaultUser("guest");

    Role role = new Role("notif", true, true, true, true, true, true, true, true, true, true);
    Set<Role> roles = new HashSet<>();
    roles.add(role);
    server
        .getSecurityRepository()
        .addMatch(
            ActiveMQDefaultConfiguration.getDefaultManagementNotificationAddress().toString(),
            roles);

    securityManager.getConfiguration().addRole("admin", "notif");

    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    adminSession = sf.createSession("admin", "admin", false, true, true, false, 1);
    adminSession.start();

    adminSession.createTemporaryQueue(
        ActiveMQDefaultConfiguration.getDefaultManagementNotificationAddress(), notifQueue);

    notifConsumer = adminSession.createConsumer(notifQueue);
  }
public class SharedStoreSlavePolicyConfiguration implements HAPolicyConfiguration {
  private long failbackDelay = ActiveMQDefaultConfiguration.getDefaultFailbackDelay();

  private boolean failoverOnServerShutdown =
      ActiveMQDefaultConfiguration.isDefaultFailoverOnServerShutdown();

  private boolean restartBackup = ActiveMQDefaultConfiguration.isDefaultRestartBackup();

  private boolean allowFailBack = ActiveMQDefaultConfiguration.isDefaultAllowAutoFailback();

  private ScaleDownConfiguration scaleDownConfiguration;

  public SharedStoreSlavePolicyConfiguration() {}

  @Override
  public TYPE getType() {
    return TYPE.SHARED_STORE_SLAVE;
  }

  public boolean isRestartBackup() {
    return restartBackup;
  }

  public SharedStoreSlavePolicyConfiguration setRestartBackup(boolean restartBackup) {
    this.restartBackup = restartBackup;
    return this;
  }

  public ScaleDownConfiguration getScaleDownConfiguration() {
    return scaleDownConfiguration;
  }

  public SharedStoreSlavePolicyConfiguration setScaleDownConfiguration(
      ScaleDownConfiguration scaleDownConfiguration) {
    this.scaleDownConfiguration = scaleDownConfiguration;
    return this;
  }

  public boolean isAllowFailBack() {
    return allowFailBack;
  }

  public SharedStoreSlavePolicyConfiguration setAllowFailBack(boolean allowFailBack) {
    this.allowFailBack = allowFailBack;
    return this;
  }

  public boolean isFailoverOnServerShutdown() {
    return failoverOnServerShutdown;
  }

  public SharedStoreSlavePolicyConfiguration setFailoverOnServerShutdown(
      boolean failoverOnServerShutdown) {
    this.failoverOnServerShutdown = failoverOnServerShutdown;
    return this;
  }

  public long getFailbackDelay() {
    return failbackDelay;
  }

  public SharedStoreSlavePolicyConfiguration setFailbackDelay(long failbackDelay) {
    this.failbackDelay = failbackDelay;
    return this;
  }
}
  public NettyAcceptor(
      final String name,
      final ClusterConnection clusterConnection,
      final Map<String, Object> configuration,
      final BufferHandler handler,
      final ConnectionLifeCycleListener listener,
      final ScheduledExecutorService scheduledThreadPool,
      final Map<String, ProtocolManager> protocolMap) {
    this.name = name;

    this.clusterConnection = clusterConnection;

    this.configuration = configuration;

    this.handler = handler;

    this.listener = listener;

    sslEnabled =
        ConfigurationHelper.getBooleanProperty(
            TransportConstants.SSL_ENABLED_PROP_NAME,
            TransportConstants.DEFAULT_SSL_ENABLED,
            configuration);

    nioRemotingThreads =
        ConfigurationHelper.getIntProperty(
            TransportConstants.NIO_REMOTING_THREADS_PROPNAME, -1, configuration);
    backlog =
        ConfigurationHelper.getIntProperty(TransportConstants.BACKLOG_PROP_NAME, -1, configuration);
    useInvm =
        ConfigurationHelper.getBooleanProperty(
            TransportConstants.USE_INVM_PROP_NAME,
            TransportConstants.DEFAULT_USE_INVM,
            configuration);

    this.protocolHandler =
        new ProtocolHandler(protocolMap, this, configuration, scheduledThreadPool);

    this.protocolsString = getProtocols(protocolMap);

    host =
        ConfigurationHelper.getStringProperty(
            TransportConstants.HOST_PROP_NAME, TransportConstants.DEFAULT_HOST, configuration);
    port =
        ConfigurationHelper.getIntProperty(
            TransportConstants.PORT_PROP_NAME, TransportConstants.DEFAULT_PORT, configuration);
    if (sslEnabled) {
      keyStoreProvider =
          ConfigurationHelper.getStringProperty(
              TransportConstants.KEYSTORE_PROVIDER_PROP_NAME,
              TransportConstants.DEFAULT_KEYSTORE_PROVIDER,
              configuration);

      keyStorePath =
          ConfigurationHelper.getStringProperty(
              TransportConstants.KEYSTORE_PATH_PROP_NAME,
              TransportConstants.DEFAULT_KEYSTORE_PATH,
              configuration);

      keyStorePassword =
          ConfigurationHelper.getPasswordProperty(
              TransportConstants.KEYSTORE_PASSWORD_PROP_NAME,
              TransportConstants.DEFAULT_KEYSTORE_PASSWORD,
              configuration,
              ActiveMQDefaultConfiguration.getPropMaskPassword(),
              ActiveMQDefaultConfiguration.getPropMaskPassword());

      trustStoreProvider =
          ConfigurationHelper.getStringProperty(
              TransportConstants.TRUSTSTORE_PROVIDER_PROP_NAME,
              TransportConstants.DEFAULT_TRUSTSTORE_PROVIDER,
              configuration);

      trustStorePath =
          ConfigurationHelper.getStringProperty(
              TransportConstants.TRUSTSTORE_PATH_PROP_NAME,
              TransportConstants.DEFAULT_TRUSTSTORE_PATH,
              configuration);

      trustStorePassword =
          ConfigurationHelper.getPasswordProperty(
              TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME,
              TransportConstants.DEFAULT_TRUSTSTORE_PASSWORD,
              configuration,
              ActiveMQDefaultConfiguration.getPropMaskPassword(),
              ActiveMQDefaultConfiguration.getPropMaskPassword());

      enabledCipherSuites =
          ConfigurationHelper.getStringProperty(
              TransportConstants.ENABLED_CIPHER_SUITES_PROP_NAME,
              TransportConstants.DEFAULT_ENABLED_CIPHER_SUITES,
              configuration);

      enabledProtocols =
          ConfigurationHelper.getStringProperty(
              TransportConstants.ENABLED_PROTOCOLS_PROP_NAME,
              TransportConstants.DEFAULT_ENABLED_PROTOCOLS,
              configuration);

      needClientAuth =
          ConfigurationHelper.getBooleanProperty(
              TransportConstants.NEED_CLIENT_AUTH_PROP_NAME,
              TransportConstants.DEFAULT_NEED_CLIENT_AUTH,
              configuration);
    } else {
      keyStoreProvider = TransportConstants.DEFAULT_KEYSTORE_PROVIDER;
      keyStorePath = TransportConstants.DEFAULT_KEYSTORE_PATH;
      keyStorePassword = TransportConstants.DEFAULT_KEYSTORE_PASSWORD;
      trustStoreProvider = TransportConstants.DEFAULT_TRUSTSTORE_PROVIDER;
      trustStorePath = TransportConstants.DEFAULT_TRUSTSTORE_PATH;
      trustStorePassword = TransportConstants.DEFAULT_TRUSTSTORE_PASSWORD;
      enabledCipherSuites = TransportConstants.DEFAULT_ENABLED_CIPHER_SUITES;
      enabledProtocols = TransportConstants.DEFAULT_ENABLED_PROTOCOLS;
      needClientAuth = TransportConstants.DEFAULT_NEED_CLIENT_AUTH;
    }

    tcpNoDelay =
        ConfigurationHelper.getBooleanProperty(
            TransportConstants.TCP_NODELAY_PROPNAME,
            TransportConstants.DEFAULT_TCP_NODELAY,
            configuration);
    tcpSendBufferSize =
        ConfigurationHelper.getIntProperty(
            TransportConstants.TCP_SENDBUFFER_SIZE_PROPNAME,
            TransportConstants.DEFAULT_TCP_SENDBUFFER_SIZE,
            configuration);
    tcpReceiveBufferSize =
        ConfigurationHelper.getIntProperty(
            TransportConstants.TCP_RECEIVEBUFFER_SIZE_PROPNAME,
            TransportConstants.DEFAULT_TCP_RECEIVEBUFFER_SIZE,
            configuration);

    this.scheduledThreadPool = scheduledThreadPool;

    batchDelay =
        ConfigurationHelper.getLongProperty(
            TransportConstants.BATCH_DELAY, TransportConstants.DEFAULT_BATCH_DELAY, configuration);

    directDeliver =
        ConfigurationHelper.getBooleanProperty(
            TransportConstants.DIRECT_DELIVER,
            TransportConstants.DEFAULT_DIRECT_DELIVER,
            configuration);

    httpUpgradeEnabled =
        ConfigurationHelper.getBooleanProperty(
            TransportConstants.HTTP_UPGRADE_ENABLED_PROP_NAME,
            TransportConstants.DEFAULT_HTTP_UPGRADE_ENABLED,
            configuration);

    connectionsAllowed =
        ConfigurationHelper.getLongProperty(
            TransportConstants.CONNECTIONS_ALLOWED,
            TransportConstants.DEFAULT_CONNECTIONS_ALLOWED,
            configuration);
  }