/** * Creates a PicContainer which extends the specified ComponentContainer <strong>but is not referenced in return</strong>. */ private static MutablePicoContainer createContainer(ComponentContainer parent) { ComponentMonitor componentMonitor = new NullComponentMonitor(); ReflectionLifecycleStrategy lifecycleStrategy = new StopSafeReflectionLifecycleStrategy(componentMonitor) { @Override public boolean isLazy(ComponentAdapter<?> adapter) { return true; } }; return new DefaultPicoContainer(new OptInCaching(), lifecycleStrategy, parent.getPicoContainer(), componentMonitor); }
/** * Constructor. * * @param resources message resource * @param logger logger * @param properties {@link ConsoleProperties} * @param eventSyncCondition event synchronized condition to synchronize server stop phase. */ public AgentControllerServer(Resources resources, Logger logger, ConsoleProperties properties, Condition eventSyncCondition, ConsoleCommunicationSetting consoleCommunicationSetting) { m_eventSyncCondition = eventSyncCondition; m_container = new DefaultPicoContainer(new Caching()); m_container.addComponent(logger); m_container.addComponent(resources); m_container.addComponent(properties); m_container.addComponent(new StandardTimeAuthority()); m_container.addComponent(consoleCommunicationSetting); m_container.addComponent(ConsoleCommunicationImplementationEx.class); m_container.addComponent(AgentProcessControlImplementation.class); m_timer = new Timer(true); m_container.addComponent(m_timer); // m_container.addComponent(WireEnhancedProcessReportMessage.class); m_container.addComponent(ErrorQueue.class); ErrorQueue errorQueue = m_container.getComponent(ErrorQueue.class); errorQueue.setErrorHandler(new ErrorHandlerImplementation(logger)); }
protected ScopedContainers makeScopedContainers(boolean stateless) { //NullLifecycleStrategy ls = new NullLifecycleStrategy(); DefaultPicoContainer appCtnr = new DefaultPicoContainer(new Guarding().wrap(new Caching()), makeLifecycleStrategy(), makeParentContainer(), makeAppComponentMonitor()); Storing sessStoring = new Storing(); DefaultPicoContainer sessCtnr = new DefaultPicoContainer(new Guarding().wrap(sessStoring), makeLifecycleStrategy(), appCtnr, makeSessionComponentMonitor()); Storing reqStoring = new Storing(); DefaultPicoContainer reqCtnr = new DefaultPicoContainer(new Guarding().wrap(addRequestBehaviors(reqStoring)), makeLifecycleStrategy(), sessCtnr, makeRequestComponentMonitor()); ThreadLocalLifecycleState sessionState = new ThreadLocalLifecycleState(); ThreadLocalLifecycleState requestState = new ThreadLocalLifecycleState(); sessCtnr.setLifecycleState(sessionState); reqCtnr.setLifecycleState(requestState); return new ScopedContainers(appCtnr, sessCtnr, reqCtnr, sessStoring, reqStoring, sessionState, requestState); }
/** * process adapter node * * @param container * @param rootElement */ @SuppressWarnings("unchecked") protected void insertAdapter(MutablePicoContainer container, Element rootElement) { String key = rootElement.getAttribute(KEY); String klass = rootElement.getAttribute(CLASS); try { DefaultPicoContainer nested = new DefaultPicoContainer(); populateContainer(nested, rootElement); if (key != null) { container.addAdapter((ComponentAdapter) nested.getComponent(key)); } else if (klass != null) { Class clazz = getClassLoader().loadClass(klass); container.addAdapter((ComponentAdapter) nested.getComponent(clazz)); } else { container.addAdapter(nested.getComponent(ComponentAdapter.class)); } } catch (ClassNotFoundException ex) { throw new ScriptedPicoContainerMarkupException(ex); } }
DefaultPicoContainer factory = new DefaultPicoContainer(); if (composition == null) { throw new NullPointerException("composition can't be null"); factory.addComponent(composition); factory.addComponent(classLoader);
@Override protected PicoContainer createContainer(PicoContainer parentContainer, Object assemblyScope) { return (new DefaultPicoContainer(parentContainer)).change(Characteristics.CACHE); } }
public static MutablePicoContainer buildPicoContainer() { ReflectionLifecycleStrategy lifecycleStrategy = new ReflectionLifecycleStrategy(new NullComponentMonitor(), "start", "stop", "dispose"); DefaultPicoContainer result = new DefaultPicoContainer(new OptInCaching(), lifecycleStrategy, null); result.as(Characteristics.CACHE).addComponent(new IocContainer(result)); // for components that directly inject other components (eg Plugins) return result; } }
/** * Shut down the console. * */ public void shutdown() { m_shutdown = true; m_container.getComponent(ConsoleCommunication.class).shutdown(); try { m_timer.cancel(); } catch (Exception e) { // Fall through noOp(); } if (m_container.getLifecycleState().isStarted()) { m_container.stop(); } }
@Override public Object getComponent(final Object componentKeyOrType, final Class<? extends Annotation> annotation) { try { return super.getComponent(componentKeyOrType, annotation); } catch (Throwable t) { throw new IllegalStateException("Unable to load component " + componentKeyOrType, t); } }
public ClassLoadingPicoContainer build() { DefaultPicoContainer tpc = new TransientPicoContainer(); tpc.addComponent(ClassLoader.class, classLoader); tpc.addComponent("sc", scriptClass); tpc.addComponent(MutablePicoContainer.class, picoBuilder.build()); ClassLoadingPicoContainer pico = (ClassLoadingPicoContainer) tpc.getComponent("sc"); for (URL url : urls) { pico.addClassLoaderURL(url); } return pico; }
/** * Run agent controller in synchronized way. */ public void run() { if (m_shutdown) { throw processException("The console can not be run because it's already shutdown"); } m_container.start(); m_container.getComponent(AgentProcessControlImplementation.class); ConsoleCommunication communication = m_container.getComponent(ConsoleCommunication.class); synchronized (m_eventSyncCondition) { // Now ready to work m_eventSyncCondition.notifyAll(); } // CHECKSTYLE:OFF while (communication.processOneMessage()) { noOp(); // Fall through // Process until communication is shut down. } }
m_filterContainer.addComponent(output); m_filterContainer.addComponent(logger); m_filterContainer.addComponent(commentSource); m_filterContainer.addComponent(componentClass); m_filterContainer.addComponent( AttributeStringParserImplementation.class); m_filterContainer.addComponent(ConnectionCache.class); m_filterContainer.addComponent( ConnectionHandlerFactoryImplementation.class); m_filterContainer.addComponent(ParametersFromProperties.class); m_filterContainer.addComponent(HTTPRecordingImplementation.class); m_filterContainer.addComponent(ProcessHTTPRecordingWithXSLT.class); m_filterContainer.addComponent( RegularExpressionsImplementation.class); m_filterContainer.addComponent(URIParserImplementation.class); m_filterContainer.addComponent(SimpleStringEscaper.class); m_filterContainer.addComponent( BuiltInStyleSheet.TraditionalJython); m_filterContainer.addComponent(BuiltInStyleSheet.Clojure); m_filterContainer.addComponent(new StyleSheetFile(new File(s))); m_filterContainer.changeMonitor(
public void add(Class<? extends TCPProxyFilter> theClass) { final String key = m_type + ++m_value; m_filterContainer.addComponent(key, theClass); m_filterKeys.add(key); }
@Override public MutablePicoContainer addComponent(final Object componentKey, final Object componentImplementationOrInstance, final Parameter... parameters) throws PicoCompositionException { if (componentKey == null) { throw new NullPointerException("componentKey"); } if (componentImplementationOrInstance == null) { throw new NullPointerException("componentImplementationOrInstance"); } super.addComponent(componentKey, componentImplementationOrInstance, parameters); if (! (componentImplementationOrInstance instanceof Class)) { instanceRegistrations.add(super.getComponentAdapter(componentKey)); } else { addStoredReference(componentKey); } return this; }
@Override public synchronized void stop() { super.stop(); flushInstances(); }
DefaultPicoContainer appCtnr = new DefaultPicoContainer(new Guarding().wrap(new Caching()), makeLifecycleStrategy(), makeParentContainer(), makeAppComponentMonitor()); DefaultPicoContainer sessCtnr; PicoContainer parentOfRequestContainer; sessionState = new ThreadLocalLifecycleState(); sessStoring = new Storing(); sessCtnr = new DefaultPicoContainer(new Guarding().wrap(sessStoring), makeLifecycleStrategy(), appCtnr, makeSessionComponentMonitor()); sessCtnr.setLifecycleState(sessionState); parentOfRequestContainer = sessCtnr; DefaultPicoContainer reqCtnr = new DefaultPicoContainer(new Guarding().wrap(addRequestBehaviors(reqStoring)), makeLifecycleStrategy(), parentOfRequestContainer, makeRequestComponentMonitor()); ThreadLocalLifecycleState requestState = new ThreadLocalLifecycleState(); reqCtnr.setLifecycleState(requestState); return new ScopedContainers(appCtnr, sessCtnr, reqCtnr, sessStoring, reqStoring, sessionState, requestState);
/** * Get internal component. * * @param componentType component type class * @param <T> component type * @return component */ public <T> T getComponent(Class<T> componentType) { return m_container.getComponent(componentType); } }
@Override public MutablePicoContainer addComponent(final Object implOrInstance) throws PicoCompositionException { if ((implOrInstance instanceof Class)) { super.addComponent(implOrInstance); addStoredReference(implOrInstance); return this; } else { return this.addComponent(implOrInstance.getClass(), implOrInstance); } }
/** * Creates a PicContainer which extends the specified ComponentContainer <strong>but is not referenced in return</strong> * and lazily starts its components. */ private static MutablePicoContainer createContainer(ComponentContainer parent) { ComponentMonitor componentMonitor = new NullComponentMonitor(); ReflectionLifecycleStrategy lifecycleStrategy = new StopSafeReflectionLifecycleStrategy(componentMonitor) { @Override public boolean isLazy(ComponentAdapter<?> adapter) { return adapter.getComponentImplementation().getAnnotation(EagerStart.class) == null; } }; return new DefaultPicoContainer(new OptInCaching(), lifecycleStrategy, parent.getPicoContainer(), componentMonitor); }