com.mongodb.connection.ServerDescription Java Examples

The following examples show how to use com.mongodb.connection.ServerDescription. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MongoClientIT.java    From uavstack with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void preProcess(WriteOperation t, Object proxy, Method method, Object[] args) {

    if (!method.getName().equals("execute")) {
        return;
    }

    WriteBinding binding = (WriteBinding) args[0];
    ServerDescription serverDesc = binding.getWriteConnectionSource().getServerDescription();

    String address = serverDesc.getAddress().toString();

    String operationType = t.getClass().getSimpleName();

    String url = "mongo://" + address + "/" + dbName;

    Map<String, Object> params = new HashMap<String, Object>();
    params.put(CaptureConstants.INFO_CLIENT_REQUEST_URL, url);
    params.put(CaptureConstants.INFO_CLIENT_REQUEST_ACTION, operationType);
    params.put(CaptureConstants.INFO_CLIENT_APPID, applicationId);
    params.put(CaptureConstants.INFO_CLIENT_TYPE, "mongo.client");

    if (logger.isDebugable()) {
        logger.debug("Invoke START:" + url + ",op=" + operationType, null);
    }

    UAVServer.instance().runMonitorCaptureOnServerCapPoint(CaptureConstants.CAPPOINT_APP_CLIENT,
            Monitor.CapturePhase.PRECAP, params);

    // register adapter
    UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter",
            "registerAdapter", MongoClientAdapter.class);

    ivcContextParams = (Map<String, Object>) UAVServer.instance().runSupporter(
            "com.creditease.uav.apm.supporters.InvokeChainSupporter", "runCap",
            InvokeChainConstants.CHAIN_APP_CLIENT, InvokeChainConstants.CapturePhase.PRECAP, params,
            MongoClientAdapter.class, args);
}
 
Example #2
Source File: MongoClientIT.java    From uavstack with Apache License 2.0 5 votes vote down vote up
private void doCap(int rc, WriteBinding binding, Throwable e) {

            ServerDescription serverDesc = binding.getWriteConnectionSource().getServerDescription();

            String targetServer = "Mongo" + toVersionString(serverDesc.getVersion()) + "_"
                    + serverDesc.getType().toString();

            Map<String, Object> params = new HashMap<String, Object>();

            params.put(CaptureConstants.INFO_CLIENT_TARGETSERVER, targetServer);
            params.put(CaptureConstants.INFO_CLIENT_RESPONSECODE, rc);

            if (logger.isDebugable()) {
                logger.debug("Invoke END: rc=" + rc + "," + targetServer, null);
            }

            UAVServer.instance().runMonitorCaptureOnServerCapPoint(CaptureConstants.CAPPOINT_APP_CLIENT,
                    Monitor.CapturePhase.DOCAP, params);

            if (rc == -1) {
                params.put(CaptureConstants.INFO_CLIENT_RESPONSESTATE, e.toString());
            }
            if (ivcContextParams != null) {
                ivcContextParams.putAll(params);
            }

            UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter", "runCap",
                    InvokeChainConstants.CHAIN_APP_CLIENT, InvokeChainConstants.CapturePhase.DOCAP, ivcContextParams,
                    MongoClientAdapter.class, null);
        }
 
