Java Code Examples for org.apache.commons.beanutils.BeanMap#entryIterator()

The following examples show how to use org.apache.commons.beanutils.BeanMap#entryIterator() . 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: StramWebServices.java    From Bats with Apache License 2.0 6 votes vote down vote up
private Map<String, Object> getPropertiesAsMap(@QueryParam("propertyName") String propertyName, BeanMap operatorProperties)
{
  Map<String, Object> m = new HashMap<>();
  @SuppressWarnings("rawtypes")
  Iterator entryIterator = operatorProperties.entryIterator();
  while (entryIterator.hasNext()) {
    try {
      @SuppressWarnings("unchecked")
      Map.Entry<String, Object> entry = (Map.Entry<String, Object>)entryIterator.next();
      if (propertyName == null) {
        m.put(entry.getKey(), entry.getValue());
      } else if (propertyName.equals(entry.getKey())) {
        m.put(entry.getKey(), entry.getValue());
        break;
      }
    } catch (Exception ex) {
      LOG.warn("Caught exception", ex);
    }
  }
  return m;
}
 
Example 2
Source File: StramToNodeGetPropertyRequest.java    From Bats with Apache License 2.0 6 votes vote down vote up
@Override
public StatsListener.OperatorResponse execute(Operator operator, int operatorId, long windowId) throws IOException
{
  BeanMap beanMap = new BeanMap(operator);
  Map<String, Object> propertyValue = new HashMap<>();
  if (propertyName != null) {
    if (beanMap.containsKey(propertyName)) {
      propertyValue.put(propertyName, beanMap.get(propertyName));
    }
  } else {
    Iterator entryIterator = beanMap.entryIterator();
    while (entryIterator.hasNext()) {
      Map.Entry<String, Object> entry = (Map.Entry<String, Object>)entryIterator.next();
      propertyValue.put(entry.getKey(), entry.getValue());
    }
  }
  logger.debug("Getting property {} on operator {}", propertyValue, operator);
  OperatorResponse response = new OperatorResponse(requestId, propertyValue);
  return response;
}
 
Example 3
Source File: StramWebServices.java    From attic-apex-core with Apache License 2.0 6 votes vote down vote up
private Map<String, Object> getPropertiesAsMap(@QueryParam("propertyName") String propertyName, BeanMap operatorProperties)
{
  Map<String, Object> m = new HashMap<>();
  @SuppressWarnings("rawtypes")
  Iterator entryIterator = operatorProperties.entryIterator();
  while (entryIterator.hasNext()) {
    try {
      @SuppressWarnings("unchecked")
      Map.Entry<String, Object> entry = (Map.Entry<String, Object>)entryIterator.next();
      if (propertyName == null) {
        m.put(entry.getKey(), entry.getValue());
      } else if (propertyName.equals(entry.getKey())) {
        m.put(entry.getKey(), entry.getValue());
        break;
      }
    } catch (Exception ex) {
      LOG.warn("Caught exception", ex);
    }
  }
  return m;
}
 
Example 4
Source File: StramToNodeGetPropertyRequest.java    From attic-apex-core with Apache License 2.0 6 votes vote down vote up
@Override
public StatsListener.OperatorResponse execute(Operator operator, int operatorId, long windowId) throws IOException
{
  BeanMap beanMap = new BeanMap(operator);
  Map<String, Object> propertyValue = new HashMap<>();
  if (propertyName != null) {
    if (beanMap.containsKey(propertyName)) {
      propertyValue.put(propertyName, beanMap.get(propertyName));
    }
  } else {
    Iterator entryIterator = beanMap.entryIterator();
    while (entryIterator.hasNext()) {
      Map.Entry<String, Object> entry = (Map.Entry<String, Object>)entryIterator.next();
      propertyValue.put(entry.getKey(), entry.getValue());
    }
  }
  logger.debug("Getting property {} on operator {}", propertyValue, operator);
  OperatorResponse response = new OperatorResponse(requestId, propertyValue);
  return response;
}
 
