Search in sources :

Example 21 with JavelinConnector

use of com.twinsoft.convertigo.beans.connectors.JavelinConnector in project convertigo by convertigo.

the class JavelinConnectorComposite method createWaitAtFromSelectionZone.

public void createWaitAtFromSelectionZone() {
    JavelinConnector javelinConnector = (JavelinConnector) connector;
    if (javelinConnector.isLearning()) {
        long timeout = 1000;
        if (!bHandlerOpened)
            openScreenClassHandler(true);
        // If there was a pending doAction command, clear it
        if (bDoAction) {
            bDoAction = false;
            long rightNow = new java.util.Date().getTime();
            timeout = rightNow - doActionTime;
        }
        Javelin javelin = getJavelin();
        Rectangle zone = javelin.getSelectionZone();
        String strZone = javelin.getString(zone.x, zone.y, zone.width);
        writeLine("javelin.waitAt(\"" + strZone + "\", " + zone.x + ", " + zone.y + ", " + ((int) (timeout * 1.3)) + ");");
        bWaitForDataStable = false;
        javelin.setSelectionZone(new Rectangle(0, 0, 0, 0));
        javelin.requestFocus();
    }
}
Also used : JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) Rectangle(java.awt.Rectangle) Javelin(com.twinsoft.twinj.Javelin)

Example 22 with JavelinConnector

use of com.twinsoft.convertigo.beans.connectors.JavelinConnector in project convertigo by convertigo.

the class JavelinConnectorComposite method refresh.

public void refresh() {
    JavelinConnector javelinConnector = (JavelinConnector) connector;
    if (javelinConnector.javelin != null) {
        javelinConnector.javelin.invalidate();
        javelinConnector.javelin.repaint();
        javelinConnector.javelin.validate();
        javelinConnector.javelin.requestFocus();
    }
}
Also used : JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector)

Example 23 with JavelinConnector

use of com.twinsoft.convertigo.beans.connectors.JavelinConnector in project convertigo by convertigo.

the class ContextManager method verifyPoolContext.

private boolean verifyPoolContext(Context context) {
    JavelinConnector javelinConnector = (JavelinConnector) context.getConnector();
    if (javelinConnector == null) {
        return true;
    }
    // TODO: find why the javelin is null sometimes with pools
    if (javelinConnector.javelin == null) {
        return true;
    }
    Engine.logContextManager.trace("verifyPoolContext() context=" + context.contextID);
    Engine.logContextManager.trace("verifyPoolContext() connector=" + Integer.toHexString(javelinConnector.hashCode()));
    Engine.logContextManager.trace("verifyPoolContext() javelin=" + Integer.toHexString(javelinConnector.javelin.hashCode()));
    boolean isConnected = ((iJavelin) javelinConnector.javelin).isConnected();
    Engine.logContextManager.trace("verifyPoolContext() isConnected=" + isConnected);
    boolean isInExpectedScreenClass = true;
    String initialScreenClass = context.pool.getInitialScreenClass();
    String currentScreenClassName = "none";
    if (initialScreenClass.length() > 0) {
        ScreenClass currentScreenClass = javelinConnector.getCurrentScreenClass();
        currentScreenClassName = currentScreenClass.getName();
        isInExpectedScreenClass = initialScreenClass.equals(currentScreenClass.getName());
    }
    Engine.logContextManager.trace("verifyPoolContext() expected screen class: " + context.pool.getInitialScreenClass());
    Engine.logContextManager.trace("verifyPoolContext() current screen class: " + currentScreenClassName);
    Engine.logContextManager.trace("verifyPoolContext() isInExpectedScreenClass=" + isInExpectedScreenClass);
    boolean b = isConnected && isInExpectedScreenClass;
    if (!b) {
        Engine.logContextManager.warn("Zombie context detected! context: " + context.contextID);
    }
    return b;
}
Also used : JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) com.twinsoft.twinj.iJavelin(com.twinsoft.twinj.iJavelin)

Example 24 with JavelinConnector

use of com.twinsoft.convertigo.beans.connectors.JavelinConnector 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 25 with JavelinConnector

use of com.twinsoft.convertigo.beans.connectors.JavelinConnector in project convertigo by convertigo.

the class Get method createCategories.

