Package org.wso2.carbon.application.deployer.config

Examples of org.wso2.carbon.application.deployer.config.RegistryConfig$Association


    static AssociationEnd getOppositeAssociationEnd(final Property associationEnd)
    {
        Object opposite = associationEnd.getOpposite();
        if (opposite == null)
        {
            Association association = associationEnd.getAssociation();

            if (association != null)
            {
                Collection ends = association.getMemberEnds();
                for (final Iterator endIterator = ends.iterator(); endIterator.hasNext();)
                {
                    final Object end = endIterator.next();
                    if (end != null && !associationEnd.equals(end))
                    {
View Full Code Here


                    + cacheKey);
        }

        // look up cache
        Object prop = cfgCtx.getPropertyNonReplicable(CachingConstants.CACHE_MANAGER);
        CacheManager cacheManager;
        if (prop != null && prop instanceof CacheManager) {
            cacheManager = (CacheManager) prop;
        } else {
            synchronized (cfgCtx) {
                // check again after taking the lock to make sure no one else did it before us
                prop = cfgCtx.getPropertyNonReplicable(CachingConstants.CACHE_MANAGER);
                if (prop != null && prop instanceof CacheManager) {
                    cacheManager = (CacheManager) prop;

                } else {
                    synLog.traceOrDebug("Creating/recreating the cache object");
                    cacheManager = new CacheManager();
                    cfgCtx.setProperty(CachingConstants.CACHE_MANAGER, cacheManager);
                }
            }
        }
View Full Code Here

            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug("Storing the response message into the cache at scope : " +
                    scope + " with ID : " + cacheKey + " for request hash : " + requestHash);
            }

            CachedObject cachedObj = cacheManager.getResponseForKey(cacheKey, requestHash, cfgCtx);
            if (cachedObj != null) {

                if (synLog.isTraceOrDebugEnabled()) {
                    synLog.traceOrDebug("Storing the response for the message with ID : " +
                        synCtx.getMessageID() + " with request hash ID : " +
                        cachedObj.getRequestHash() + " in the cache : " + cacheKey);
                }

                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                try {
                    MessageHelper.cloneSOAPEnvelope(synCtx.getEnvelope()).serialize(outStream);
                    cachedObj.setResponseEnvelope(outStream.toByteArray());
                } catch (XMLStreamException e) {
                    handleException("Unable to set the response to the Cache", e, synCtx);
                }

                /* this is not required yet, can commented this for perf improvements
                   in the future there can be a situation where user sends the request
                   with the response hash (if client side caching is on) in which case
                   we can compare that response hash with the given response hash and
                   respond with not-modified http header */
                // cachedObj.setResponseHash(cache.getGenerator().getDigest(
                //     ((Axis2MessageContext) synCtx).getAxis2MessageContext()));

                if (cachedObj.getTimeout() > 0) {
                    cachedObj.setExpireTimeMillis(System.currentTimeMillis() + cachedObj.getTimeout());
                }

                cfgCtx.setProperty(CachingConstants.CACHE_MANAGER, cacheManager);
//                Replicator.replicate(cfgCtx, new String[]{cacheManagerKey});
                Replicator.replicate(cfgCtx);
View Full Code Here

        if (cacheManager.containsKey(cacheKey, requestHash) &&
            cacheManager.getResponseForKey(cacheKey, requestHash, cfgCtx) != null) {

            // get the response from the cache and attach to the context and change the
            // direction of the message
            CachedObject cachedObj = cacheManager.getResponseForKey(cacheKey, requestHash, cfgCtx);

            if (!cachedObj.isExpired() && cachedObj.getResponseEnvelope() != null) {

                if (synLog.isTraceOrDebugEnabled()) {
                    synLog.traceOrDebug("Cache-hit for message ID : " + synCtx.getMessageID());
                }

                // mark as a response and replace envelope from cache
                synCtx.setResponse(true);
                try {
                    SOAPEnvelope omSOAPEnv = SOAPMessageHelper.buildSOAPEnvelopeFromBytes(
                            cachedObj.getResponseEnvelope());

                    // todo: if there is a WSA messageID in the response, is that need to be unique on each and every resp

                    synCtx.setEnvelope(omSOAPEnv);
                } catch (AxisFault axisFault) {
                    handleException("Error setting response envelope from cache : "
                        + cacheKey, synCtx);
                } catch (IOException ioe) {
                    handleException("Error setting response envelope from cache : "
                        + cacheKey, ioe, synCtx);
                } catch (SOAPException soape) {
                    handleException("Error setting response envelope from cache : "
                        + cacheKey, soape, synCtx);
                }

                // take specified action on cache hit
                if (onCacheHitSequence != null) {
                    // if there is an onCacheHit use that for the mediation
                    synLog.traceOrDebug("Delegating message to the onCachingHit "
                            + "Anonymous sequence");
                    onCacheHitSequence.mediate(synCtx);

                } else if (onCacheHitRef != null) {

                    if (synLog.isTraceOrDebugEnabled()) {
                        synLog.traceOrDebug("Delegating message to the onCachingHit " +
                            "sequence : " + onCacheHitRef);
                    }
                    synCtx.getSequence(onCacheHitRef).mediate(synCtx);

                } else {

                    if (synLog.isTraceOrDebugEnabled()) {
                        synLog.traceOrDebug("Request message " + synCtx.getMessageID() +
                            " was served from the cache : " + cacheKey);
                    }
                    // send the response back if there is not onCacheHit is specified
                    synCtx.setTo(null);
                    Axis2Sender.sendBack(synCtx);
                }
                // stop any following mediators from executing
                return false;

            } else {
                // cache exists, but has expired...
                cachedObj.expire();
                cachedObj.setTimeout(timeout);
                synLog.traceOrDebug("Existing cached response has expired. Reset cache element");

                cfgCtx.setProperty(CachingConstants.CACHE_MANAGER, cacheManager);
//                Replicator.replicate(cfgCtx, new String[]{cacheManagerKey});
                Replicator.replicate(cfgCtx);
View Full Code Here

     * @throws ClusteringFault if there is an error in replicating the cfgCtx
     */
    private void storeRequestToCache(ConfigurationContext cfgCtx,
        String requestHash, CacheManager cacheManager) throws ClusteringFault {

        CachedObject cachedObj = new CachedObject();
        cachedObj.setRequestHash(requestHash);
        // this does not set the expiretime but just sets the timeout and the espiretime will
        // be set when the response is availabel
        cachedObj.setTimeout(timeout);
        cacheManager.addResponseWithKey(cacheKey, requestHash, cachedObj, cfgCtx);

        cfgCtx.setProperty(CachingConstants.CACHE_MANAGER, cacheManager);
//        Replicator.replicate(cfgCtx, new String[]{cacheManagerKey});
        Replicator.replicate(cfgCtx);
View Full Code Here

                sgMetadata.setServices(services.toArray(new String[services.size()]));
                serviceGroups.add(sgMetadata);

            } else if (RegistryResourceDeployer.REGISTRY_RESOURCE_TYPE.equals(type)) {
                // Create a Registry config metadata instance
                RegistryConfig regConf = artifact.getRegConfig();
                if (regConf == null) {
                    regConf = readRegConfig(currentApplication.getAppName(), artifact.getName());
                }
                if (regConf == null) {
                    continue;
                }
                artifact.setRegConfig(regConf);
                RegistryMetadata regMeta = new RegistryMetadata();
                regMeta.setArtifactName(artifact.getName());

                List<String> resources = new ArrayList<String>();
                List<String> collections = new ArrayList<String>();
                List<Association> associations = new ArrayList<Association>();

                // add resources
                for (RegistryConfig.Resourse resourse : regConf.getResources()) {
                    resources.add(resourse.getPath() + "/" + resourse.getFileName());
                }
                // add collections
                for (RegistryConfig.Collection collection : regConf.getCollections()) {
                    collections.add(collection.getPath());
                }
                // add associations
                for (RegistryConfig.Association association : regConf.getAssociations()) {
                    Association assoMeta = new Association(association.getSourcePath(),
                            association.getTargetPath());
                    associations.add(assoMeta);
                }
View Full Code Here

        }
        return artifactType;
    }

    private RegistryConfig readRegConfig(String parentAppName, String artifactName) {
        RegistryConfig regConfig = null;
        try {
            CarbonAppPersistenceManager capm = new CarbonAppPersistenceManager(getAxisConfig());
            regConfig = capm.loadRegistryConfig(AppDeployerConstants.APPLICATIONS + parentAppName +
                                    AppDeployerConstants.APP_DEPENDENCIES + artifactName);
        } catch (Exception e) {
View Full Code Here

    private void deployRegistryArtifacts(CarbonAppPersistenceManager capm,
                                         List<Artifact> artifacts, String parentAppName) {
        for (Artifact artifact : artifacts) {
            if (REGISTRY_RESOURCE_TYPE.equals(artifact.getType())) {
                try {
                    RegistryConfig regConfig = buildRegistryConfig(artifact);
                    if (regConfig != null) {
                        capm.writeArtifactResources(regConfig);
                        capm.persistRegConfig(AppDeployerConstants.APPLICATIONS +
                                parentAppName + AppDeployerConstants.APP_DEPENDENCIES +
                                artifact.getName(), regConfig);
View Full Code Here

     *
     * @param artifact - Registry/Resource artifact
     * @return - RegistryConfig instance
     */
    private RegistryConfig buildRegistryConfig(Artifact artifact) {
        RegistryConfig regConfig = null;
        // get the file path of the registry config file
        List<CappFile> files = artifact.getFiles();
        if (files.size() == 1) {
            String fileName = artifact.getFiles().get(0).getName();
            String regConfigPath = artifact.getExtractedPath() +
                    File.separator + fileName;

            File f = new File(regConfigPath);
            if (f.exists()) {
                // read the reg config file and build the configuration
                InputStream xmlInputStream = null;
                try {
                    xmlInputStream = new FileInputStream(f);
                    regConfig = AppDeployerUtils.populateRegistryConfig(
                            new StAXOMBuilder(xmlInputStream).getDocumentElement());
                } catch (Exception e) {
                    log.error("Error while reading file : " + fileName, e);
                } finally {
                    if (xmlInputStream != null) {
                        try {
                            xmlInputStream.close();
                        } catch (IOException e) {
                            log.error("Error while closing input stream.", e);
                        }
                    }
                }

                if (regConfig != null) {
                    regConfig.setExtractedPath(artifact.getExtractedPath());
                    regConfig.setParentArtifactName(artifact.getName());
                    regConfig.setConfigFileName(fileName);
                }
            } else {
                log.error("Registry config file not found at : " + regConfigPath);
            }
        } else {
View Full Code Here

     * @param artifactPath - registry path of the "registry/resource" artifact
     * @return - RegistryConfig instance built
     * @throws Exception - on registry errors
     */
    public RegistryConfig loadRegistryConfig(String artifactPath) throws Exception {
        RegistryConfig regConfig = null;
        String regConfigPath = artifactPath + AppDeployerConstants.REG_CONFIG_XML;
        if (configRegistry.resourceExists(regConfigPath)) {
            Resource artifactResource = configRegistry.get(regConfigPath);
            InputStream xmlStream = artifactResource.getContentStream();
            if (xmlStream != null) {
View Full Code Here

TOP

Related Classes of org.wso2.carbon.application.deployer.config.RegistryConfig$Association

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.