/**
   * The "do it" method called by the SingleMethodActivator. Receive information from its probes
   * (getObjectsFromAllProbes()) and send them to bee projectionists (EpiphyteProjectionist)
   */
  public void observe() {
    if (((BeeControler) redControler.getAgentNb(0)).getPurposeName().equals("carre")) {
      watchRedQueensPoints();
      if (redPoints.length > 0) {
        msg.setTable(redPoints);
        broadcastMessage(
            BeeLauncher.BEE_COMMUNITY, "simulation", Color.red.toString() + "Controler", msg);
      }
    }

    if (((BeeControler) blueControler.getAgentNb(0)).getPurposeName().equals("carre")) {
      watchBlueQueensPoints();
      if (bluePoints.length > 0) {
        msg.setTable(bluePoints);
        broadcastMessage(
            BeeLauncher.BEE_COMMUNITY, "simulation", Color.blue.toString() + "Controler", msg);
      }
    }

    if (((BeeControler) greenControler.getAgentNb(0)).getPurposeName().equals("carre")) {
      watchGreenQueensPoints();
      if (greenPoints.length > 0) {
        msg.setTable(greenPoints);
        broadcastMessage(
            BeeLauncher.BEE_COMMUNITY, "simulation", Color.green.toString() + "Controler", msg);
      }
    }
  }
Example #2
0
  /**
   * return the RrdGraphDef for this graph, used the indicated probe any data can be overridden of a
   * provided map of Plottable
   *
   * @param probe
   * @param ownData data used to override probe's own values
   * @return
   * @throws IOException
   * @throws RrdException
   */
  public DataProcessor getPlottedDatas(Probe<?, ?> probe, Map<?, ?> ownData, long start, long end)
      throws IOException {
    DataProcessor retValue = new DataProcessor(start, end);
    String rrdName = probe.getRrdName();

    String lastName = null;
    for (DsDesc ds : allds) {
      boolean stack = ds.graphType == GraphType.STACK;
      boolean plotted = stack || ds.graphType == GraphType.LINE || ds.graphType == GraphType.AREA;
      if (ds.rpn == null && ds.dsName != null) {
        // Does the datas existe in the provided values
        if (ownData != null && ownData.containsKey(ds.dsName) && ds.graphType == GraphType.LINE) {
          retValue.addDatasource(ds.name, (Plottable) ownData.get(ds.dsName));
        }
        // Or they might be on the associated rrd
        else if (probe.dsExist(ds.dsName)) {
          retValue.addDatasource(ds.name, rrdName, ds.dsName, ds.cf);
        }
      } else if (ds.rpn != null) {
        retValue.addDatasource(ds.name, ds.rpn);
      }
      if (plotted && stack) {
        retValue.addDatasource("Plotted" + ds.name, lastName + ", " + ds.name + ", +");
      } else if (plotted) {
        retValue.addDatasource("Plotted" + ds.name, ds.name);
      }
      lastName = ds.name;
    }
    if (logger.isTraceEnabled()) {
      logger.trace("Datastore for " + getName());
      for (String s : retValue.getSourceNames()) logger.trace("\t" + s);
    }
    return retValue;
  }
  public void check(Probe probe) {
    int tries = 0;
    while (!probe.isSatisfied() && tries < waitTimes.length) {
      probe.sample();
      Uninterruptibles.sleepUninterruptibly(waitTimes[tries], TimeUnit.MILLISECONDS);
      tries++;
    }

    if (!probe.isSatisfied()) {
      throw new AssertionError(probe.message());
    }
  }
  @Test
  public void isNotSatisfiedIfWebElementNotLocated() {

    context.checking(
        new Expectations() {
          {
            oneOf(element).find();
            will(returnValue(null));
          }
        });

    probe.doProbe();
    assertThat(probe.isSatisfied(), is(false));
  }