private void createCategories(Document document, DatabaseObject dbo, Class<? extends DatabaseObject> databaseObjectClass, Element root) throws Exception {
    Element response = document.createElement("response");
    try {
        List<String> defaultDboList = new ArrayList<>();
        Class<? extends DatabaseObject> parentObjectClass = dbo.getClass();
        Map<String, DboCategoryData> categoryNameToDboCategory = new HashMap<>();
        DboExplorerManager manager = Engine.theApp.getDboExplorerManager();
        for (DboGroup group : manager.getGroups()) {
            for (DboCategory category : group.getCategories()) {
                for (DboBeans beansCategory : category.getBeans()) {
                    for (DboBean bean : beansCategory.getBeans()) {
                        // Skip if bean is disabled
                        if (!bean.isEnable()) {
                            continue;
                        }
                        String className = bean.getClassName();
                        try {
                            Class<DatabaseObject> beanClass = GenericUtils.cast(Class.forName(className));
                            DboCategoryInfo dboCategoryInfo = DatabaseObject.getDboGroupInfo(beanClass);
                            if (dboCategoryInfo == null) {
                                continue;
                            }
                            // If one of these cases, do not add the category
                            if (dbo instanceof ScreenClass) {
                                ScreenClass sc = (ScreenClass) dbo;
                                // Do not show Criteria category if it is the default Screen Class
                                if (sc.getDepth() == 0 && dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Criteria.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof CicsConnector) {
                                // Do not show Pool category
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Pool.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof JavelinConnector) {
                                // Do not show ScreenClass category
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(ScreenClass.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof SqlConnector) {
                                // Do not show Pool category
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Pool.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof HtmlConnector) {
                                // Do not show Pool and ScreenClass categories
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Pool.class)) || dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(ScreenClass.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof HttpConnector) {
                                // Do not show Pool category
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Pool.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof SiteClipperConnector) {
                                // Do not show Pool and ScreenClass categories
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Pool.class)) || dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(ScreenClass.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof Transaction) {
                                // Do not show Statement category
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Statement.class))) {
                                    continue;
                                }
                            }
                            if (bean.isDefault()) {
                                defaultDboList.add(className);
                            }
                            // The bean should derived from
                            // DatabaseObject...
                            boolean isDatabaseObject = (DatabaseObject.class.isAssignableFrom(beanClass));
                            if (isDatabaseObject) {
                                // ... and should derived from the specified class
                                boolean isFromSpecifiedClass = (databaseObjectClass == null || (databaseObjectClass != null && databaseObjectClass.isAssignableFrom(beanClass)));
                                if (isFromSpecifiedClass) {
                                    // Check parent
                                    boolean bFound = DatabaseObjectsManager.checkParent(parentObjectClass, bean);
                                    if (bFound) {
                                        String technology = DboUtils.getTechnology(dbo, beanClass);
                                        // Check technology if needed
                                        if (technology != null) {
                                            Collection<String> acceptedTechnologies = bean.getEmulatorTechnologies();
                                            if (!acceptedTechnologies.isEmpty() && !acceptedTechnologies.contains(technology)) {
                                                continue;
                                            }
                                        }
                                        String beanInfoClassName = className + "BeanInfo";
                                        Class<BeanInfo> beanInfoClass = GenericUtils.cast(Class.forName(beanInfoClassName));
                                        if (beanInfoClass != null) {
                                            String categoryName = dboCategoryInfo.getCategoryName();
                                            // Create category
                                            DboCategoryData dboCategoryData = categoryNameToDboCategory.get(categoryName);
                                            if (dboCategoryData == null) {
                                                dboCategoryData = new DboCategoryData(dboCategoryInfo.getCategoryId(), categoryName, dboCategoryInfo.getIconClassCSS());
                                                categoryNameToDboCategory.put(categoryName, dboCategoryData);
                                            }
                                            // Beans name
                                            String beansName = beansCategory.getName();
                                            if (beansName.length() == 0) {
                                                beansName = categoryName;
                                            }
                                            // Create beans
                                            DboBeansData dboBeansData = dboCategoryData.getDboBeans(beansName);
                                            if (dboBeansData == null) {
                                                dboBeansData = new DboBeansData(beansName);
                                                dboCategoryData.addDboBeans(beansName, dboBeansData);
                                            }
                                            // Create bean
                                            DboBeanData dboBeanData = new DboBeanData(beanInfoClass.getConstructor().newInstance());
                                            dboBeansData.addDboBean(dboBeanData);
                                        } else {
                                            String message = java.text.MessageFormat.format("The \"{0}\" does not exist.", new Object[] { beanInfoClassName });
                                            throw new Exception(message);
                                        }
                                    }
                                }
                            } else {
                                String message = java.text.MessageFormat.format("The \"{0}\" class is not a Convertigo database object.", new Object[] { className });
                                throw new Exception(message);
                            }
                        } catch (ClassNotFoundException e) {
                            String message = java.text.MessageFormat.format("Unable to analyze the \"{0}\" class.\n\nClass not found: {1}", new Object[] { className, e.getMessage() });
                            throw new Exception(message);
                        } catch (Throwable e) {
                            String message = java.text.MessageFormat.format("Unable to analyze the \"{0}\" Convertigo database object.", new Object[] { className });
                            throw new Exception(message);
                        }
                    }
                }
            }
        }
        // Find the default selected bean for each categories
        for (DboCategoryData dboCategory : categoryNameToDboCategory.values()) {
            boolean defaultDboFound = false;
            List<DboBeanData> dboBeansList = dboCategory.getAllDboBean(true);
            // By default, we chose the first bean as default selected bean
            DboBeanData defaultSelectedBean = dboBeansList.get(0);
            // Find the default selected bean
            for (int i = 0; i < dboBeansList.size() && !defaultDboFound; ++i) {
                Class<DatabaseObject> beanClass = dboBeansList.get(i).getBeanClass();
                // Another bean is set as default selected bean
                if (defaultDboFound = defaultDboList.contains(beanClass.getName())) {
                    defaultSelectedBean = dboBeansList.get(i);
                }
            }
            defaultSelectedBean.setSelectedByDefault(true);
        }
        // XmlLize
        for (DboCategoryData dboCategory : categoryNameToDboCategory.values()) {
            response.appendChild(dboCategory.toXml(document));
        }
    } catch (Exception e) {
        throw new Exception("Unable to load database objects properties.");
    }
    root.appendChild(response);
}
Also used : HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) HashMap(java.util.HashMap) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) Element(org.w3c.dom.Element) BeanInfo(java.beans.BeanInfo) ArrayList(java.util.ArrayList) DboCategory(com.twinsoft.convertigo.engine.dbo_explorer.DboCategory) DboBeansData(com.twinsoft.convertigo.beans.dbo_explorer.DboBeansData) DboBeanData(com.twinsoft.convertigo.beans.dbo_explorer.DboBeanData) SqlConnector(com.twinsoft.convertigo.beans.connectors.SqlConnector) DboCategoryInfo(com.twinsoft.convertigo.beans.core.DatabaseObject.DboCategoryInfo) SiteClipperConnector(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector) DboCategoryData(com.twinsoft.convertigo.beans.dbo_explorer.DboCategoryData) DboGroup(com.twinsoft.convertigo.engine.dbo_explorer.DboGroup) DboExplorerManager(com.twinsoft.convertigo.engine.dbo_explorer.DboExplorerManager) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DboBeans(com.twinsoft.convertigo.engine.dbo_explorer.DboBeans) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) Transaction(com.twinsoft.convertigo.beans.core.Transaction) CicsConnector(com.twinsoft.convertigo.beans.connectors.CicsConnector) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DboBean(com.twinsoft.convertigo.engine.dbo_explorer.DboBean)

