Package kr.or.ioi2002.RMIServer

Examples of kr.or.ioi2002.RMIServer.Job


    private void readResponse() throws AgentException, IOException {
        socket.setSoTimeout(getTimeoutForJobType(currentJob.getType()));
        String command = readLine();
        if (command == null)
            throw new AgentException("RESULT expected, but connection terminated; " + command);
        StringTokenizer tokenizer = new StringTokenizer(command, " ");
        try {
            if (!tokenizer.nextToken().equals("RESULT"))
                throw new AgentException("RESULT expected; " + command);
            assertHasMoreTokens(tokenizer, command);
            String expectedType = currentJob.getType().toString();
            if (JobType.FEEDBACK.equals(currentJob.getType())) {
                expectedType = "GRADE";
            }
            if (!tokenizer.nextToken().equals(expectedType))
                throw new AgentException(currentJob.getType() + " expected; " + command);
            assertHasMoreTokens(tokenizer, command);
            String result = tokenizer.nextToken();
            if (result.equals("OK") || result.equals("FAIL"))
                currentJob.result = result;
            else
                throw new AgentException("OK or FAIL expected;" + command);
            assertHasMoreTokens(tokenizer, command);
            currentJob.setTask(tokenizer.nextToken());
        } catch (NoSuchElementException e) {
            throw new AgentException("NoSuchElementException: error parsing RESULT");
        }
        currentJob.output = recvBytes();
    }
View Full Code Here


        currentJob.output = recvBytes();
    }

    private void assertHasMoreTokens(StringTokenizer t, String command) throws AgentException {
        if (!t.hasMoreTokens())
            throw new AgentException("invalid RESULT format from grading machine; " + command);
    }
View Full Code Here

        // recv grader_log
        currentJob.log = recvBytes();

        if (currentJob.getUserid() == null || currentJob.getTask() == null)
            throw new AgentException(
                    "!currentJob.userid == null || currentJob.task == null: doGrade");

        // store grader-generated files to the server
        // delete previous
        clearGradeResultFile(currentJob.getContestId(), currentJob.getUserid(), currentJob
                .getTask());

        // save csv and log as file
        TempFile tmpfilelog = TempFile.createFromByteArray(currentJob.log);
        saveGradeResultFile(currentJob.getContestId(),
                currentJob.getUserid(),
                currentJob.getTask(),
                tmpfilelog,
                currentJob.getTask() + ".grader.log");
        TempFile tmpfilecsv = TempFile.createFromByteArray(currentJob.output);
        saveGradeResultFile(currentJob.getContestId(),
                currentJob.getUserid(),
                currentJob.getTask(),
                tmpfilecsv,
                currentJob.getTask() + ".grader.csv");

        // retreive filelist and recv files
        byte[] abyFilelist = recvBytes();
        String strFilelist = new String(abyFilelist);
        StringTokenizer tFile = new StringTokenizer(strFilelist, "\n");
        try {
            String strFilename = null;
            while (tFile.hasMoreTokens() && !(strFilename = tFile.nextToken().trim()).equals("")) {
                TempFile tmpFile = recvFile();
                saveGradeResultFile(currentJob.getContestId(), currentJob.getUserid(), currentJob
                        .getTask(), tmpFile, strFilename);
            }
        } catch (NoSuchElementException e) {
            throw new AgentException("!NoSuchElementException: doGrade");
        }
    }
View Full Code Here

            // expect READY in 10 sec
            socket.setSoTimeout(10000);
            command = readLine();
            if (command.length() < 5)
                throw new AgentException("READY expected; " + command);
            if (!command.substring(0, 5).equals("READY"))
                throw new AgentException("READY expected; " + command);
            if (command.length() > 5) // version information available
            {
                agentVersion = command.substring(5).trim();
            }
            writeLine("ACK");
View Full Code Here

        byte[] bHeader = new byte[8];
        int toRead = 8;
        while (toRead > 0) {
            int iRead = is.read(bHeader, 8 - toRead, toRead);
            if (iRead < 0)
                throw new AgentException("closed during recvFile");
            toRead -= iRead;
        }
        DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bHeader));
        int keyvalue = dis.readInt();
        if (keyvalue != FILE_TRANSFER_INTEGRITY_KEY)
            throw new AgentException("recvFile: Wrong Integrity Key");
        int length = dis.readInt();
        dis.close();

        if (length > FILESIZE_LIMIT)
            throw new AgentException("recvFile: FILESIZE_LIMIT("
                    + String.valueOf(FILESIZE_LIMIT)
                    + ") exceeded, length="
                    + String.valueOf(length));

        return TempFile.createFromStream(is, length);
View Full Code Here

        byte[] bHeader = new byte[8];
        int toRead = 8;
        while (toRead > 0) {
            int iRead = is.read(bHeader, 8 - toRead, toRead);
            if (iRead < 0)
                throw new AgentException("closed during recvBytes");
            toRead -= iRead;
        }
        DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bHeader));
        int keyvalue = dis.readInt();
        if (keyvalue != FILE_TRANSFER_INTEGRITY_KEY)
            throw new AgentException("recvBytes: Wrong Integrity Key");
        int length = dis.readInt();
        dis.close();

        if (length < 0 || length > FILESIZE_LIMIT)
            throw new AgentException("recvBytes: FILESIZE_LIMIT("
                    + String.valueOf(FILESIZE_LIMIT)
                    + ") exceeded, length="
                    + String.valueOf(length));

        byte[] buffer = new byte[length];
View Full Code Here

        ByteArrayOutputStream baos = new ByteArrayOutputStream(80);
        int iRead = -1;
        do {
            iRead = is.read();
            if (iRead < 0)
                throw new AgentException("closed during readLine");
            baos.write(iRead);
        } while (iRead != '\n');
        return baos.toString().trim();
    }
View Full Code Here

        if (JobType.SUBMIT == currentJob.getType())
            return SUBMIT_PROCESS_TIMEOUT;
        if (JobType.TEST == currentJob.getType())
            return TEST_PROCESS_TIMEOUT;

        throw new AgentException("Invalid job type - not supported by this agent.");
    }
View Full Code Here

        if (currentJob.getType() != JobType.TEST) {
            if (task.getType() == Task.PROBLEM_TYPE_OUTPUT) {
                try {
                    protoBuilder.addTestIndexes(Integer.parseInt(currentJob.getTestIndex()));
                } catch (NumberFormatException e) {
                    throw new AgentException("Invalid test index.");
                }
            } else {
                Contest contest = extractContest();
                protoBuilder.addAllTestIndexes(task.getTestIndexesByJobType(currentJob.getType(),
                        !currentJob.isNotGradeFeedback(),
View Full Code Here

        // we will continue work with os, so do not close dataOutput.
    }

    private Task getTask() throws AgentException {
        if (currentJob == null) {
            throw new AgentException("No current job!");
        }
        Task task = contestManager.getTaskByName(currentJob.getContestId(), currentJob.getTask());
        if (task == null) {
            throw new AgentException("Cannot read task"
                    + currentJob.getTask()
                    + " in contest:"
                    + currentJob.getContestId());
        }
        return task;
View Full Code Here

TOP

Related Classes of kr.or.ioi2002.RMIServer.Job

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.