Example #5
0
  @Override
  public PEnumerate executePEnumerate(VirtualFrame frame) throws UnexpectedResultException {
    probe.enter(child, frame);
    PEnumerate result;

    try {
      result = child.executePEnumerate(frame);
    } catch (KillException e) {
      throw (e);
    } catch (Exception e) {
      probe.leaveExceptional(child, frame, e);
      throw (e);
    }

    return result;
  }
Example #6
0
  @Override
  public Object execute(VirtualFrame frame) {
    probe.enter(child, frame);
    Object result;

    try {
      result = child.execute(frame);
      probe.leave(child, frame);
    } catch (KillException e) {
      throw (e);
    } catch (Exception e) {
      probe.leaveExceptional(child, frame, e);
      throw (e);
    }

    return result;
  }
Example #7
0
  @Override
  public int executeInt(VirtualFrame frame) throws UnexpectedResultException {
    probe.enter(child, frame);
    int result;

    try {
      result = child.executeInt(frame);
      probe.leave(child, frame);
    } catch (KillException e) {
      throw (e);
    } catch (Exception e) {
      probe.leaveExceptional(child, frame, e);
      throw (e);
    }

    return result;
  }
  @Test
  public void displaysCorrectFailureDescriptionForProbeWhenElementDoesNotExist() {
    final StringDescription description = new StringDescription();

    probe.describeFailureTo(description);

    assertThat(description.toString(), is("The element does not exist"));
  }
Example #9
0
  @Override
  public PSequenceIterator executePSequenceIterator(VirtualFrame frame)
      throws UnexpectedResultException {
    probe.enter(child, frame);
    PSequenceIterator result;

    try {
      result = child.executePSequenceIterator(frame);
      probe.leave(child, frame);
    } catch (KillException e) {
      throw (e);
    } catch (Exception e) {
      probe.leaveExceptional(child, frame, e);
      throw (e);
    }

    return result;
  }
Example #10
0
  @Override
  public PythonBuiltinClass executePythonBuiltinClass(VirtualFrame frame)
      throws UnexpectedResultException {
    probe.enter(child, frame);
    PythonBuiltinClass result;

    try {
      result = child.executePythonBuiltinClass(frame);
      probe.leave(child, frame);
    } catch (KillException e) {
      throw (e);
    } catch (Exception e) {
      probe.leaveExceptional(child, frame, e);
      throw (e);
    }

    return result;
  }
  @Test
  public void isSatisfiedIfWebElementHasBeenLocatedAndMatcherMatches() {

    final WebElement webElement = context.mock(WebElement.class);

    context.checking(
        new Expectations() {
          {
            oneOf(element).find();
            will(returnValue(webElement));

            oneOf(elementMatcher).matches(webElement);
            will(returnValue(true));
          }
        });

    probe.doProbe();
    assertThat(probe.isSatisfied(), is(true));
  }
