@Override public void set(Object bean) { brewery.ingredient(bean); }
/** Retrieves a component by name and ensures the returned component is * initialized. * @return the initialized component, never returns null. * @param name is the name of the component. * @throws RuntimeException if the type parameter is null. * @throws RuntimeException if the component can not be found in the brewery */ public synchronized Object get(String name) { Object component = getOpt(name); if (component!=null) { return component; } throw new RuntimeException("Unknown component name: '"+name+"' \n"+toString()); }
@Test public void testLookupByClassname() { Brewery brewery = new Brewery(); Object h2o = "h2o"; brewery.ingredient(h2o); assertSame(h2o, brewery.get(String.class)); }
public DefaultConfiguration() { brewery = new Brewery(); brewery.ingredient(this); brewery.ingredient(new WorkflowEngineConfiguration()); brewery.ingredient(new WorkflowEngineImpl()); brewery.ingredient(new SimpleWorkflowCache()); brewery.ingredient(new AsynchronousExecutorService()); brewery.ingredient(new ConditionServiceImpl()); brewery.ingredient(new JobServiceImpl()); brewery.ingredient(new ActivityTypeService()); brewery.ingredient(new DataTypeService()); brewery.ingredient(new TimerTypeService()); brewery.ingredient(new JsonStreamMappingsBuilder()); brewery.ingredient(new JavaBeanValueMappingsBuilder()); brewery.supplier(new JsonStreamMapperSupplier(), JsonStreamMapper.class); brewery.supplier(new JavaBeanValueMapperSupplier(), JavaBeanValueMapper.class); brewery.supplier(new BpmnMapperSupplier(), BpmnMapper.class); }
public DefaultAdapterConfiguration() { brewery = new Brewery(); brewery.ingredient(this); brewery.ingredient(new JsonFactory()); brewery.ingredient(new DataTypeService()); brewery.ingredient(new DefaultJsonStreamMapper()); brewery.ingredient(new DefaultJavaBeanValueMapper()); }
public MongoConfiguration() { brewery.ingredient(this); brewery.supplier(new MongoClientSupplier(), MongoClient.class); brewery.supplier(new MongoDbSupplier(), DB.class); brewery.supplier(new MongoGridFSSupplier(), GridFS.class); brewery.supplier(new MongoObjectMapperSupplier(), MongoObjectMapper.class); brewery.ingredient(new MongoDb()); brewery.ingredient(new MongoWorkflowStore()); brewery.ingredient(new MongoWorkflowInstanceStore()); brewery.ingredient(new MongoJobStore()); brewery.ingredient(new MongoObjectMappingsBuilder()); }
/** Adds an uninitialized component to the brewery. * It will be possible to lookup this component by all it's * superclasses and interfaces it implements. * @throws RuntimeException if component is null */ public void ingredient(Object component) { Exceptions.checkNotNullParameter(component, "component"); String name = component.getClass().getName(); alias(name, component.getClass()); ingredient(component, name); if (component instanceof Stoppable) { addStoppable((Stoppable) component); } }
for (String name: ingredients.keySet()) { Object component = ingredients.get(name); addNameIfStartable(namesToStart, name, component.getClass()); addNameIfStartable(namesToStart, name, component.getClass()); startables.add((Startable) get(name));
/** Adds a factory to the brewery that will be able to * create components when it's requested by type. * @throws RuntimeException if supplier is null * @throws RuntimeException if type is null */ public void supplier(Supplier supplier, Class<?> type) { Exceptions.checkNotNullParameter(supplier, "supplier"); Exceptions.checkNotNullParameter(type, "type"); String name = type.getName(); alias(name, type); supplier(supplier, name); }
protected synchronized void ensureStarted() { if (!isStarted) { start(); } }
/** Retrieves an optional component based on the given class and if it's found, * the brewery ensures the returned component is initialized. * If the component is not found, null is returned. * Lookup by type should only be done for classes and interfaces * of which you know there will only be one in the whole brewery. * Use lookup by name otherwise. * @return the initialized component or null if it is not found. * @param type is the class or interface of the requested component. Subclasses * of the given class or implementations of the given class will * be found as well. * @throws RuntimeException if the type parameter is null. */ @SuppressWarnings("unchecked") public <T> T getOpt(Class<T> type) { Exceptions.checkNotNullParameter(type, "type"); return (T) getOpt(type.getName()); }
@Override public void stop() { brewery.stop(); } }
@Test public void testRetrieveAnIngredient() { Brewery brewery = new Brewery(); // Put h2o as an ingredient named water into the brewery Object h2o = "h2o"; brewery.ingredient(h2o, "water"); // Get water from the brewery // No initialization required assertSame(h2o, brewery.get("water")); // Getting the water again produces the exact same object assertSame(h2o, brewery.get("water")); }
public MongoConfiguration() { brewery.ingredient(this); brewery.supplier(new MongoClientSupplier(), MongoClient.class); brewery.supplier(new MongoDbSupplier(), DB.class); brewery.supplier(new MongoGridFSSupplier(), GridFS.class); brewery.supplier(new MongoObjectMapperSupplier(), MongoObjectMapper.class); brewery.ingredient(new MongoDb()); brewery.ingredient(new MongoWorkflowStore()); brewery.ingredient(new MongoWorkflowInstanceStore()); brewery.ingredient(new MongoJobStore()); brewery.ingredient(new MongoObjectMappingsBuilder()); }
@Override public void start() { brewery.start(); }
public WorkflowParser(Configuration configuration) { this.configuration = configuration; this.path = new LinkedList<>(); this.contextStack = new Stack<>(); this.issues = new ParseIssues(); // this cast is necessary to get the workflow parse listener optional // because the brewery.getOpt method is not available on the configuration itself if (configuration instanceof DefaultConfiguration) { DefaultConfiguration defaultConfiguration = (DefaultConfiguration)configuration; Brewery brewery = defaultConfiguration.getBrewery(); this.workflowParseListener = brewery.getOpt(WorkflowParseListener.class); } }
@Override public void stop() { brewery.stop(); } }