Search in sources :

Example 1 with ExpectedExceptionForDebug

use of water.util.Utils.ExpectedExceptionForDebug in project h2o-2 by h2oai.

the class Job method fork.

/**
   * Forks computation of this job.
   *
   * <p>The call does not block.</p>
   * @return always returns this job.
   */
public Job fork() {
    init();
    H2OCountedCompleter task = new H2OCountedCompleter() {

        @Override
        public void compute2() {
            try {
                try {
                    // Exec always waits till the end of computation
                    Job.this.exec();
                    Job.this.remove();
                } catch (Throwable t) {
                    if (!(t instanceof ExpectedExceptionForDebug))
                        Log.err(t);
                    Job.this.cancel(t);
                }
            } finally {
                tryComplete();
            }
        }
    };
    start(task);
    H2O.submitTask(task);
    return this;
}
Also used : ExpectedExceptionForDebug(water.util.Utils.ExpectedExceptionForDebug) H2OCountedCompleter(water.H2O.H2OCountedCompleter)

Example 2 with ExpectedExceptionForDebug

use of water.util.Utils.ExpectedExceptionForDebug in project h2o-2 by h2oai.

the class RequestServer method serve.

@Override
public NanoHTTPD.Response serve(String uri, String method, Properties header, Properties parms) {
    // Jack priority for user-visible requests
    Thread.currentThread().setPriority(Thread.MAX_PRIORITY - 1);
    // update arguments and determine control variables
    uri = maybeTransformRequest(uri);
    // determine the request type
    Request.RequestType type = Request.RequestType.requestType(uri);
    String requestName = type.requestName(uri);
    maybeLogRequest(uri, method, parms, header);
    // determine version
    int version = parseVersion(uri);
    int idx = version >> 16;
    version &= 0xFFFF;
    String uripath = uri.substring(idx);
    // Strip suffix type from middle of URI
    String path = requestName(uripath);
    Method meth = null;
    try {
        // Find handler for url
        meth = lookup(method, path);
        if (meth != null) {
            return wrap(HTTP_OK, handle(type, meth, version, parms), type);
        }
    } catch (IllegalArgumentException e) {
        return wrap(HTTP_BADREQUEST, new HTTP404V1(e.getMessage(), uri), type);
    } catch (Exception e) {
        // make sure that no Exception is ever thrown out from the request
        return wrap(e.getMessage() != "unimplemented" ? HTTP_INTERNALERROR : HTTP_NOTIMPLEMENTED, new HTTP500V1(e), type);
    }
    // Wasn't a new type of handler:
    try {
        // determine if we have known resource
        Request request = _requests.get(requestName);
        // found
        if (request == null)
            return getResource(uri);
        // Some requests create an instance per call
        request = request.create(parms);
        // call the request
        return request.serve(this, parms, type);
    } catch (Exception e) {
        if (!(e instanceof ExpectedExceptionForDebug))
            e.printStackTrace();
        // make sure that no Exception is ever thrown out from the request
        parms.setProperty(Request.ERROR, e.getClass().getSimpleName() + ": " + e.getMessage());
        return _http500.serve(this, parms, type);
    }
}
Also used : ExpectedExceptionForDebug(water.util.Utils.ExpectedExceptionForDebug) HTTP500V1(water.schemas.HTTP500V1) Method(java.lang.reflect.Method) IOException(java.io.IOException) HTTP404V1(water.schemas.HTTP404V1)

Aggregations

ExpectedExceptionForDebug (water.util.Utils.ExpectedExceptionForDebug)2 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 H2OCountedCompleter (water.H2O.H2OCountedCompleter)1 HTTP404V1 (water.schemas.HTTP404V1)1 HTTP500V1 (water.schemas.HTTP500V1)1