Search in sources :

Example 1 with DevicePool

use of com.twinsoft.util.DevicePool in project convertigo by convertigo.

the class ContextManager method getDevicePool.

public synchronized DevicePool getDevicePool(String poolID, int iStart, int iStop, int iIncr, int iDigits) {
    DevicePool devicePool = getDevicePool(poolID);
    if (devicePool == null) {
        devicePool = new DevicePool();
        devicePool.init(iStart, iStop, iIncr, iDigits);
        addDevicePool(poolID, devicePool);
    }
    return devicePool;
}
Also used : DevicePool(com.twinsoft.util.DevicePool)

Example 2 with DevicePool

use of com.twinsoft.util.DevicePool in project convertigo by convertigo.

the class ContextManager method remove.

public void remove(Context context) {
    if (context == null) {
        // Silently ignore
        Engine.logContextManager.warn("The context cannot be removed because it does not exist any more!");
        return;
    }
    if (context.isDestroying) {
        return;
    }
    context.isDestroying = true;
    context.requireRemoval(false);
    try {
        String contextID = context.contextID;
        Engine.logContextManager.info("Removing context " + contextID);
        contexts.remove(contextID, context);
        if ((context.requestedObject != null) && (context.requestedObject.runningThread != null)) {
            Engine.logContextManager.debug("Stopping requestable thread for context " + contextID);
            // context.requestedObject.runningThread.bContinue = false;
            context.abortRequestable();
        }
        // Trying to execute the end transaction (only in the engine mode)
        if (Engine.isEngineMode()) {
            for (Connector connector : context.getOpenedConnectors()) {
                // Execute the end transaction
                String endTransactionName = "n/a";
                try {
                    endTransactionName = connector.getEndTransactionName();
                    if (endTransactionName != null && !endTransactionName.equals("")) {
                        Engine.logContextManager.debug("Trying to execute the end transaction: \"" + endTransactionName + "\"");
                        context.connectorName = connector.getName();
                        context.connector = connector;
                        context.transactionName = endTransactionName;
                        context.sequenceName = null;
                        DefaultRequester defaultRequester = new DefaultRequester();
                        // #4910 - prevent loop for destroying context renew
                        context.isDestroying = false;
                        context.requireRemoval(false);
                        defaultRequester.processRequest(context);
                        Engine.logContextManager.debug("End transaction successfull");
                    }
                } catch (Throwable e) {
                    Engine.logContextManager.error("Unable to execute the end transaction; " + "context: " + context.contextID + ", " + "project: " + context.projectName + ", " + "connector: " + context.connectorName + ", " + "end transaction: " + endTransactionName, e);
                } finally {
                    context.isDestroying = true;
                }
                // Unlocks device if any
                // WARNING: removing the device pool MUST BE DONE AFTER the end transaction!!!
                String connectorQName = connector.getQName();
                DevicePool devicePool = getDevicePool(connectorQName);
                if (devicePool != null) {
                    long contextNum = (Long.valueOf(Integer.toString(context.contextNum, 10))).longValue();
                    Engine.logContextManager.trace("DevicePool for '" + connectorQName + "' exist: unlocking device for context number " + contextNum + ".");
                    devicePool.unlockDevice(contextNum);
                }
                Engine.logContextManager.trace("Releasing " + connector.getName() + " connector (" + connector.getClass().getName() + ") for context id " + context.contextID);
                Engine.execute(new Runnable() {

                    public void run() {
                        connector.release();
                    }
                });
            }
        }
        context.clearConnectors();
        // Set TwsCachedXPathAPI to null
        context.cleanXpathApi();
        Engine.theApp.sessionManager.removeSession(contextID);
        String projectName = (String) context.projectName;
        /* Fix: #1754 - Slower transaction execution with many session */
        // HTTP session maintain its own context list in order to
        // improve context removal on session unbound process
        // See also #4198 which fix a regression
        String sessionID = context.httpSession != null ? context.httpSession.getId() : context.contextID.substring(0, context.contextID.indexOf("_"));
        HttpSession httpSession = HttpSessionListener.getHttpSession(sessionID);
        if (httpSession != null) {
            synchronized (httpSession) {
                try {
                    List<Context> contextList = GenericUtils.cast(SessionAttribute.contexts.get(httpSession));
                    if ((contextList != null) && contextList.contains(context)) {
                        contextList.remove(context);
                        Engine.logContextManager.debug("(ContextManager) context " + contextID + " has been removed from http session's context list");
                    }
                } catch (Exception e) {
                // Ignore: HTTP session may have already been invalidated
                }
            }
        }
        Engine.logContextManager.debug("Context " + contextID + " has been removed");
        Engine.logContext.debug("[" + contextID + "] Context removed, project: " + projectName);
        Engine.logContextManager.info("Current in-use contexts: " + contexts.size());
        Engine.logUsageMonitor.info("[Contexts] Current in-use contexts: " + contexts.size());
    } catch (Exception e) {
        Engine.logContextManager.warn("Failed to remove the context " + context.contextID, e);
    }
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) HttpSession(javax.servlet.http.HttpSession) DevicePool(com.twinsoft.util.DevicePool) DefaultRequester(com.twinsoft.convertigo.engine.requesters.DefaultRequester)