Example #12
0
  private void initializeBeanResults(ResultSet rs) {
    try {
      ClassInfo classInfo = ClassInfo.getInstance(getResultClass());
      String[] propertyNames = classInfo.getWriteablePropertyNames();

      Map propertyMap = new HashMap();
      for (int i = 0; i < propertyNames.length; i++) {
        propertyMap.put(propertyNames[i].toUpperCase(java.util.Locale.ENGLISH), propertyNames[i]);
      }

      List resultMappingList = new ArrayList();
      ResultSetMetaData rsmd = rs.getMetaData();
      for (int i = 0, n = rsmd.getColumnCount(); i < n; i++) {
        String columnName = getColumnIdentifier(rsmd, i + 1);
        String upperColumnName = columnName.toUpperCase(java.util.Locale.ENGLISH);
        String matchedProp = (String) propertyMap.get(upperColumnName);
        Class type = null;
        if (matchedProp == null) {
          Probe p = ProbeFactory.getProbe(this.getResultClass());
          try {
            type = p.getPropertyTypeForSetter(this.getResultClass(), columnName);
          } catch (Exception e) {
            // TODO - add logging to this class?
          }
        } else {
          type = classInfo.getSetterType(matchedProp);
        }
        if (type != null || matchedProp != null) {
          ResultMapping resultMapping = new ResultMapping();
          resultMapping.setPropertyName((matchedProp != null ? matchedProp : columnName));
          resultMapping.setColumnName(columnName);
          resultMapping.setColumnIndex(i + 1);
          resultMapping.setTypeHandler(
              getDelegate().getTypeHandlerFactory().getTypeHandler(type)); // map SQL to JDBC type
          resultMappingList.add(resultMapping);
        }
      }
      setResultMappingList(resultMappingList);

    } catch (SQLException e) {
      throw new RuntimeException("Error automapping columns. Cause: " + e);
    }
  }
  @Test
  public void isNotSatisfiedIfMatcherDoesNotMatch() {

    final WebElement webElement = context.mock(WebElement.class);

    context.checking(
        new Expectations() {
          {
            oneOf(element).find();
            will(returnValue(webElement));

            oneOf(elementMatcher).matches(webElement);
            will(returnValue(false));
          }
        });

    probe.doProbe();
    assertThat(probe.isSatisfied(), is(false));
  }
Example #14
0
  /**
   * @param bean
   * @param probe
   * @return the set of dependents
   */
  static Set<Dependency> getDependents(Bean<?> bean, Probe probe) {
    Set<Dependency> dependents = new HashSet<Dependency>();
    for (Bean<?> candidate : probe.getBeans()) {
      if (candidate.equals(bean)) {
        continue;
      }
      BeanManager beanManager = probe.getBeanManager(candidate);
      if (beanManager == null) {
        // Don't process built-in beans
        continue;
      }
      Set<InjectionPoint> injectionPoints = candidate.getInjectionPoints();
      if (injectionPoints != null && !injectionPoints.isEmpty()) {
        for (InjectionPoint injectionPoint : injectionPoints) {

          // At this point unsatisfied or ambiguous dependency should not exits
          Bean<?> candidateDependency =
              beanManager.resolve(
                  beanManager.getBeans(
                      injectionPoint.getType(),
                      injectionPoint
                          .getQualifiers()
                          .toArray(new Annotation[injectionPoint.getQualifiers().size()])));
          boolean satisfies = false;

          if (isBuiltinBeanButNotExtension(candidateDependency)) {
            satisfies =
                bean.equals(
                    probe.getBean(
                        Components.getBuiltinBeanId((AbstractBuiltInBean<?>) candidateDependency)));
          } else {
            satisfies = bean.equals(candidateDependency);
          }
          if (satisfies) {
            dependents.add(new Dependency(candidate, injectionPoint));
          }
        }
      }
    }
    return dependents;
  }
  @Test
  public void displaysCorrectFailureDescriptionForProbeWhenElementDoesNotMatch() {
    final StringDescription description = new StringDescription();

    final WebElement webElement = context.mock(WebElement.class);

    context.checking(
        new Expectations() {
          {
            oneOf(element).find();
            will(returnValue(webElement));

            oneOf(elementMatcher).describeTo(description);
          }
        });

    probe.doProbe();
    probe.describeFailureTo(description);

    assertThat(description.toString(), is("The element does not match "));
  }
Example #16
0
 @Override
 public void returnVoid(Node node, VirtualFrame frame) {
   this.probe.checkProbeUnchanged();
   if (firstInstrumentNode != null) {
     firstInstrumentNode.returnVoid(node, frame);
   }
   final AfterTagInstrument afterTagInstrument = probe.getAfterTagInstrument();
   if (afterTagInstrument != null) {
     afterTagInstrument
         .getListener()
         .onReturnVoid(probe, ((WrapperNode) this.getParent()).getChild(), frame);
   }
 }
