public DistributedStateManager(
     DatabaseCluster<Z, D> cluster, CommandDispatcherFactory dispatcherFactory) throws Exception {
   this.cluster = cluster;
   this.stateManager = cluster.getStateManager();
   StateCommandContext<Z, D> context = this;
   this.dispatcher =
       dispatcherFactory.createCommandDispatcher(cluster.getId() + ".state", context, this, this);
 }
  /**
   * {@inheritDoc}
   *
   * @see net.sf.hajdbc.state.StateManagerFactory#createStateManager(net.sf.hajdbc.DatabaseCluster)
   */
  @Override
  public <Z, D extends Database<Z>> StateManager createStateManager(DatabaseCluster<Z, D> cluster) {
    if (this.urlPattern == null) {
      throw new IllegalArgumentException(
          "No embedded database driver was detected on the classpath.");
    }

    String url = MessageFormat.format(this.urlPattern, cluster.getId(), Strings.HA_JDBC_HOME);
    DriverDatabase database = new DriverDatabase();
    database.setLocation(url);
    database.setUser(this.user);
    database.setPassword(this.password);

    this.logger.log(
        Level.INFO, "State for database cluster {0} will be persisted to {1}", cluster, url);

    return new SQLStateManager<Z, D>(cluster, database, new GenericObjectPoolFactory(this));
  }