Search in sources :

Example 31 with Connector

use of com.twinsoft.convertigo.beans.core.Connector in project convertigo by convertigo.

the class Migration7_0_0 method migrate.

public static void migrate(final String projectName) {
    try {
        Map<String, Reference> referenceMap = new HashMap<String, Reference>();
        XmlSchema projectSchema = null;
        Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName, false);
        // Copy all xsd files to project's xsd directory
        File destDir = new File(project.getXsdDirPath());
        copyXsdOfProject(projectName, destDir);
        String projectWsdlFilePath = Engine.PROJECTS_PATH + "/" + projectName + "/" + projectName + ".wsdl";
        File wsdlFile = new File(projectWsdlFilePath);
        String projectXsdFilePath = Engine.PROJECTS_PATH + "/" + projectName + "/" + projectName + ".xsd";
        File xsdFile = new File(projectXsdFilePath);
        if (xsdFile.exists()) {
            // Load project schema from old XSD file
            XmlSchemaCollection collection = new XmlSchemaCollection();
            collection.setSchemaResolver(new DefaultURIResolver() {

                public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) {
                    // Case of a c8o project location
                    if (schemaLocation.startsWith("../") && schemaLocation.endsWith(".xsd")) {
                        try {
                            String targetProjectName = schemaLocation.substring(3, schemaLocation.indexOf("/", 3));
                            File pDir = new File(Engine.projectDir(targetProjectName));
                            if (pDir.exists()) {
                                File pFile = new File(Engine.PROJECTS_PATH + schemaLocation.substring(2));
                                // Case c8o project is already migrated
                                if (!pFile.exists()) {
                                    Document doc = Engine.theApp.schemaManager.getSchemaForProject(targetProjectName).getSchemaDocument();
                                    DOMSource source = new DOMSource(doc);
                                    StringWriter writer = new StringWriter();
                                    StreamResult result = new StreamResult(writer);
                                    TransformerFactory.newInstance().newTransformer().transform(source, result);
                                    StringReader reader = new StringReader(writer.toString());
                                    return new InputSource(reader);
                                }
                            }
                            return null;
                        } catch (Exception e) {
                            Engine.logDatabaseObjectManager.warn("[Migration 7.0.0] Unable to find schema location \"" + schemaLocation + "\"", e);
                            return null;
                        }
                    } else if (schemaLocation.indexOf("://") == -1 && schemaLocation.endsWith(".xsd")) {
                        return super.resolveEntity(targetNamespace, schemaLocation, Engine.PROJECTS_PATH + "/" + projectName);
                    }
                    return super.resolveEntity(targetNamespace, schemaLocation, baseUri);
                }
            });
            projectSchema = SchemaUtils.loadSchema(new File(projectXsdFilePath), collection);
            ConvertigoError.updateXmlSchemaObjects(projectSchema);
            SchemaMeta.setCollection(projectSchema, collection);
            for (Connector connector : project.getConnectorsList()) {
                for (Transaction transaction : connector.getTransactionsList()) {
                    try {
                        // Migrate transaction in case of a Web Service consumption project
                        if (transaction instanceof XmlHttpTransaction) {
                            XmlHttpTransaction xmlHttpTransaction = (XmlHttpTransaction) transaction;
                            String reqn = xmlHttpTransaction.getResponseElementQName();
                            if (!reqn.equals("")) {
                                boolean useRef = reqn.indexOf(";") == -1;
                                // Doc/Literal case
                                if (useRef) {
                                    try {
                                        String[] qn = reqn.split(":");
                                        QName refName = new QName(projectSchema.getNamespaceContext().getNamespaceURI(qn[0]), qn[1]);
                                        xmlHttpTransaction.setXmlElementRefAffectation(new XmlQName(refName));
                                    } catch (Exception e) {
                                    }
                                } else // RPC case
                                {
                                    int index, index2;
                                    try {
                                        index = reqn.indexOf(";");
                                        String opName = reqn.substring(0, index);
                                        if ((index2 = reqn.indexOf(";", index + 1)) != -1) {
                                            String eltName = reqn.substring(index + 1, index2);
                                            String eltType = reqn.substring(index2 + 1);
                                            String[] qn = eltType.split(":");
                                            QName typeName = new QName(projectSchema.getNamespaceContext().getNamespaceURI(qn[0]), qn[1]);
                                            String responseElementQName = opName + ";" + eltName + ";" + "{" + typeName.getNamespaceURI() + "}" + typeName.getLocalPart();
                                            xmlHttpTransaction.setResponseElementQName(responseElementQName);
                                        }
                                    } catch (Exception e) {
                                    }
                                }
                            }
                        }
                        // Retrieve required XmlSchemaObjects for transaction
                        QName requestQName = new QName(project.getTargetNamespace(), transaction.getXsdRequestElementName());
                        QName responseQName = new QName(project.getTargetNamespace(), transaction.getXsdResponseElementName());
                        LinkedHashMap<QName, XmlSchemaObject> map = new LinkedHashMap<QName, XmlSchemaObject>();
                        XmlSchemaWalker dw = XmlSchemaWalker.newDependencyWalker(map, true, false);
                        dw.walkByElementRef(projectSchema, requestQName);
                        dw.walkByElementRef(projectSchema, responseQName);
                        // Create transaction schema
                        String targetNamespace = projectSchema.getTargetNamespace();
                        String prefix = projectSchema.getNamespaceContext().getPrefix(targetNamespace);
                        XmlSchema transactionSchema = SchemaUtils.createSchema(prefix, targetNamespace, XsdForm.unqualified.name(), XsdForm.unqualified.name());
                        // Add required prefix declarations
                        List<String> nsList = new LinkedList<String>();
                        for (QName qname : map.keySet()) {
                            String nsURI = qname.getNamespaceURI();
                            if (!nsURI.equals(Constants.URI_2001_SCHEMA_XSD)) {
                                if (!nsList.contains(nsURI)) {
                                    nsList.add(nsURI);
                                }
                            }
                            String nsPrefix = qname.getPrefix();
                            if (!nsURI.equals(targetNamespace)) {
                                NamespaceMap nsMap = SchemaUtils.getNamespaceMap(transactionSchema);
                                if (nsMap.getNamespaceURI(nsPrefix) == null) {
                                    nsMap.add(nsPrefix, nsURI);
                                    transactionSchema.setNamespaceContext(nsMap);
                                }
                            }
                        }
                        // Add required imports
                        for (String namespaceURI : nsList) {
                            XmlSchemaObjectCollection includes = projectSchema.getIncludes();
                            for (int i = 0; i < includes.getCount(); i++) {
                                XmlSchemaObject xmlSchemaObject = includes.getItem(i);
                                if (xmlSchemaObject instanceof XmlSchemaImport) {
                                    if (((XmlSchemaImport) xmlSchemaObject).getNamespace().equals(namespaceURI)) {
                                        // do not allow import with same ns !
                                        if (namespaceURI.equals(project.getTargetNamespace()))
                                            continue;
                                        String location = ((XmlSchemaImport) xmlSchemaObject).getSchemaLocation();
                                        // This is a convertigo project reference
                                        if (location.startsWith("../")) {
                                            // Copy all xsd files to xsd directory
                                            String targetProjectName = location.substring(3, location.indexOf("/", 3));
                                            copyXsdOfProject(targetProjectName, destDir);
                                        }
                                        // Add reference
                                        addReferenceToMap(referenceMap, namespaceURI, location);
                                        // Add import
                                        addImport(transactionSchema, namespaceURI, location);
                                    }
                                }
                            }
                        }
                        QName responseTypeQName = new QName(project.getTargetNamespace(), transaction.getXsdResponseTypeName());
                        // Add required schema objects
                        for (QName qname : map.keySet()) {
                            if (qname.getNamespaceURI().equals(targetNamespace)) {
                                XmlSchemaObject ob = map.get(qname);
                                if (qname.getLocalPart().startsWith("ConvertigoError"))
                                    continue;
                                transactionSchema.getItems().add(ob);
                                // Add missing response error element and attributes
                                if (qname.equals(responseTypeQName)) {
                                    Transaction.addSchemaResponseObjects(transactionSchema, (XmlSchemaComplexType) ob);
                                }
                            }
                        }
                        // Add missing ResponseType (with document)
                        if (map.containsKey(responseTypeQName)) {
                            Transaction.addSchemaResponseType(transactionSchema, transaction);
                        }
                        // Add everything
                        if (map.isEmpty()) {
                            Transaction.addSchemaObjects(transactionSchema, transaction);
                        }
                        // Add c8o error objects (for internal xsd edition only)
                        ConvertigoError.updateXmlSchemaObjects(transactionSchema);
                        // Save schema to file
                        String transactionXsdFilePath = transaction.getSchemaFilePath();
                        new File(transaction.getSchemaFileDirPath()).mkdirs();
                        SchemaUtils.saveSchema(transactionXsdFilePath, transactionSchema);
                    } catch (Exception e) {
                        Engine.logDatabaseObjectManager.error("[Migration 7.0.0] An error occured while migrating transaction \"" + transaction.getName() + "\"", e);
                    }
                    if (transaction instanceof TransactionWithVariables) {
                        TransactionWithVariables transactionVars = (TransactionWithVariables) transaction;
                        handleRequestableVariable(transactionVars.getVariablesList());
                        // Change SQLQuery variables : i.e. {id} --> {{id}}
                        if (transaction instanceof SqlTransaction) {
                            String sqlQuery = ((SqlTransaction) transaction).getSqlQuery();
                            sqlQuery = sqlQuery.replaceAll("\\{([a-zA-Z0-9_]+)\\}", "{{$1}}");
                            ((SqlTransaction) transaction).setSqlQuery(sqlQuery);
                        }
                    }
                }
            }
        } else {
            // Should only happen for projects which version <= 4.6.0
            XmlSchemaCollection collection = new XmlSchemaCollection();
            String prefix = project.getName() + "_ns";
            projectSchema = SchemaUtils.createSchema(prefix, project.getNamespaceUri(), XsdForm.unqualified.name(), XsdForm.unqualified.name());
            ConvertigoError.addXmlSchemaObjects(projectSchema);
            SchemaMeta.setCollection(projectSchema, collection);
            for (Connector connector : project.getConnectorsList()) {
                for (Transaction transaction : connector.getTransactionsList()) {
                    if (transaction instanceof TransactionWithVariables) {
                        TransactionWithVariables transactionVars = (TransactionWithVariables) transaction;
                        handleRequestableVariable(transactionVars.getVariablesList());
                    }
                }
            }
        }
        // Handle sequence objects
        for (Sequence sequence : project.getSequencesList()) {
            handleSteps(projectSchema, referenceMap, sequence.getSteps());
            handleRequestableVariable(sequence.getVariablesList());
        }
        // Add all references to project
        if (!referenceMap.isEmpty()) {
            for (Reference reference : referenceMap.values()) project.add(reference);
        }
        // Delete XSD file
        if (xsdFile.exists())
            xsdFile.delete();
        // Delete WSDL file
        if (wsdlFile.exists())
            wsdlFile.delete();
    } catch (Exception e) {
        Engine.logDatabaseObjectManager.error("[Migration 7.0.0] An error occured while migrating project \"" + projectName + "\"", e);
    }
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) InputSource(org.xml.sax.InputSource) DOMSource(javax.xml.transform.dom.DOMSource) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Document(org.w3c.dom.Document) LinkedHashMap(java.util.LinkedHashMap) XmlSchemaWalker(com.twinsoft.convertigo.engine.util.XmlSchemaWalker) StringWriter(java.io.StringWriter) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) DefaultURIResolver(org.apache.ws.commons.schema.resolver.DefaultURIResolver) StringReader(java.io.StringReader) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection) StreamResult(javax.xml.transform.stream.StreamResult) Reference(com.twinsoft.convertigo.beans.core.Reference) ProjectSchemaReference(com.twinsoft.convertigo.beans.references.ProjectSchemaReference) ImportXsdSchemaReference(com.twinsoft.convertigo.beans.references.ImportXsdSchemaReference) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) QName(javax.xml.namespace.QName) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) Sequence(com.twinsoft.convertigo.beans.core.Sequence) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException) LinkedList(java.util.LinkedList) Project(com.twinsoft.convertigo.beans.core.Project) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) SqlTransaction(com.twinsoft.convertigo.beans.transactions.SqlTransaction) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) XmlSchema(org.apache.ws.commons.schema.XmlSchema) NamespaceMap(org.apache.ws.commons.schema.utils.NamespaceMap) TransactionWithVariables(com.twinsoft.convertigo.beans.core.TransactionWithVariables) File(java.io.File)