Example #17
0
 @Override
 public void enter(Node node, VirtualFrame frame) {
   this.probe.checkProbeUnchanged();
   final BeforeTagInstrument beforeTagInstrument = probe.getBeforeTagInstrument();
   if (beforeTagInstrument != null) {
     beforeTagInstrument
         .getListener()
         .onEnter(probe, ((WrapperNode) this.getParent()).getChild(), frame);
   }
   if (firstInstrumentNode != null) {
     firstInstrumentNode.enter(node, frame);
   }
 }
  @Test
  public void displaysCorrectDescriptionForProbe() {

    final StringDescription description = new StringDescription();

    context.checking(
        new Expectations() {
          {
            oneOf(describer).describeTo(description);
          }
        });

    probe.describeTo(description);
  }
Example #19
0
 @Override
 public void returnExceptional(Node node, VirtualFrame frame, Throwable exception) {
   if (exception instanceof KillException) {
     throw (KillException) exception;
   }
   if (exception instanceof QuitException) {
     throw (QuitException) exception;
   }
   this.probe.checkProbeUnchanged();
   if (firstInstrumentNode != null) {
     firstInstrumentNode.returnExceptional(node, frame, exception);
   }
   final AfterTagInstrument afterTagInstrument = probe.getAfterTagInstrument();
   if (afterTagInstrument != null) {
     afterTagInstrument
         .getListener()
         .onReturnExceptional(
             probe, ((WrapperNode) this.getParent()).getChild(), frame, exception);
   }
 }
Example #20
0
 /**
  * @param bda
  * @param bean
  * @return true if the bda is null or the id of the BDA for the given bean equals to the value
  */
 boolean testBda(String bda, Bean<?> bean) {
   if (bda == null) {
     return true;
   }
   if (bean == null) {
     return false;
   }
   BeanManagerImpl beanManagerImpl = probe.getBeanManager(bean);
   if (beanManagerImpl == null) {
     return false;
   }
   if (FILTER_ADDITIONAL_BDAS_MARKER.equals(bda)) {
     if (beanManagerImpl.getId().endsWith(ADDITIONAL_BDA_SUFFIX)) {
       return false;
     }
   } else {
     if (!Components.getId(beanManagerImpl.getId()).equals(bda)) {
       return false;
     }
   }
   return true;
 }
Example #21
0
 /**
  * @param bean
  * @param beanManager
  * @param probe
  * @return the set of dependencies
  */
 static Set<Dependency> getDependencies(Bean<?> bean, BeanManager beanManager, Probe probe) {
   Set<Dependency> dependencies = new HashSet<Dependency>();
   Set<InjectionPoint> injectionPoints = bean.getInjectionPoints();
   if (injectionPoints != null && !injectionPoints.isEmpty()) {
     for (InjectionPoint injectionPoint : injectionPoints) {
       // At this point unsatisfied or ambiguous dependency should not exits
       Bean<?> dependency =
           beanManager.resolve(
               beanManager.getBeans(
                   injectionPoint.getType(),
                   injectionPoint
                       .getQualifiers()
                       .toArray(new Annotation[injectionPoint.getQualifiers().size()])));
       if (isBuiltinBeanButNotExtension(dependency)) {
         dependency =
             probe.getBean(Components.getBuiltinBeanId((AbstractBuiltInBean<?>) dependency));
       }
       dependencies.add(new Dependency(dependency, injectionPoint));
     }
   }
   return dependencies;
 }
