Java源码示例:io.opentracing.contrib.jdbc.parser.URLParser

示例1
@Override
public Connection connect(String url, Properties info) throws SQLException {
  // if there is no url, we have problems
  if (url == null) {
    throw new SQLException("url is required");
  }

  final Set<String> ignoreStatements;
  final boolean withActiveSpanOnly;
  if (interceptorMode) {
    withActiveSpanOnly = TracingDriver.withActiveSpanOnly;
    ignoreStatements = TracingDriver.ignoreStatements;
  } else if (acceptsURL(url)) {
    withActiveSpanOnly = url.contains(WITH_ACTIVE_SPAN_ONLY);
    ignoreStatements = extractIgnoredStatements(url);
  } else {
    return null;
  }

  url = extractRealUrl(url);

  // find the real driver for the URL
  final Driver wrappedDriver = findDriver(url);

  final Tracer currentTracer = getTracer();
  final ConnectionInfo connectionInfo = URLParser.parser(url);
  final Span span = buildSpan("AcquireConnection", "", connectionInfo, withActiveSpanOnly,
      Collections.<String>emptySet(), currentTracer);
  final Connection connection;
  try (Scope ignored = currentTracer.activateSpan(span)) {
    connection = wrappedDriver.connect(url, info);
  } finally {
    span.finish();
  }

  return WrapperProxy
      .wrap(connection, new TracingConnection(connection, connectionInfo, withActiveSpanOnly,
          ignoreStatements, currentTracer));
}
 
示例2
/**
 * Intercepts calls to {@link DataSource#getConnection()} (and related), wrapping the outcome in a
 * {@link TracingConnection} proxy
 *
 * @param pjp the intercepted join point
 * @return a new {@link TracingConnection} proxy wrapping the result of the joint point
 * @throws Throwable in case of wrong JDBC URL
 */
@Around("execution(java.sql.Connection *.getConnection(..)) && target(javax.sql.DataSource)")
public Object getConnection(final ProceedingJoinPoint pjp) throws Throwable {
  Connection conn = (Connection) pjp.proceed();
  if (WrapperProxy.isWrapper(conn, TracingConnection.class)) {
    return conn;
  }
  String url = conn.getMetaData().getURL();
  ConnectionInfo connectionInfo = URLParser.parse(url);
  return WrapperProxy.wrap(conn, new TracingConnection(conn, connectionInfo,
      withActiveSpanOnly, ignoredStatements, GlobalTracer.get()));
}
 
示例3
public TracingDataSource(DataSource delegate) {
  this.delegate = delegate;
  try (Connection connection = delegate.getConnection()) {
    connectionInfo = URLParser.parser(connection.getMetaData().getURL());
    LOG.debug(
        "URL {} connectionInfo {}",
        connection.getMetaData().getURL(),
        connectionInfo.getPeerService());
  } catch (SQLException e) {
    throw new RuntimeException(e);
  }
}