/**
   * {@inheritDoc}
   *
   * @see
   *     com.continuent.tungsten.replicator.plugin.ReplicatorPlugin#prepare(com.continuent.tungsten.replicator.plugin.PluginContext)
   */
  public synchronized void prepare(PluginContext context)
      throws ReplicatorException, InterruptedException {
    // Prepare database connection.
    if (url != null && url.trim().length() > 0) {
      logger.info("Preparing SQL catalog tables");
      ReplicatorRuntime runtime = (ReplicatorRuntime) context;
      String metadataSchema = context.getReplicatorSchemaName();
      catalog = new CatalogManager(runtime);
      catalog.connect(url, user, password, metadataSchema, vendor);
      catalog.prepareSchema();
    } else logger.info("SQL catalog tables are disabled");

    // Configure and prepare the log.
    diskLog = new DiskLog();
    diskLog.setDoChecksum(doChecksum);
    diskLog.setEventSerializerClass(eventSerializer);
    diskLog.setLogDir(logDir);
    diskLog.setLogFileSize(logFileSize);
    diskLog.setLogFileRetainMillis(logFileRetainMillis);
    diskLog.setLogConnectionTimeoutMillis(logConnectionTimeout * 1000);
    diskLog.setBufferSize(bufferSize);
    diskLog.setFsyncOnFlush(fsyncOnFlush);
    if (fsyncOnFlush) {
      // Only used with fsync.
      diskLog.setFlushIntervalMillis(flushIntervalMillis);
    }
    diskLog.setReadOnly(readOnly);
    diskLog.prepare();
    logger.info("Log preparation is complete");

    // Start server for THL connections.
    if (context.isRemoteService() == false) {
      try {
        server = new Server(context, sequencer, this);
        server.start();
      } catch (IOException e) {
        throw new ReplicatorException("Unable to start THL server", e);
      }
    }
  }