@Test public void testDuplicateCreate() { Source avroSource1 = sourceFactory.create("avroSource1", "avro"); Source avroSource2 = sourceFactory.create("avroSource2", "avro"); Assert.assertNotNull(avroSource1); Assert.assertNotNull(avroSource2); Assert.assertNotSame(avroSource1, avroSource2); Assert.assertTrue(avroSource1 instanceof AvroSource); Assert.assertTrue(avroSource2 instanceof AvroSource); Source s1 = sourceFactory.create("avroSource1", "avro"); Source s2 = sourceFactory.create("avroSource2", "avro"); Assert.assertNotSame(avroSource1, s1); Assert.assertNotSame(avroSource2, s2); }
@Override public Source create(String name, String type) throws FlumeException { Preconditions.checkNotNull(name, "name"); Preconditions.checkNotNull(type, "type"); logger.info("Creating instance of source {}, type {}", name, type); Class<? extends Source> sourceClass = getClass(type); try { Source source = sourceClass.newInstance(); source.setName(name); return source; } catch (Exception ex) { throw new FlumeException("Unable to create source: " + name +", type: " + type + ", class: " + sourceClass.getName(), ex); } }
DefaultSourceFactory implements SourceFactory { @Override public Source create(String name, String type) throws FlumeException { Preconditions.checkNotNull(name, "name"); Preconditions.checkNotNull(type, "type"); logger.info("Creating instance of source {}, type {}", name, type); Class<? extends Source> sourceClass = getClass(type); try { Source source = sourceClass.newInstance(); source.setName(name); return source; } catch (Exception ex) { throw new FlumeException("Unable to create source: " + name +", type: " + type + ", class: " + sourceClass.getName(), ex); } } }
DefaultSourceFactory implements SourceFactory { @Override public Source create(String name, String type) throws FlumeException { Preconditions.checkNotNull(name, "name"); Preconditions.checkNotNull(type, "type"); logger.info("Creating instance of source {}, type {}", name, type); Class<? extends Source> sourceClass = getClass(type); try { Source source = sourceClass.newInstance(); source.setName(name); return source; } catch (Exception ex) { throw new FlumeException("Unable to create source: " + name +", type: " + type + ", class: " + sourceClass.getName(), ex); } }  }
DefaultSourceFactory implements SourceFactory { @Override public Source create(String name, String type) throws FlumeException { Preconditions.checkNotNull(name, "name"); Preconditions.checkNotNull(type, "type"); logger.info("Creating instance of source {}, type {}", name, type); Class<? extends Source> sourceClass = getClass(type); try { Source source = sourceClass.newInstance(); source.setName(name); return source; } catch (Exception ex) { throw new FlumeException("Unable to create source: " + name +", type: " + type + ", class: " + sourceClass.getName(), ex); } }  @Override Source create(String name, String type); @SuppressWarnings("unchecked") @Override Class<? extends Source> getClass(String type); }
DefaultSourceFactory implements SourceFactory { @Override public Source create(String name, String type) throws FlumeException { Preconditions.checkNotNull(name, "name"); Preconditions.checkNotNull(type, "type"); logger.info("Creating instance of source {}, type {}", name, type); Class<? extends Source> sourceClass = getClass(type); try { Source source = sourceClass.newInstance(); source.setName(name); return source; } catch (Exception ex) { throw new FlumeException("Unable to create source: " + name +", type: " + type + ", class: " + sourceClass.getName(), ex); } }  @Override Source create(String name, String type); @SuppressWarnings("unchecked") @Override Class<? extends Source> getClass(String type);  }