Example #22
0
  /**
   * Fill a GraphDef with values as defined by the graph desc
   *
   * @param graphDef the GraphDef to configure
   * @param defProbe The probe to get values from
   * @param customData some custom data, they override existing values in the associated probe
   */
  public void fillGraphDef(
      RrdGraphDef graphDef, Probe<?, ?> defProbe, Map<String, ? extends Plottable> customData) {
    HostsList hl = defProbe.getHostList();
    List<DsDesc> toDo = new ArrayList<DsDesc>();
    // The datasources already found
    Set<String> datasources = new HashSet<String>();

    for (DsDesc ds : allds) {
      boolean complete = false;
      // not a data source, don't try to add it in datasources
      if (!ds.graphType.datasource()) {
        complete = true;
      }
      // The graph is a percentile
      else if (ds.percentile != null) {
        complete = true;
        graphDef.percentile(ds.name, ds.dsName, ds.percentile);
        datasources.add(ds.name);
      }
      // A rpn datasource
      else if (ds.rpn != null) {
        complete = true;
        if (!datasources.contains(ds.name)) {
          graphDef.datasource(ds.name, ds.rpn);
          datasources.add(ds.name);
        }
      } else if (ds.graphType == GraphType.LEGEND) {
        complete = true;
      }
      // Does the datas existe in the provided values
      // It override existing values in the probe
      else if (customData != null && customData.containsKey(ds.dsName)) {
        complete = true;
        if (!datasources.contains(ds.name)) {
          graphDef.datasource(ds.name, customData.get(ds.dsName));
          datasources.add(ds.name);
          logger.trace(Util.delayedFormatString("custom data found for %s", ds.dsName));
        }
      }
      // Last but common case, datasource refers to a rrd
      // Or they might be on the associated rrd
      else {
        Probe<?, ?> probe = defProbe;
        if (ds.dspath != null) {
          if (logger.isTraceEnabled())
            logger.trace(
                "External probe path: " + ds.dspath.host + "/" + ds.dspath.probe + "/" + ds.dsName);
          probe = hl.getProbeByPath(ds.dspath.host, ds.dspath.probe);
          if (probe == null) {
            logger.error("Invalide probe: " + ds.dspath.host + "/" + ds.dspath.probe);
            continue;
          }
        }
        if (!probe.dsExist(ds.dsName)) {
          logger.error("Invalide datasource " + ds.dsName + ", not found in " + probe);
          continue;
        }

        complete = true;
        if (!datasources.contains(ds.name)) {
          String rrdName = probe.getRrdName();
          graphDef.datasource(ds.name, rrdName, ds.dsName, ds.cf);
          datasources.add(ds.name);
        } else {
          logger.error(
              "Datasource '" + ds.name + "' defined twice in " + name + ", for found: " + ds);
        }
      }
      if (complete) {
        toDo.add(ds);
      } else {
        logger.debug("Error for " + ds);
        logger.error("No way to plot " + ds.name + " in " + name + " found");
      }
    }
    // The title line, only if values block is required
    if (withSummary) {
      graphDef.comment(""); // We simulate the color box
      graphDef.comment(MANYSPACE.substring(0, Math.min(maxLengthLegend, MANYSPACE.length()) + 2));
      graphDef.comment("Current");
      graphDef.comment("  Average");
      graphDef.comment("  Minimum");
      graphDef.comment("  Maximum");
      graphDef.comment("\\l");
    }

    if (logger.isTraceEnabled()) {
      logger.trace("Datasource: " + datasources);
      logger.trace("Todo: " + toDo);
    }

    String shortLegend = withSummary ? " \\g" : null;
    for (DsDesc ds : toDo) {
      ds.graphType.draw(graphDef, ds.name, ds.color, shortLegend);
      if (withSummary && ds.graphType.legend())
        addLegend(graphDef, ds.name, ds.graphType, ds.legend);
    }
  }