Example 3 with DevicePool

use of com.twinsoft.util.DevicePool in project convertigo by convertigo.

the class JavelinConnector method analyzeServiceCode.

public String analyzeServiceCode(String javelinServiceCode) {
    if (javelinServiceCode != null) {
        if (javelinServiceCode.indexOf("<POOL:") != 0) {
            int iStart = 0, iStop = 100, iIncr = 1, iDigits = 2;
            String connectorQName, sDevice;
            try {
                RE re = new RE("<POOL:([0-9]+)-([0-9]+)/([0-9]+)>");
                if (re.match(javelinServiceCode)) {
                    if (re.getParenCount() == 4) {
                        iStart = Integer.valueOf(re.getParen(1)).intValue();
                        iStop = Integer.valueOf(re.getParen(2)).intValue();
                        iDigits = Integer.valueOf(re.getParen(3)).intValue();
                    }
                }
            } catch (Exception e) {
            // ignore
            }
            connectorQName = getQName();
            DevicePool devicePool = Engine.theApp.contextManager.getDevicePool(connectorQName, iStart, iStop, iIncr, iDigits);
            if (devicePool != null) {
                synchronized (devicePool) {
                    Engine.logBeans.trace("(JavelinConnector) DevicePool for '" + connectorQName + "':\n" + devicePool.toString());
                    // retrieve device for the context,
                    // or available one if no device is associated with this context
                    long contextNum = ((context == null) ? 1L : (long) context.contextNum);
                    deviceID = devicePool.getDevice(contextNum);
                    sDevice = devicePool.formatDevice(deviceID);
                    // locks device
                    Engine.logBeans.trace("(JavelinConnector) DevicePool for '" + connectorQName + "' exist: locking deviceID " + deviceID + " for context number " + contextNum);
                    devicePool.lockContextDevice(deviceID, contextNum);
                    // rewrite service code
                    try {
                        RE re = new RE("<POOL:([0-9]+)-([0-9]+)/([0-9]+)>");
                        String sr = re.subst(javelinServiceCode, sDevice);
                        javelinServiceCode = sr;
                        Engine.logBeans.trace("(JavelinConnector) Overrides service code: " + javelinServiceCode);
                    } catch (RESyntaxException e1) {
                    // ignore
                    }
                }
            }
        }
    }
    return javelinServiceCode;
}
Also used : RE(org.apache.regexp.RE) FindString(com.twinsoft.convertigo.beans.common.FindString) DevicePool(com.twinsoft.util.DevicePool) RESyntaxException(org.apache.regexp.RESyntaxException) RESyntaxException(org.apache.regexp.RESyntaxException) NoSuchElementException(java.util.NoSuchElementException) EvaluatorException(org.mozilla.javascript.EvaluatorException) JavaScriptException(org.mozilla.javascript.JavaScriptException) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Aggregations

DevicePool (com.twinsoft.util.DevicePool)3 FindString (com.twinsoft.convertigo.beans.common.FindString)1 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)1 Connector (com.twinsoft.convertigo.beans.core.Connector)1 EngineException (com.twinsoft.convertigo.engine.EngineException)1 DefaultRequester (com.twinsoft.convertigo.engine.requesters.DefaultRequester)1 IOException (java.io.IOException)1 NoSuchElementException (java.util.NoSuchElementException)1 HttpSession (javax.servlet.http.HttpSession)1 RE (org.apache.regexp.RE)1 RESyntaxException (org.apache.regexp.RESyntaxException)1 EvaluatorException (org.mozilla.javascript.EvaluatorException)1 JavaScriptException (org.mozilla.javascript.JavaScriptException)1