Search in sources :

Example 1 with HTTPRequestReader

use of com.ociweb.gl.api.HTTPRequestReader in project GreenLightning by oci-pronghorn.

the class AllRoutesExample2 method declareBehavior.

@Override
public void declareBehavior(GreenRuntime runtime) {
    final GreenCommandChannel cmd = runtime.newCommandChannel(NET_RESPONDER);
    RestListener listener = new RestListener() {

        @Override
        public boolean restRequest(HTTPRequestReader request) {
            // TODO: this route is the wrong value
            int id = request.getRouteId();
            System.out.println(id);
            return cmd.publishHTTPResponse(request, 200);
        }
    };
    runtime.addRestListener(listener).includeAllRoutes();
}
Also used : RestListener(com.ociweb.gl.api.RestListener) HTTPRequestReader(com.ociweb.gl.api.HTTPRequestReader) GreenCommandChannel(com.ociweb.gl.api.GreenCommandChannel)

Example 2 with HTTPRequestReader

use of com.ociweb.gl.api.HTTPRequestReader in project GreenLightning by oci-pronghorn.

the class ReactiveListenerStage method consumeRestRequest.

final void consumeRestRequest(Object listener, Pipe<HTTPRequestSchema> p) {
    while (Pipe.hasContentToRead(p)) {
        Pipe.markTail(p);
        int msgIdx = Pipe.takeMsgIdx(p);
        if (HTTPRequestSchema.MSG_RESTREQUEST_300 == msgIdx) {
            long connectionId = Pipe.takeLong(p);
            final int sequenceNo = Pipe.takeInt(p);
            int routeVerb = Pipe.takeInt(p);
            int pathId = routeVerb >>> HTTPVerb.BITS;
            int verbId = HTTPVerb.MASK & routeVerb;
            HTTPRequestReader reader = (HTTPRequestReader) Pipe.openInputStream(p);
            // logger.trace("route path selected {}",pathId);
            reader.setParseDetails(builder.httpSpec, builder.routerConfig());
            int parallelRevision = Pipe.takeInt(p);
            int parallelIdx = parallelRevision >>> HTTPRevision.BITS;
            int revision = HTTPRevision.MASK & parallelRevision;
            reader.setRevisionId(revision);
            reader.setRequestContext(Pipe.takeInt(p));
            reader.setRouteId(pathId);
            // both these values are required in order to ensure the right sequence order once processed.
            long sequenceCode = (((long) parallelIdx) << 32) | ((long) sequenceNo);
            // System.err.println("Reader is given seuqence code of "+sequenceNo);
            reader.setConnectionId(connectionId, sequenceCode);
            // assign verbs as strings...
            reader.setVerb((HTTPVerbDefaults) httpSpec.verbs[verbId]);
            if (null != restRequestReader && pathId < restRequestReader.length && null != restRequestReader[pathId]) {
                if (!restRequestReader[pathId].restRequest(listener, reader)) {
                    Pipe.resetTail(p);
                    // continue later and repeat this same value.
                    return;
                }
            } else {
                if (listener instanceof RestListener) {
                    if (!((RestListener) listener).restRequest(reader)) {
                        Pipe.resetTail(p);
                        // continue later and repeat this same value.
                        return;
                    }
                }
            }
        } else {
            logger.error("unrecognized message on {} ", p);
            throw new UnsupportedOperationException("unexpected message " + msgIdx);
        }
        Pipe.confirmLowLevelRead(p, Pipe.sizeOf(p, msgIdx));
        Pipe.releaseReadLock(p);
    }
}
Also used : RestListener(com.ociweb.gl.api.RestListener) HTTPRequestReader(com.ociweb.gl.api.HTTPRequestReader)

Aggregations

HTTPRequestReader (com.ociweb.gl.api.HTTPRequestReader)2 RestListener (com.ociweb.gl.api.RestListener)2 GreenCommandChannel (com.ociweb.gl.api.GreenCommandChannel)1