Aggregations

JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)50 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)17 Javelin (com.twinsoft.twinj.Javelin)12 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)11 Connector (com.twinsoft.convertigo.beans.core.Connector)11 EngineException (com.twinsoft.convertigo.engine.EngineException)10 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)9 Transaction (com.twinsoft.convertigo.beans.core.Transaction)8 JavelinTransaction (com.twinsoft.convertigo.beans.transactions.JavelinTransaction)8 XMLRectangle (com.twinsoft.convertigo.beans.common.XMLRectangle)7 SiteClipperConnector (com.twinsoft.convertigo.beans.connectors.SiteClipperConnector)7 SqlConnector (com.twinsoft.convertigo.beans.connectors.SqlConnector)7 CicsConnector (com.twinsoft.convertigo.beans.connectors.CicsConnector)6 HttpConnector (com.twinsoft.convertigo.beans.connectors.HttpConnector)6 com.twinsoft.twinj.iJavelin (com.twinsoft.twinj.iJavelin)6 Project (com.twinsoft.convertigo.beans.core.Project)5 ScHandlerStatement (com.twinsoft.convertigo.beans.statements.ScHandlerStatement)5 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)5 AbstractConnectorComposite (com.twinsoft.convertigo.eclipse.editors.connector.AbstractConnectorComposite)5 ConnectorEditor (com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor)5