Example #23
0
  private DatasourcesPopulator(
      T wrapped,
      Probe<?, ?> defProbe,
      ExtractInfo ei,
      Map<String, ? extends Plottable> customData,
      List<DsDesc> allds,
      String name) {
    HostsList hl = defProbe.getHostList();

    if (wrapped instanceof RrdGraphDef) {
      graphDef = (RrdGraphDef) wrapped;
      dp = null;
    } else if (wrapped instanceof DataProcessor) {
      dp = (DataProcessor) wrapped;
      graphDef = null;
    } else {
      throw new RuntimeException();
    }

    // The datasources already found
    Set<String> datasources = new HashSet<String>();

    // The needed extractors
    Map<Probe<?, ?>, Extractor> probeDS = new HashMap<Probe<?, ?>, Extractor>(1);
    probeDS.put(defProbe, defProbe.getMainStore().getExtractor());

    for (DsDesc ds : allds) {
      boolean complete;
      // Not a data source, don't try to add it in datasources
      if (!ds.graphType.datasource()) {
        complete = true;
      }
      // The graph is a percentile
      else if (ds.percentile != null) {
        complete = true;
        if (!datasources.contains(ds.name)) {
          percentile(ds.name, ds.dsName, ds.percentile);
          datasources.add(ds.name);
        }
      }
      // A rpn datasource
      else if (ds.rpn != null) {
        complete = true;
        if (!datasources.contains(ds.name)) {
          datasource(ds.name, ds.rpn);
          datasources.add(ds.name);
        }
      }
      // A legend
      else if (ds.graphType == GraphType.LEGEND) {
        complete = true;
      }
      // Does the datas existe in the provided values
      // It override existing values in the probe
      else if (customData != null && customData.containsKey(ds.dsName)) {
        complete = true;
        if (!datasources.contains(ds.name)) {
          datasource(ds.name, customData.get(ds.dsName));
          datasources.add(ds.name);
          logger.trace(delayedFormatString("custom data found for %s", ds.dsName));
        }
      }
      // Last but common case, datasource refers to a rrd
      // Or they might be on the associated rrd
      else {
        Probe<?, ?> probe = defProbe;
        if (ds.dspath != null) {
          // If the host is not defined, use the current host
          String pathHost = ds.dspath.host;
          if (pathHost == null) {
            pathHost = defProbe.getHost().getName();
          }
          logger.trace(
              delayedFormatString(
                  "External probe path: %s/%s/%s", pathHost, ds.dspath.probe, ds.dsName));
          probe = hl.getProbeByPath(pathHost, ds.dspath.probe);
          if (probe == null) {
            logger.error("Invalide probe: " + pathHost + "/" + ds.dspath.probe);
            continue;
          }
        }
        if (!probe.dsExist(ds.dsName)) {
          logger.error("Invalide datasource " + ds.dsName + ", not found in " + probe);
          continue;
        }
        complete = true;

        // Add the dsName for the probe found
        if (!probeDS.containsKey(probe)) {
          probeDS.put(probe, probe.getMainStore().getExtractor());
        }
        Extractor ex = probeDS.get(probe);
        if (!datasources.contains(ds.name)) {
          ex.addSource(ds.name, ds.dsName);
          datasources.add(ds.name);
        } else {
          logger.error(
              "Datasource '" + ds.dsName + "' defined twice in " + name + ", for found: " + ds);
        }
      }
      if (complete) {
        toDo.add(ds);
      } else {
        logger.debug("Error for " + ds);
        logger.error("No way to plot " + ds.name + " in " + name + " found");
      }
    }

    // Fill the graphdef with extracted data
    for (Extractor x : probeDS.values()) {
      if (graphDef != null) {
        x.fill(graphDef, ei);
      } else {
        x.fill(dp, ei);
      }
      x.release();
    }

    logger.trace(delayedFormatString("Datasource: %s", datasources));
    if (graphDef != null) {
      logger.trace(delayedFormatString("Todo: : %s", toDo));
    }
  }
Example #24
0
 @SlowPath
 public Iterable<SyntaxTag> getSyntaxTags() {
   return probe.getSyntaxTags();
 }
Example #25
0
 @SlowPath
 public boolean isTaggedAs(SyntaxTag tag) {
   return probe.isTaggedAs(tag);
 }
Example #26
0
 @Override
 public Node copy() {
   Node node = super.copy();
   probe.registerProbeNodeClone((ProbeNode) node);
   return node;
 }