Package org.apache.tuscany.core.context

Examples of org.apache.tuscany.core.context.Context


            destroyComponentContext(key);
        } else if (event instanceof InstanceCreated) {
            checkInit();
            Object sessionKey = getEventContext().getIdentifier(HttpSessionEvent.HTTP_IDENTIFIER);
            List<Context> shutdownQueue = destroyQueues.get(sessionKey);
            Context context = (Context) event.getSource();
            assert(shutdownQueue != null): "Shutdown queue not found for key";
            shutdownQueue.add(context);
        }
    }
View Full Code Here


    public Context getContext(String ctxName) {
        assert(ctxName != null): "No context name specified";
        checkInit();
        Map<String, Context> ctxs = getSessionContexts();
        Context context = ctxs.get(ctxName);
        if (context == null) {
            // the configuration was added after the session had started, so create a context now and start it
            ContextFactory<Context> configuration = contextFactories.get(ctxName);
            if (configuration != null) {
                context = configuration.createContext();
                context.start();
                if (context instanceof AtomicContext) {
                    ((AtomicContext) context).init();
                }

                ctxs.put(context.getName(), context);
                List<Context> shutdownQueue = destroyQueues.get(getEventContext().getIdentifier(HttpSessionEvent.HTTP_IDENTIFIER));
                synchronized (shutdownQueue) {
                    shutdownQueue.add(context);
                }
                context.addListener(this);
            }
        }
        return context;
    }
View Full Code Here

        if (components == null) {
            return;
        }
        components.remove(ctxName);
        Map<String, Context> definitions = contexts.get(key);
        Context ctx = definitions.get(ctxName);
        if (ctx != null) {
            destroyQueues.get(key).remove(ctx);
        }
        definitions.remove(ctxName);
    }
View Full Code Here

        if (m != null) {
            return m; // already created, return
        }
        Map<String, Context> sessionContext = new ConcurrentHashMap<String, Context>(contextFactories.size());
        for (ContextFactory<Context> config : contextFactories.values()) {
            Context context = config.createContext();
            context.start();
            sessionContext.put(context.getName(), context);
        }

        List<Context> shutdownQueue = new ArrayList<Context>();
        contexts.put(key, sessionContext);
        destroyQueues.put(key, shutdownQueue);
        // initialize eager components. Note this cannot be done when we initially create each context since a component may
        // contain a forward reference to a component which has not been instantiated
        for (Context context : sessionContext.values()) {
            if (context instanceof AtomicContext) {
                AtomicContext atomic = (AtomicContext) context;
                if (atomic.isEagerInit()) {
                    atomic.init()// Notify the instance
                    synchronized (shutdownQueue) {
                        shutdownQueue.add(context);
                    }
                }
            }
            context.addListener(this);
        }
        return sessionContext;
    }
View Full Code Here

        setName("Composite Scope");
    }

    public void start() throws ScopeInitializationException {
        for (ContextFactory<Context> configuration : configs) {
            Context context = configuration.createContext();
            if (!(context instanceof CompositeContext)) {
                ScopeInitializationException e = new ScopeInitializationException("Context not an composite type");
                e.addContextName(context.getName());
                throw e;
            }
            CompositeContext compositeCtx = (CompositeContext) context;
            compositeCtx.start();
            contexts.put(compositeCtx.getName(), compositeCtx);
View Full Code Here

    public void registerFactory(ContextFactory<Context> configuration) {
        assert (configuration != null) : "Configuration was null";
        configs.add(configuration);
        if (getLifecycleState() == RUNNING) {
            Context context = configuration.createContext();
            if (!(context instanceof CompositeContext)) {
                ScopeInitializationException e = new ScopeInitializationException("Context not an composite type");
                e.setIdentifier(context.getName());
                throw e;
            }
            CompositeContext compositeCtx = (CompositeContext) context;
            compositeCtx.start();
            if (moduleScopeStarted) {
View Full Code Here

    public boolean isCacheable() {
        return false;
    }

    public Object getInstance(QualifiedName qName) throws TargetException {
        Context context = getContext(qName.getPartName());
        if (context == null) {
            TargetException e = new TargetException("Component not found");
            e.setIdentifier(qName.getQualifiedName());
            throw e;
        }
        return context.getInstance(qName);
    }
View Full Code Here

    public Context getContextByKey(String ctxName, Object key) {
        return getContext(ctxName);
    }

    public void removeContext(String ctxName) throws ScopeRuntimeException {
        Context context = contexts.remove(ctxName);
        if (context != null) {
            context.stop();
        }
    }
View Full Code Here

        // use the port name to get the context since entry points ports
        ScopeContext scope = scopeIndex.get(qName.getPortName());
        if (scope == null) {
            return null;
        }
        Context ctx = scope.getContext(qName.getPortName());
        if (!(ctx instanceof EntryPointContext)) {
            TargetException e = new TargetException("Target not an entry point");
            e.setIdentifier(qName.getQualifiedName());
            e.addContextName(name);
            throw e;
        }
        return ctx.getInstance(null);
    }
View Full Code Here

    /**
     * Tests a module-to-module scoped wire is setup properly by the runtime
     */
    public void testModuleToModule() throws Exception{
        RuntimeContext runtime = MockFactory.createJavaRuntime();
        Context ctx = runtime.getSystemContext().getContext("tuscany.system.child");
        Assert.assertNotNull(ctx);
        runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test"));
        CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test");
        Assert.assertNotNull(testCtx);
        testCtx.registerModelObject(MockFactory.createModule());
View Full Code Here

TOP

Related Classes of org.apache.tuscany.core.context.Context

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.