Example 5
Source File: LogicalPlanSerializer.java    From Bats with Apache License 2.0 4 votes vote down vote up
public static PropertiesConfiguration convertToProperties(LogicalPlan dag)
{
  PropertiesConfiguration props = new PropertiesConfiguration();
  Collection<OperatorMeta> allOperators = dag.getAllOperators();

  for (OperatorMeta operatorMeta : allOperators) {
    String operatorKey = LogicalPlanConfiguration.OPERATOR_PREFIX + operatorMeta.getName();
    Operator operator = operatorMeta.getOperator();
    props.setProperty(operatorKey + "." + LogicalPlanConfiguration.OPERATOR_CLASSNAME, operator.getClass().getName());
    BeanMap operatorProperties = LogicalPlanConfiguration.getObjectProperties(operator);
    @SuppressWarnings("rawtypes")
    Iterator entryIterator = operatorProperties.entryIterator();
    while (entryIterator.hasNext()) {
      try {
        @SuppressWarnings("unchecked")
        Map.Entry<String, Object> entry = (Map.Entry<String, Object>)entryIterator.next();
        if (!entry.getKey().equals("class") && !entry.getKey().equals("name") && entry.getValue() != null) {
          props.setProperty(operatorKey + "." + entry.getKey(), entry.getValue());
        }
      } catch (Exception ex) {
        LOG.warn("Error trying to get a property of operator {}", operatorMeta.getName(), ex);
      }
    }
  }
  Collection<StreamMeta> allStreams = dag.getAllStreams();

  for (StreamMeta streamMeta : allStreams) {
    String streamKey = LogicalPlanConfiguration.STREAM_PREFIX + streamMeta.getName();
    OutputPortMeta source = streamMeta.getSource();
    Collection<InputPortMeta> sinks = streamMeta.getSinks();
    props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_SOURCE, source.getOperatorMeta().getName() + "." + source.getPortName());
    String sinksValue = "";
    for (InputPortMeta sink : sinks) {
      if (!sinksValue.isEmpty()) {
        sinksValue += ",";
      }
      sinksValue += sink.getOperatorMeta().getName() + "." + sink.getPortName();
    }
    props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_SINKS, sinksValue);
    if (streamMeta.getLocality() != null) {
      props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_LOCALITY, streamMeta.getLocality().name());
    }
  }

  // TBD: Attributes

  return props;
}
 
Example 6
Source File: LogicalPlanSerializer.java    From attic-apex-core with Apache License 2.0 4 votes vote down vote up
public static PropertiesConfiguration convertToProperties(LogicalPlan dag)
{
  PropertiesConfiguration props = new PropertiesConfiguration();
  Collection<OperatorMeta> allOperators = dag.getAllOperators();

  for (OperatorMeta operatorMeta : allOperators) {
    String operatorKey = LogicalPlanConfiguration.OPERATOR_PREFIX + operatorMeta.getName();
    Operator operator = operatorMeta.getOperator();
    props.setProperty(operatorKey + "." + LogicalPlanConfiguration.OPERATOR_CLASSNAME, operator.getClass().getName());
    BeanMap operatorProperties = LogicalPlanConfiguration.getObjectProperties(operator);
    @SuppressWarnings("rawtypes")
    Iterator entryIterator = operatorProperties.entryIterator();
    while (entryIterator.hasNext()) {
      try {
        @SuppressWarnings("unchecked")
        Map.Entry<String, Object> entry = (Map.Entry<String, Object>)entryIterator.next();
        if (!entry.getKey().equals("class") && !entry.getKey().equals("name") && entry.getValue() != null) {
          props.setProperty(operatorKey + "." + entry.getKey(), entry.getValue());
        }
      } catch (Exception ex) {
        LOG.warn("Error trying to get a property of operator {}", operatorMeta.getName(), ex);
      }
    }
  }
  Collection<StreamMeta> allStreams = dag.getAllStreams();

  for (StreamMeta streamMeta : allStreams) {
    String streamKey = LogicalPlanConfiguration.STREAM_PREFIX + streamMeta.getName();
    OutputPortMeta source = streamMeta.getSource();
    Collection<InputPortMeta> sinks = streamMeta.getSinks();
    props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_SOURCE, source.getOperatorMeta().getName() + "." + source.getPortName());
    String sinksValue = "";
    for (InputPortMeta sink : sinks) {
      if (!sinksValue.isEmpty()) {
        sinksValue += ",";
      }
      sinksValue += sink.getOperatorMeta().getName() + "." + sink.getPortName();
    }
    props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_SINKS, sinksValue);
    if (streamMeta.getLocality() != null) {
      props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_LOCALITY, streamMeta.getLocality().name());
    }
  }

  // TBD: Attributes

  return props;
}