Package org.syrup

Examples of org.syrup.PTask


    {

        XMLOutput o = new XMLOutput();
        SerializationHandler h = o.wrap(out);

        PTask p[] = sp.match(template);

        // Outputs the fetched PTasks to the OutputStream in XML format.
        o.startDocument("match", h);

        for (int i = 0; i < p.length; i++)
View Full Code Here


        try
        {
            while (totalIterations > 0
                || totalIterations < 0)
            {
                PTask p[] = sp.match(template);

                int k = 1;
                int i = 0;
                int executionRuns = 0;

                // Go through all matching PTasks sequentially.
                while (i < p.length)
                {
                    logger.log(Level.INFO, "starting "
                        + p[i], p[i]);

                    PTask p2 = null;
                    int ii = 0;

                    // Retry execution (5 times) upon failure.
                    while (ii++ < 5)
                    {
                        try
                        {
                            p2 = sp.execute(p[i]);
                            executionRuns++;
                            break;
                        }
                        catch (InterruptedException ie)
                        {
                            throw ie;
                        }
                        catch (Exception e)
                        {
                            logger.log(Level.INFO, "execution failed "
                                + p[i], e);
                        }

                        // This block is only entered when execution fails.
                        try
                        {
                            sp.stop(new PTaskTemplateImpl(new String[]
                            {
                                "stop", "-key=equal", " "
                                    + p[i]
                            }));
                        }
                        catch (Exception e)
                        {
                            logger.log(Level.INFO, "stopping failed "
                                + p[i], e);
                        }
                        logger.log(Level.INFO, "... retrying execution "
                            + p[i]);
                    }

                    // Indicates that execution has failed 5 times
                    if (p2 == null)
                    {
                        // Bail out to top level caller.
                        throw new Exception("execution cannot continue - exhausted all retries");
                    }
                    // Indicates that the execution was succesful.
                    if (p2 != p[i])
                    {
                        logger.log(Level.INFO, "executed "
                            + p2, p2);
                    }
                    // Indicates that the execution was not succesful.
                    else
                    {
                        logger.log(Level.INFO, "dropped "
                            + p2, p2);
                    }
                    // Indicates that the PTask was already taken by another
                    // Worker.
                    if (p[i].modifications() == p2.modifications())
                    {
                        // Increase the step taken through the fetched list.
                        // This will lower the chance of hitting a PTask
                        // that has been taken by another Worker.
                        k += 1;
View Full Code Here

    private static int stop(WorkSpace sp, PTaskTemplate template)
        throws Exception
    {
        int stopped = 0;

        PTask p[] = sp.match(template);

        // Stops the matching PTasks sequentially and one by one.
        for (int i = 0; i < p.length; i++)
        {
            PTask pp = sp.stop(p[i]);
            if (pp != p[i])
            {
                logger.log(Level.INFO, "stopped "
                    + pp);
                stopped++;
View Full Code Here

     * @return An array of PTasks that match the PTaskTemplate.
     */
    public PTask[] match(PTaskTemplate template, SyrupConnection con)
        throws Exception
    {
        PTask p[] = new PTask[0];
        String qq = null;

        List qParts = new LinkedList();

        // Add all the qualifiers, mapping from PTaskTemplate attributes to SQL
        // attributes.
        qParts.add(new QueryOperation(template, "description", "description"));
        qParts.add(new QueryOperation(template, "name", "name"));
        qParts.add(new QueryOperation(template, "function_class", "functionClass"));
        qParts.add(new QueryOperation(template, "environment", "environment"));
        qParts.add(new QueryOperation(template, "parameter", "parameter"));
        qParts.add(new QueryOperation(template, "or_type", "orType"));
        qParts.add(new QueryOperation(template, "parent_key", "parentKey"));
        qParts.add(new QueryOperation(template, "key_", "key"));
        qParts.add(new QueryOperation(template, "modifications", "modifications"));
        qParts.add(new QueryOperation(template, "modification_time", "modificationTime"));
        qParts.add(new QueryOperation(template, "creation_time", "creationTime"));
        qParts.add(new QueryOperation(template, "executable", "executable"));
        qParts.add(new QueryOperation(template, "done", "done"));
        qParts.add(new QueryOperation(template, "worker", "worker"));
        qParts.add(new QueryOperation(template, "is_parent", "isParent"));

        // Builds the SQL query.
        // [TODO: use an StringBuffer to speed up the concatenation of Strings].
        Iterator qIterator = qParts.iterator();
        while (qIterator.hasNext())
        {
            QueryOperation op = (QueryOperation) qIterator.next();
            if (op.sqlOp != null)
            {
                if (qq != null)
                {
                    qq = qq
                        + " and ";
                }
                else
                {
                    qq = " ";
                }
                qq = qq
                    + op.sqlAtt + " " + op.sqlOp + " ?";
            }
        }

        if (qq == null)
        {
            qq = sqlImpl().sqlStatements().selectTasksStatement();
        }
        else
        {
            qq = sqlImpl().sqlStatements().selectTasksStatement()
                + "where" + qq;
        }

        PreparedStatement ps = null;

    
            ps = con.prepareStatement(qq);
          
           
            qIterator = qParts.iterator();
            int ii = 1;

            while (qIterator.hasNext())
            {
                QueryOperation op = (QueryOperation) qIterator.next();

                // For each qualifier, the SQL value is set.
                if (op.sqlOp != null)
                {
                    ps.setObject(ii++, op.value);
                }
            }

            ResultSet result = null;
               
            try
            {  
            result = ps.executeQuery();

            // Build the result array
            // [TODO: Make this more efficient without the need of an extra
            // ArrayList object]
            ArrayList ptasks = new ArrayList();
            while (result.next())
            {
                PTask t = sqlImpl().queryFunctions().readPTask(result);
                ptasks.add(t);
            }

            p = new PTask[ptasks.size()];
            Object[] o = ptasks.toArray();
View Full Code Here

        EndPoint out_1 = readOutEndPoint(p.key(), false, con);
        EndPoint out_2 = readOutEndPoint(p.key(), true, con);

        // [TODO: check if it is necessary to read it again, or can we take the
        // given parameter p?]
        PTask self = readPTask(p.key(), con);

        return new ContextImpl(self, in_1, in_2, out_1, out_2);
    }
View Full Code Here

     *            The SyrupConnection over which SQL statements are executed.
     * @return The PTask, given an identifier.
     */
    protected PTask readPTask(String key, SyrupConnection con) throws Exception
    {
        PTask t = null;
        ResultSet r = null;
       
        if (key != null)
        {
            PreparedStatement s = null;
View Full Code Here

     *            The ResultSet that holds the PTask attributes.
     * @return The PTask held by a ResultSet.
     */
    protected PTask readPTask(ResultSet result) throws Exception
    {
        PTask ptask = new PTaskImpl(result.getString("parent_key"), result.getString("key_"),
            result.getBoolean("or_type"), result.getString("function_class"),
            result.getString("name"), result.getString("description"),
            result.getString("parameter"), result.getString("environment"), result.getBoolean("done"),
            result.getLong("creation_time"), result.getLong("modification_time"),
            result.getLong("modifications"), result.getBoolean("executable"),
View Full Code Here

        if (p != null)
        {
            if (p.task() instanceof PTask)
            {
                PTask t = (PTask) p.task();
                if (p.isSecond())
                {
                    a.addAttribute("", "", "lkey", "string", t.key()
                        + "-2");
                }
                else
                {
                    a.addAttribute("", "", "lkey", "string", t.key()
                        + "-1");
                }
                a.addAttribute("", "", "lparentKey", "string", t.parentKey());
                a.addAttribute("", "", "lname", "string", t.name());
            }
        }
        return a;
    }
View Full Code Here

TOP

Related Classes of org.syrup.PTask

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.