Skip to main content

Processor interface

DirPoll.Processor is the byte-in / byte-out interface. DirPoll reads the request file, hands you the raw bytes, and writes whatever you return to the response/ directory. You never touch the filesystem directly.

Interface

publicinterfaceProcessor{
byte[]process(String name,byte[] request)
throwsDirPoll.DirPollException;
}
ParameterDescription
nameThe request file name, e.g. "order-123.req"
requestRaw contents of the request file
returnBytes to write to response/ — return null to suppress the response file

If processing fails, throw a DirPollException. The file moves to bad/. If the error is transient, set retry = true on the exception and DirPoll will move the file back to request/ after a back-off delay.

EchoProcessor

The tutorial ships a minimal EchoProcessor that echoes the file content back as a response:

publicclassEchoProcessorimplementsDirPoll.Processor{

@Override
publicbyte[]process(String name,byte[] request)
throwsDirPoll.DirPollException{
String content =newString(request,StandardCharsets.UTF_8).trim();
String response ="ECHO ["+ name +"]: "+ content +System.lineSeparator();
return response.getBytes(StandardCharsets.UTF_8);
}
}

Try it

Build and install, then start Q2:

./gradlew :tutorials:dirpoll:installApp
./tutorials/dirpoll/bin/q2

In another terminal, drop a file into the request directory:

echo"hello world"> tutorials/dirpoll/build/install/dirpoll/dirpoll/request/test.req

After one poll interval (1 second by default) you will see a matching file in dirpoll/response/:

ECHO [test.req]: hello world

The original request file is moved to dirpoll/archive/ (because archive=true in the deploy descriptor).

Response file naming

By default the response file keeps the same name as the request. You can change the suffix via the response.suffix property:

<propertyname="response.suffix"value=".resp"/>

With that setting a request named order-123.req produces a response named order-123.resp.

Returning null

Returning null from process() is valid and means "no response needed". DirPoll skips writing to response/ entirely. Use this for fire-and-forget requests where the caller does not poll for a response.

AltStyle によって変換されたページ (->オリジナル) /