/collection-plugins/mongodb/src/main/java/com/springsource/insight/plugin/mongodb/AbstractMongoDBExternalResourceAnalyzer.java

https://github.com/spring-projects/spring-insight-plugins · Java · 71 lines · 43 code · 10 blank · 18 comment · 2 complexity · 1c76009556ce6b3ed6fb50199e054218 MD5 · raw file

  1. /**
  2. * Copyright (c) 2009-2011 VMware, Inc. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.springsource.insight.plugin.mongodb;
  17. import java.util.ArrayList;
  18. import java.util.Collection;
  19. import java.util.Collections;
  20. import java.util.List;
  21. import com.springsource.insight.intercept.operation.Operation;
  22. import com.springsource.insight.intercept.operation.OperationType;
  23. import com.springsource.insight.intercept.topology.AbstractExternalResourceAnalyzer;
  24. import com.springsource.insight.intercept.topology.ExternalResourceDescriptor;
  25. import com.springsource.insight.intercept.topology.ExternalResourceType;
  26. import com.springsource.insight.intercept.topology.MD5NameGenerator;
  27. import com.springsource.insight.intercept.trace.Frame;
  28. import com.springsource.insight.intercept.trace.Trace;
  29. import com.springsource.insight.util.ListUtil;
  30. /**
  31. *
  32. */
  33. public abstract class AbstractMongoDBExternalResourceAnalyzer extends AbstractExternalResourceAnalyzer {
  34. public static final String MONGODB_VENDOR = "MongoDB";
  35. protected AbstractMongoDBExternalResourceAnalyzer(OperationType type) {
  36. super(type);
  37. }
  38. public Collection<ExternalResourceDescriptor> locateExternalResourceName(Trace trace, Collection<Frame> dbFrames) {
  39. if (ListUtil.size(dbFrames) <= 0) {
  40. return Collections.emptyList();
  41. }
  42. List<ExternalResourceDescriptor> dbDescriptors = new ArrayList<ExternalResourceDescriptor>(dbFrames.size());
  43. for (Frame dbFrame : dbFrames) {
  44. Operation op = dbFrame.getOperation();
  45. String host = op.get("host", String.class);
  46. int port = op.getInt("port", (-1));
  47. String dbName = op.get("dbName", String.class);
  48. String mongoHash = MD5NameGenerator.getName(dbName + host + port);
  49. String color = colorManager.getColor(op);
  50. dbDescriptors.add(new ExternalResourceDescriptor(dbFrame,
  51. "mongo:" + mongoHash,
  52. dbName,
  53. ExternalResourceType.DOCSTORE.name(),
  54. MONGODB_VENDOR,
  55. host,
  56. port,
  57. color, false));
  58. }
  59. return dbDescriptors;
  60. }
  61. }