public GGMonitoredSourceInfo buildGGMonitoredSourceInfo(
      LogicalSourceStaticConfig sourceConfig, PhysicalSourceStaticConfig pConfig)
      throws DatabusException, InvalidConfigException {
    // udpate partition mapping
    PartitionFunction partitionFunction =
        GGEventGenerationFactory.buildPartitionFunction(sourceConfig);
    _partitionFunctionHashMap.put((int) sourceConfig.getId(), partitionFunction);

    EventSourceStatistics statisticsBean = new EventSourceStatistics(sourceConfig.getName());

    GGMonitoredSourceInfo sourceInfo =
        new GGMonitoredSourceInfo(sourceConfig.getId(), sourceConfig.getName(), statisticsBean);

    registerMbeans(sourceInfo);

    return sourceInfo;
  }
    @Override
    public void run() {

      ConcurrentAppendableCompositeFileInputStream compositeInputStream = null;
      try {
        if (_xmlCallback == null) _xmlCallback = new HandleXmlCallback();

        String xmlDir = GGEventGenerationFactory.uriToGGDir(_pConfig.getUri());
        String xmlPrefix = GGEventGenerationFactory.uriToXmlPrefix(_pConfig.getUri());
        File file = new File(xmlDir);
        if (!file.exists() || !file.isDirectory()) {
          _log.fatal(
              "Unable to load the directory: "
                  + xmlDir
                  + " it doesn't seem to be a valid directory");
          throw new DatabusException("Invalid trail file directory");
        }

        boolean parseError = false;
        do {
          try {
            _log.info(
                "Using xml directory : " + xmlDir + " and using the xml Prefix : " + xmlPrefix);
            compositeInputStream = locateScnInTrailFile(xmlDir, xmlPrefix);
            compositeInputStream.setGGParserStats(_ggParserStats);
            _log.info("Attempting to start the parser...");

            // Not a retry, first time the producer is started, in which case, start the eventBuffer
            // with the appropriate scn
            if (!parseError) {
              _log.info("Starting dbusEventBuffer with _scn : " + _startPrevScn.get());
              getEventBuffer().start(_startPrevScn.get());
            } else {
              _log.warn(
                  "Umm, looks like the parser had failed, this is an retry attempt using _scn: "
                      + _scn.get());
              _log.info("CompositeInputStream used:" + compositeInputStream);
            }

            StaxBuilder builder =
                new StaxBuilder(
                    _schemaRegistryService,
                    wrapStreamWithXmlTags(compositeInputStream),
                    _pConfig,
                    _xmlCallback);

            if (_log.isDebugEnabled())
              _log.debug("CompositeInputStream used:" + compositeInputStream);

            _parser = builder.getParser();
            builder
                .processXml(); // --> The call doesn't return after this (it starts processing the
            // xml trail files), unless a shutdown is requested or an exception
            // is thrown.
            parseError =
                false; // --> If this code path is executed, then the shutdown has been requested
          } catch (XMLStreamException e) {
            _ggParserStats.addParsingError();

            // If the parser was in the middle of execution and an shutdown was issued, then an
            // xmlstream exception is expected.
            if (_shutdownRequested) {
              parseError = false;
            } else {
              _log.error("Error while parsing the xml, will retry loading the parser", e);
              _log.info("Last scn seen before the crash: " + _scn.get());
              _log.info("CompositeInputStream used:" + compositeInputStream);
              parseError = true;
            }
          } finally {
            if (compositeInputStream != null) compositeInputStream.close();
          }
        } while (parseError); // TODO && retry count (add config to control number of retires)

      } catch (RuntimeException e) {
        _log.info("CompositeInputStream used:" + compositeInputStream);
        _log.error("Error while parsing data, compositeInputStream shutting down the relay", e);
        _currentState = GoldenGateEventProducer.State.SHUTDOWN;
        throw e;
      } catch (Exception e) {
        _log.info("CompositeInputStream used:" + compositeInputStream);
        _log.error("Error while parsing data, compositeInputStream shutting down the relay", e);
        _currentState = GoldenGateEventProducer.State.SHUTDOWN;
        return;
      }
    }