Exemplo n.º 1
0
  public <T1, T2> TypePairComparatorFactory<T1, T2> getPairComparatorFactory(ClassLoader cl) {
    final String className = this.config.getString(DRIVER_PAIR_COMPARATOR_FACTORY, null);
    if (className == null) {
      return null;
    }

    @SuppressWarnings("unchecked")
    final Class<TypePairComparatorFactory<T1, T2>> superClass =
        (Class<TypePairComparatorFactory<T1, T2>>) (Class<?>) TypePairComparatorFactory.class;
    try {
      final Class<? extends TypePairComparatorFactory<T1, T2>> clazz =
          Class.forName(className, true, cl).asSubclass(superClass);
      return InstantiationUtil.instantiate(clazz, superClass);
    } catch (ClassNotFoundException cnfex) {
      throw new RuntimeException(
          "The class '"
              + className
              + "', noted in the configuration as "
              + "pair comparator factory, could not be found. It is not part of the user code's class loader resources.");
    } catch (ClassCastException ccex) {
      throw new CorruptConfigurationException(
          "The class noted in the configuration as the pair comparator factory "
              + "is no subclass of TypePairComparatorFactory.");
    }
  }
Exemplo n.º 2
0
 public void setStubWrapper(UserCodeWrapper<?> wrapper) {
   try {
     InstantiationUtil.writeObjectToConfig(wrapper, this.config, STUB_OBJECT);
   } catch (IOException e) {
     throw new CorruptConfigurationException(
         "Could not write the user code wrapper " + wrapper.getClass() + " : " + e.toString(), e);
   }
 }
Exemplo n.º 3
0
  private final void setTypeComparatorFactory(
      TypeComparatorFactory<?> factory, String classNameKey, String parametersPrefix) {
    // sanity check the factory type
    InstantiationUtil.checkForInstantiation(factory.getClass());

    // store the type
    this.config.setString(classNameKey, factory.getClass().getName());
    // store the parameters
    final DelegatingConfiguration parameters =
        new DelegatingConfiguration(this.config, parametersPrefix);
    factory.writeParametersToConfig(parameters);
  }
Exemplo n.º 4
0
 @SuppressWarnings("unchecked")
 public <T> UserCodeWrapper<T> getStubWrapper(ClassLoader cl) {
   try {
     return (UserCodeWrapper<T>)
         InstantiationUtil.readObjectFromConfig(this.config, STUB_OBJECT, cl);
   } catch (ClassNotFoundException e) {
     throw new CorruptConfigurationException(
         "Could not read the user code wrapper: " + e.getMessage(), e);
   } catch (IOException e) {
     throw new CorruptConfigurationException(
         "Could not read the user code wrapper: " + e.getMessage(), e);
   }
 }
Exemplo n.º 5
0
  public DataDistribution getOutputDataDistribution(int outputNum, final ClassLoader cl)
      throws ClassNotFoundException {
    final String className = this.config.getString(OUTPUT_DATA_DISTRIBUTION_CLASS, null);
    if (className == null) {
      return null;
    }

    final Class<? extends DataDistribution> clazz;
    try {
      clazz =
          (Class<? extends DataDistribution>)
              Class.forName(className, true, cl).asSubclass(DataDistribution.class);
    } catch (ClassCastException ccex) {
      throw new CorruptConfigurationException(
          "The class noted in the configuration as the data distribution "
              + "is no subclass of DataDistribution.");
    }

    final DataDistribution distribution =
        InstantiationUtil.instantiate(clazz, DataDistribution.class);

    final byte[] stateEncoded =
        this.config.getBytes(OUTPUT_DATA_DISTRIBUTION_PREFIX + outputNum, null);
    if (stateEncoded == null) {
      throw new CorruptConfigurationException(
          "The configuration contained the data distribution type, but no serialized state.");
    }

    final ByteArrayInputStream bais = new ByteArrayInputStream(stateEncoded);
    final DataInputStream in = new DataInputStream(bais);

    try {
      distribution.read(in);
      return distribution;
    } catch (Exception ex) {
      throw new RuntimeException(
          "The deserialization of the encoded data distribution state caused an error"
                      + ex.getMessage()
                  == null
              ? "."
              : ": " + ex.getMessage(),
          ex);
    }
  }
Exemplo n.º 6
0
  private final <T> TypeComparatorFactory<T> getTypeComparatorFactory(
      String classNameKey, String parametersPrefix, ClassLoader cl) {
    // check the class name
    final String className = this.config.getString(classNameKey, null);
    if (className == null) {
      return null;
    }

    // instantiate the class
    @SuppressWarnings("unchecked")
    final Class<TypeComparatorFactory<T>> superClass =
        (Class<TypeComparatorFactory<T>>) (Class<?>) TypeComparatorFactory.class;
    final TypeComparatorFactory<T> factory;
    try {
      Class<? extends TypeComparatorFactory<T>> clazz =
          Class.forName(className, true, cl).asSubclass(superClass);
      factory = InstantiationUtil.instantiate(clazz, superClass);
    } catch (ClassNotFoundException cnfex) {
      throw new RuntimeException(
          "The class '"
              + className
              + "', noted in the configuration as "
              + "comparator factory, could not be found. It is not part of the user code's class loader resources.");
    } catch (ClassCastException ccex) {
      throw new CorruptConfigurationException(
          "The class noted in the configuration as the comparator factory "
              + "is no subclass of TypeComparatorFactory.");
    }

    // parameterize the comparator factory
    final Configuration parameters = new DelegatingConfiguration(this.config, parametersPrefix);
    try {
      factory.readParametersFromConfig(parameters, cl);
    } catch (ClassNotFoundException cnfex) {
      throw new RuntimeException(
          "The type serializer factory could not load its parameters from the "
              + "configuration due to missing classes.",
          cnfex);
    }

    return factory;
  }
Exemplo n.º 7
0
 public void setDriverPairComparator(TypePairComparatorFactory<?, ?> factory) {
   final Class<?> clazz = factory.getClass();
   InstantiationUtil.checkForInstantiation(clazz);
   this.config.setString(DRIVER_PAIR_COMPARATOR_FACTORY, clazz.getName());
 }