Example #3
Source File: MongoClientIT.java    From uavstack with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void preProcess(ReadOperation t, Object proxy, Method method, Object[] args) {

    if (!method.getName().equals("execute")) {
        return;
    }

    ReadBinding binding = (ReadBinding) args[0];
    ServerDescription serverDesc = binding.getReadConnectionSource().getServerDescription();

    String address = serverDesc.getAddress().toString();

    String operationType = t.getClass().getSimpleName();

    String url = "mongo://" + address + "/" + dbName;

    Map<String, Object> params = new HashMap<String, Object>();
    params.put(CaptureConstants.INFO_CLIENT_REQUEST_URL, url);
    params.put(CaptureConstants.INFO_CLIENT_REQUEST_ACTION, operationType);
    params.put(CaptureConstants.INFO_CLIENT_APPID, applicationId);
    params.put(CaptureConstants.INFO_CLIENT_TYPE, "mongo.client");

    if (logger.isDebugable()) {
        logger.debug("Invoke START:" + url + ",op=" + operationType, null);
    }

    UAVServer.instance().runMonitorCaptureOnServerCapPoint(CaptureConstants.CAPPOINT_APP_CLIENT,
            Monitor.CapturePhase.PRECAP, params);

    // register adapter
    UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter",
            "registerAdapter", MongoClientAdapter.class);

    ivcContextParams = (Map<String, Object>) UAVServer.instance().runSupporter(
            "com.creditease.uav.apm.supporters.InvokeChainSupporter", "runCap",
            InvokeChainConstants.CHAIN_APP_CLIENT, InvokeChainConstants.CapturePhase.PRECAP, params,
            MongoClientAdapter.class, args);
}
 
Example #4
Source File: MongoClientIT.java    From uavstack with Apache License 2.0 5 votes vote down vote up
private void doCap(int rc, ReadBinding binding, Throwable e) {

            ServerDescription serverDesc = binding.getReadConnectionSource().getServerDescription();

            String targetServer = "Mongo" + toVersionString(serverDesc.getVersion()) + "_"
                    + serverDesc.getType().toString();

            Map<String, Object> params = new HashMap<String, Object>();

            params.put(CaptureConstants.INFO_CLIENT_TARGETSERVER, targetServer);
            params.put(CaptureConstants.INFO_CLIENT_RESPONSECODE, rc);

            if (logger.isDebugable()) {
                logger.debug("Invoke END: rc=" + rc + "," + targetServer, null);
            }

            UAVServer.instance().runMonitorCaptureOnServerCapPoint(CaptureConstants.CAPPOINT_APP_CLIENT,
                    Monitor.CapturePhase.DOCAP, params);

            if (rc == -1) {
                params.put(CaptureConstants.INFO_CLIENT_RESPONSESTATE, e.toString());
            }
            if (ivcContextParams != null) {
                ivcContextParams.putAll(params);
            }

            UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter", "runCap",
                    InvokeChainConstants.CHAIN_APP_CLIENT, InvokeChainConstants.CapturePhase.DOCAP, ivcContextParams,
                    MongoClientAdapter.class, null);
        }
 
Example #5
Source File: MongoRemotePeerHelper.java    From skywalking with Apache License 2.0 5 votes vote down vote up
public static String getRemotePeer(Cluster cluster) {
    StringBuilder peersBuilder = new StringBuilder();
    for (ServerDescription description : cluster.getDescription().getAll()) {
        ServerAddress address = description.getAddress();
        peersBuilder.append(address.getHost()).append(":").append(address.getPort()).append(";");
    }
    return peersBuilder.substring(0, peersBuilder.length() - 1);
}
 
Example #6
Source File: MongoDriverConnectInterceptor3_0.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
private List<String> getHostList(Object arg) {
    if (!(arg instanceof Cluster)) {
        return Collections.emptyList();
    }

    final Cluster cluster = (Cluster) arg;

    final List<String> hostList = new ArrayList<String>();

    Collection<ServerDescription> serverDescriptions;// = cluster.getDescription().getAll();//.getServerDescriptions();

    try {
        ClusterDescription.class.getDeclaredMethod("getServerDescriptions");
        serverDescriptions = cluster.getDescription().getServerDescriptions();
    } catch (NoSuchMethodException e) {
        serverDescriptions = cluster.getDescription().getAll();
    }

    for (ServerDescription serverDescription : serverDescriptions) {

        ServerAddress serverAddress = serverDescription.getAddress();
        final String hostAddress = HostAndPort.toHostAndPortString(serverAddress.getHost(), serverAddress.getPort());
        hostList.add(hostAddress);
    }

    return hostList;
}