Package org.apache.stanbol.commons.jobs.api

Examples of org.apache.stanbol.commons.jobs.api.JobResult


                    try {
                        //log.debug("Process " + Integer.toString(num) + " is working");
                        Thread.sleep(jst);
                    } catch (InterruptedException ie) {}
                }
                JobResult r = new JobResult(){

                    @Override
                    public String getMessage() {
                        return "This is process " + Integer.toString(num);
                    }
View Full Code Here


                     */
                    Object o;
                    try {
                        o = f.get();
                        if(o instanceof JobResult){
                            JobResult result = (JobResult) o;
                            return Response.ok(result.getMessage()).build();
                        }else{
                            log.error("Job {} is not a test job", jid);
                            throw new WebApplicationException(Response.Status.NOT_FOUND);
                        }
                    } catch (InterruptedException e) {
                        log.error("Error: ",e);
                        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
                    } catch (ExecutionException e) {
                        log.error("Error: ",e);
                        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
                    }
                   
                }else{
                    /**
                     * We return 404 with additional info (Content-Location, the related job resource)
                     *
                     * TODO
                     * Change into json representations
                     */
                    String location = getPublicBaseUri() + "jobs/" + jid;
                    String info = new StringBuilder().append("Result not ready.\n").append("Job Location: ").append(location).toString();
                    return Response.status(404).header("Content-Location", location).header("Content-type","text/plain").entity(info).build();
                }
            }else {
                log.info("No job found with id {}", jid);
                return Response.status(Response.Status.NOT_FOUND).build();
            }
        }else{
            // No id have been provided, we create a new test job
            JobManager m = getJobManager();
            String id = m.execute(new Job() {
                @Override
                public JobResult call() throws Exception {
                    for (int i = 0; i < 30; i++) {
                        try {
                            log.info("Test Process is working");
                            Thread.sleep(1000);
                        } catch (InterruptedException ie) {}
                    }
                    return new JobResult(){
   
                        @Override
                        public String getMessage() {
                            return "This is a test job";
                        }
View Full Code Here

                    try {
                        //log.debug("Process " + Integer.toString(num) + " is working");
                        Thread.sleep(jst);
                    } catch (InterruptedException ie) {}
                }
                JobResult r = new JobResult(){

                    @Override
                    public String getMessage() {
                        return "This is process " + Integer.toString(num);
                    }
View Full Code Here

                     */
                    Object o;
                    try {
                        o = f.get();
                        if(o instanceof JobResult){
                            JobResult result = (JobResult) o;
                            return Response.ok(result.getMessage()).build();
                        }else{
                            log.error("Job {} is not a test job", jid);
                            throw new WebApplicationException(Response.Status.NOT_FOUND);
                        }
                    } catch (InterruptedException e) {
                        log.error("Error: ",e);
                        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
                    } catch (ExecutionException e) {
                        log.error("Error: ",e);
                        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
                    }
                   
                }else{
                    /**
                     * We return 404 with additional info (Content-Location, the related job resource)
                     *
                     * TODO
                     * Change into json representations
                     */
                    String location = getPublicBaseUri() + "jobs/" + jid;
                    String info = new StringBuilder().append("Result not ready.\n").append("Job Location: ").append(location).toString();
                    return Response.status(404).header("Content-Location", location).header("Content-type","text/plain").entity(info).build();
                }
            }else {
                log.info("No job found with id {}", jid);
                return Response.status(Response.Status.NOT_FOUND).build();
            }
        }else{
            // No id have been provided, we create a new test job
            JobManager m = getJobManager();
            String id = m.execute(new Job() {
                @Override
                public JobResult call() throws Exception {
                    for (int i = 0; i < 30; i++) {
                        try {
                            log.info("Test Process is working");
                            Thread.sleep(1000);
                        } catch (InterruptedException ie) {}
                    }
                    return new JobResult(){
   
                        @Override
                        public String getMessage() {
                            return "This is a test job";
                        }
View Full Code Here

TOP

Related Classes of org.apache.stanbol.commons.jobs.api.JobResult

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.