Example 32 with Connector

use of com.twinsoft.convertigo.beans.core.Connector in project convertigo by convertigo.

the class HtmlConnectorDesignComposite method checkEventSource.

private boolean checkEventSource(EventObject event) {
    boolean isSourceFromConnector = false;
    Object source = event.getSource();
    if (event instanceof EngineEvent) {
        if (source instanceof DatabaseObject) {
            Connector connector = ((DatabaseObject) source).getConnector();
            if ((connector != null) && (connector.equals(htmlConnector)))
                isSourceFromConnector = true;
        }
    }
    return isSourceFromConnector;
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) EngineEvent(com.twinsoft.convertigo.engine.EngineEvent) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) EventObject(java.util.EventObject) TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ConnectorTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ConnectorTreeObject)

Example 33 with Connector

use of com.twinsoft.convertigo.beans.core.Connector in project convertigo by convertigo.

the class AbstractConnectorComposite method selectionChanged.

/**
 * Handles tree view selection
 */
public void selectionChanged(SelectionChangedEvent event) {
    if (event.getSource() instanceof ISelectionProvider) {
        IStructuredSelection selection = (IStructuredSelection) event.getSelection();
        TreeObject treeObject = (TreeObject) selection.getFirstElement();
        if (treeObject != null) {
            if (ILearnable.class.isAssignableFrom(this.getClass()) && (!HttpConnectorComposite.class.equals(this.getClass()))) {
                ConnectorTreeObject connectorTreeObject = treeObject.getConnectorTreeObject();
                if (connectorTreeObject != null) {
                    Connector connector = (Connector) connectorTreeObject.getObject();
                    if (connector.equals(this.connector)) {
                        if (treeObject instanceof TransactionTreeObject) {
                            if (!this.connector.isLearning())
                                toolBarSetEnable("Learn", true);
                        } else {
                            if (!this.connector.isLearning())
                                toolBarSetEnable("Learn", false);
                        }
                    } else {
                        if (!this.connector.isLearning())
                            toolBarSetEnable("Learn", false);
                    }
                }
            }
        }
    }
}
Also used : ConnectorTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ConnectorTreeObject) Connector(com.twinsoft.convertigo.beans.core.Connector) TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ConnectorTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ConnectorTreeObject) TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 34 with Connector

