/** Adds an uninitialized component to the brewery * under the given name. * @throws RuntimeException if component is null * @throws RuntimeException if name is null */ public void ingredient(Object component, String name) { Exceptions.checkNotNullParameter(component, "component"); Exceptions.checkNotNullParameter(name, "name"); // log.debug("ingredient("+ingredient+")-->"+name); ingredients.put(name, component); }
public static void checkNotNullParameter(Object object, String argumentName) { checkNotNull(object, argumentName+" is null"); }
public static void checkNotNull(Object object, String description) { checkTrue(object!=null, description); }
/** Adds an alias so that a component with the * given name is also available as the given alias. * @throws RuntimeException if alias is null * @throws RuntimeException if name is null */ public void alias(String alias, String name) { Exceptions.checkNotNullParameter(alias, "alias"); Exceptions.checkNotNullParameter(name, "name"); if (!alias.equals(name)) { aliases.put(alias, name); } }
public static void checkNotNull(Object object) { checkNotNull(object, "expected a non-null value"); }
public TimerType instantiateTimerType(Timer timer) { Exceptions.checkNotNullParameter(timer, "timer"); Class<? extends TimerType> timerTypeClass = timerTypeClasses.get(timer.getClass()); if (timerTypeClass==null) { throw new RuntimeException("No TimerType defined for "+timer.getClass().getName()); } try { return timerTypeClass.newInstance(); } catch (Exception e) { throw new RuntimeException("Couldn't instantiate "+timerTypeClass+": "+e.getMessage(), e); } }
protected ScopeInstanceImpl getScopeInstance(WorkflowInstanceImpl workflowInstance, String activityInstanceId) { ScopeInstanceImpl scopeInstance = workflowInstance; if (activityInstanceId!=null) { scopeInstance = workflowInstance.findActivityInstance(activityInstanceId); Exceptions.checkNotNull(scopeInstance); } return scopeInstance; }
public ActivityType instantiateActivityType(Activity activityApi) { Exceptions.checkNotNullParameter(activityApi, "activityApi"); Class<? extends ActivityType> activityTypeClass = activityTypeClasses.get(activityApi.getClass()); if (activityTypeClass==null) { throw new RuntimeException("No ActivityType defined for "+activityApi.getClass().getName()); } try { return activityTypeClass.newInstance(); } catch (Exception e) { throw new RuntimeException("Couldn't instantiate "+activityTypeClass+": "+e.getMessage(), e); } }
/** Adds a factory to the brewery that will be able to * create components when it's requested by name. * The supplier will be {@link Supplier#supply(Brewery) asked} * to instantiate a component when it's being retrieved from * the brewery, aka lazy initialization. * @throws RuntimeException if supplier is null * @throws RuntimeException if name is null */ public void supplier(Supplier supplier, String name) { Exceptions.checkNotNullParameter(supplier, "supplier"); Exceptions.checkNotNullParameter(name, "name"); suppliers.put(name, supplier); if (supplier instanceof Stoppable) { addStoppable((Stoppable) supplier); } }
public AbstractTriggerImpl instantiateTriggerType(Trigger trigger) { Exceptions.checkNotNullParameter(trigger, "trigger"); Class<? extends AbstractTriggerImpl> triggerImplClass = triggerClasses.get(trigger.getClass()); if (triggerImplClass==null) { throw new RuntimeException("No trigger type defined for "+trigger.getClass().getName()); } try { return triggerImplClass.newInstance(); } catch (Exception e) { throw new RuntimeException("Couldn't instantiate "+triggerImplClass+": "+e.getMessage(), e); } }
/** 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); }
/** Removes a component from the brewery by type. */ public void remove(Class<?> type) { Exceptions.checkNotNullParameter(type, "type"); remove(type.getName()); }
/** Removes a component from the brewery by name. */ public void remove(String name) { Exceptions.checkNotNullParameter(name, "name"); String realName = name; if (aliases.containsKey(name)) { realName = aliases.get(name); } if (realName!=null) { ingredients.remove(realName); beers.remove(realName); ArrayList<String> keys = new ArrayList<>(aliases.keySet()); for (String key: keys) { String value = aliases.get(key); if (realName.equals(value)) { aliases.remove(key); } } } }
/** Adds an initialized component to the brewery * under the given name. * @throws RuntimeException if component is null * @throws RuntimeException if name is null */ public void beer(Object component, String name) { Exceptions.checkNotNullParameter(component, "component"); Exceptions.checkNotNullParameter(name, "name"); beers.put(name, component); if (component instanceof Brewable) { ((Brewable)component).brew(this); } if (component instanceof Stoppable) { addStoppable((Stoppable) component); } }
/** Retrieves an initialized component based on the given class and * ensures the returned component is initialized. * 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, never returns null. * @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. A RuntimeException is thrown if type is null. * @throws RuntimeException if the component can not be found in the brewery * @throws RuntimeException if the type parameter is null. */ @SuppressWarnings("unchecked") public <T> T get(Class<T> type) { Exceptions.checkNotNullParameter(type, "type"); return (T) get(type.getName()); }
/** Puts an initialized component into 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 beer(Object component) { Exceptions.checkNotNullParameter(component, "component"); String name = component.getClass().getName(); alias(name, component.getClass()); beer(component, name); }
/** 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()); }
/** 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); } }
Exceptions.checkNotNullParameter(name, "name"); ensureStarted(); if (aliases.containsKey(name)) {
@Override public WorkflowId findLatestWorkflowIdBySource(String sourceWorkflowId) { Exceptions.checkNotNullParameter(sourceWorkflowId, "sourceWorkflowId"); Query query = new Query() .equal(SOURCE_WORKFLOW_ID, sourceWorkflowId) .orderDesc(CREATE_TIME) .page(0, 1); Fields fields = new Fields() .include(_ID); BasicDBObject dbWorkflow = workflowsCollection.findOne("find-latest-workflow", query.get(), fields.get(), query.orderBy); return dbWorkflow!=null ? new WorkflowId(dbWorkflow.get(_ID).toString()) : null; }