use of com.twinsoft.convertigo.beans.core.Connector in project convertigo by convertigo.

the class ContextManager method managePoolContexts.

private void managePoolContexts() {
    if (Engine.isStudioMode()) {
        return;
    }
    if (!Engine.isStarted) {
        Engine.logContextManager.debug("Engine is stopped => do not manage pools");
        return;
    }
    Engine.logContextManager.debug("Executing vulture thread for context pooling");
    try {
        long timeout = manage_poll_timeout;
        long now = System.currentTimeMillis();
        if (timeout != -1) {
            timeout += now;
        }
        pooledContextsToCreateSet.clear();
        Map<String, Integer> counters = new HashMap<String, Integer>();
        // with the auto-start transaction
        for (String projectName : Engine.theApp.databaseObjectsManager.getAllProjectNamesList()) {
            if (!isRunning)
                return;
            Engine.logContextManager.trace("Analyzing project " + projectName);
            Project project = null;
            try {
                project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
            } catch (Exception e) {
                Engine.logContextManager.warn("Unable to load project '" + projectName + "'; avorting pool research for this project", e);
                continue;
            }
            Collection<Connector> vConnectors = project.getConnectorsList();
            Engine.logContextManager.trace("Connectors: " + vConnectors);
            for (Connector connector : vConnectors) {
                if (!isRunning)
                    return;
                Engine.logContextManager.trace("Connector: " + connector);
                Collection<Pool> vPools = connector.getPoolsList();
                Engine.logContextManager.trace("Pools: " + vPools);
                String poolName;
                for (Pool pool : vPools) {
                    if (!isRunning)
                        return;
                    poolName = pool.getName();
                    Engine.logContextManager.trace("Pool: " + poolName);
                    int pooledContexts = pool.getNumberOfContexts();
                    Engine.logContextManager.debug("Pool size: " + pooledContexts);
                    String poolNameWithPath = pool.getNameWithPath();
                    pooledContextsInUse = 0;
                    pooledContextsLocked = 0;
                    pooledContextsZombie = 0;
                    pooledContextsToCreate = 0;
                    counters.put(poolNameWithPath, 0);
                    if (pooledContexts > 0) {
                        for (int i = 1; i <= pool.getNumberOfContexts(); i++) {
                            if (!isRunning)
                                return;
                            Project localProject = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
                            Connector localConnector = localProject.getConnectorByName(connector.getName());
                            Pool localPool = localConnector.getPoolByName(pool.getName());
                            String servCode = localPool.getServiceCode();
                            if (servCode != null && !servCode.equals("")) {
                                if (localConnector instanceof JavelinConnector) {
                                    ((JavelinConnector) localConnector).setServiceCode(servCode);
                                    Engine.logContextManager.trace("Connector service code overridden to : " + servCode);
                                }
                            // TODO add code for each specific connector to use pools serviceCode property
                            }
                            managePoolContext(localProject, localConnector, localPool, i);
                        }
                        int pooledContextsInUsePercentage = 100 * pooledContextsInUse / pooledContexts;
                        int pooledContextsLockedPercentage = 100 * pooledContextsLocked / pooledContexts;
                        String poolStatistics = "Pool '" + poolNameWithPath + "' usage: pool size: " + pooledContexts + "; in use contexts: " + pooledContextsInUse + " (" + pooledContextsInUsePercentage + "%); zombie contexts: " + pooledContextsZombie;
                        ;
                        if (pooledContextsZombie > 0) {
                            Engine.logContextManager.warn("Pool '" + poolNameWithPath + "' had zombie contexts!");
                            Engine.logContextManager.warn(poolStatistics);
                        }
                        if (pooledContextsInUsePercentage > 80) {
                            Engine.logContextManager.warn("Pool '" + poolNameWithPath + "' is overloaded!");
                            Engine.logContextManager.warn(poolStatistics);
                        }
                        Engine.theApp.usageMonitor.setUsageCounter("[Pool] '" + poolNameWithPath + "' size", pooledContexts);
                        Engine.theApp.usageMonitor.setUsageCounter("[Pool] '" + poolNameWithPath + "' in use contexts", pooledContextsInUse + " (" + pooledContextsInUsePercentage + "%)");
                        Engine.theApp.usageMonitor.setUsageCounter("[Pool] '" + poolNameWithPath + "' locked contexts", pooledContextsLocked + " (" + pooledContextsLockedPercentage + "%)");
                        Engine.theApp.usageMonitor.setUsageCounter("[Pool] '" + poolNameWithPath + "' zombie contexts", pooledContextsZombie);
                        Engine.theApp.usageMonitor.setUsageCounter("[Pool] '" + poolNameWithPath + "' to be created contexts", pooledContextsToCreate);
                    }
                }
            }
        }
        for (Pair<Pool, Integer> pooledContextToCreate : pooledContextsToCreateSet) {
            if (!isRunning)
                return;
            String key = pooledContextToCreate.getKey().getNameWithPath();
            createPoolContext(pooledContextToCreate.getKey(), pooledContextToCreate.getValue());
            counters.put(key, counters.get(key) + 1);
            if (timeout != -1 && (now = System.currentTimeMillis()) > timeout)
                break;
        }
        for (Entry<String, Integer> entry : counters.entrySet()) {
            if (!isRunning)
                return;
            Engine.theApp.usageMonitor.setUsageCounter("[Pool] '" + entry.getKey() + "' (re)created contexts", entry.getValue());
        }
    } catch (EngineException e) {
        Engine.logContextManager.error("An unexpected error has occured in the ContextManager vulture while managing the pool contexts.", e);
    }
    Engine.logContextManager.debug("Pools creation successfully finished");
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Project(com.twinsoft.convertigo.beans.core.Project) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) Pool(com.twinsoft.convertigo.beans.core.Pool) DevicePool(com.twinsoft.util.DevicePool)

Example 35 with Connector

use of com.twinsoft.convertigo.beans.core.Connector in project convertigo by convertigo.

the class ContextManager method findPoolContext.

private Context findPoolContext(String contextName, String projectName, String connectorName, String poolName) throws EngineException {
    Engine.logContextManager.debug("Trying to find a pooled context");
    Engine.logContextManager.debug("   contextName=" + contextName);
    Engine.logContextManager.debug("   projectName=" + projectName);
    Engine.logContextManager.debug("   connectorName=" + connectorName);
    Engine.logContextManager.debug("   poolName=" + poolName);
    Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
    Connector connector;
    if (connectorName == null) {
        connector = project.getDefaultConnector();
        connectorName = connector.getName();
    } else
        connector = project.getConnectorByName(connectorName);
    // If we cannot find the pool, abort the process
    Pool pool = connector.getPoolByName(poolName);
    if (pool == null) {
        Engine.logContextManager.debug("No pool named '" + poolName + "'; aborting pool management");
        return null;
    }
    Engine.logContextManager.debug("Found pool=" + pool);
    pool.checkSymbols();
    String contextIDPrefix = ContextManager.getPoolContextID(projectName, connectorName, poolName, "");
    if (contextName != null && !contextName.equals("default") && !contextName.equals("default*")) {
        Engine.logContextManager.debug("Explicit pooled context '" + contextIDPrefix + contextName + "' has been required");
        Context context = get(contextIDPrefix + contextName);
        if (context == null)
            throw new EngineException("Explicit pooled context '" + contextIDPrefix + contextName + "' does not exist!");
        Engine.logContextManager.debug("context.waitingRequests=" + context.waitingRequests);
        Engine.logContextManager.debug("context.lockPooledContext=" + context.lockPooledContext);
        if (!context.lockPooledContext)
            throw new EngineException("Explicit pooled context '" + contextIDPrefix + contextName + "' has not been locked!");
        Engine.logContextManager.debug("The context has been previously locked and has been explicitely requested");
        return context;
    } else {
        Engine.logContextManager.debug("Searching for good candidate");
        for (Map.Entry<String, Context> entry : contexts.entrySet()) {
            Engine.logContextManager.debug("Analyzing context " + entry.getKey());
            if (entry.getKey().startsWith(contextIDPrefix)) {
                Context context = entry.getValue();
                Engine.logContextManager.debug("context.waitingRequests=" + context.waitingRequests);
                Engine.logContextManager.debug("context.lockPooledContext=" + context.lockPooledContext);
                if ((context.waitingRequests == 0) && (!context.lockPooledContext) && verifyPoolContext(context)) {
                    Engine.logContextManager.debug("Good candidate for election: " + context.contextID);
                    return entry.getValue();
                }
            }
        }
        throw new EngineException("No more available context on the pool " + poolName + "; please try again later.");
    }
}
Also used : Project(com.twinsoft.convertigo.beans.core.Project) Connector(com.twinsoft.convertigo.beans.core.Connector) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) Pool(com.twinsoft.convertigo.beans.core.Pool) DevicePool(com.twinsoft.util.DevicePool) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

Connector (com.twinsoft.convertigo.beans.core.Connector)72 Transaction (com.twinsoft.convertigo.beans.core.Transaction)43 Project (com.twinsoft.convertigo.beans.core.Project)32 EngineException (com.twinsoft.convertigo.engine.EngineException)28 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)22 Sequence (com.twinsoft.convertigo.beans.core.Sequence)21 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)17 Step (com.twinsoft.convertigo.beans.core.Step)17 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)16 HttpConnector (com.twinsoft.convertigo.beans.connectors.HttpConnector)15 SiteClipperConnector (com.twinsoft.convertigo.beans.connectors.SiteClipperConnector)14 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)14 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)14 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)12 CouchDbConnector (com.twinsoft.convertigo.beans.connectors.CouchDbConnector)11 SqlConnector (com.twinsoft.convertigo.beans.connectors.SqlConnector)11 Statement (com.twinsoft.convertigo.beans.core.Statement)11 ElseStep (com.twinsoft.convertigo.beans.steps.ElseStep)11 ThenStep (com.twinsoft.convertigo.beans.steps.ThenStep)11 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)11