Search in sources :

Example 1 with Chronometer

use of org.jpos.util.Chronometer in project jPOS by jpos.

the class QueryHost method prepare.

public int prepare(long id, Serializable ser) {
    Context ctx = (Context) ser;
    Result result = ctx.getResult();
    String ds = ctx.getString(destination);
    if (ds == null) {
        return result.fail(CMF.MISCONFIGURED_ENDPOINT, Caller.info(), "'%s' not present in Context", destination).FAIL();
    }
    String muxName = cfg.get("mux." + ds, "mux." + ds);
    MUX mux = (MUX) NameRegistrar.getIfExists(muxName);
    if (mux == null)
        return result.fail(CMF.MISCONFIGURED_ENDPOINT, Caller.info(), "MUX '%s' not found", muxName).FAIL();
    ISOMsg m = (ISOMsg) ctx.get(requestName);
    if (m == null)
        return result.fail(CMF.INVALID_REQUEST, Caller.info(), "'%s' is null", requestName).FAIL();
    Chronometer chronometer = new Chronometer();
    if (isConnected(mux)) {
        // give at least a second to catch a response
        long t = Math.max(timeout - chronometer.elapsed(), 1000L);
        try {
            if (continuations) {
                mux.request(m, t, this, ctx);
                return PREPARED | READONLY | PAUSE | NO_JOIN;
            } else {
                ISOMsg resp = mux.request(m, t);
                if (resp != null) {
                    ctx.put(responseName, resp);
                    return PREPARED | READONLY | NO_JOIN;
                } else {
                    return result.fail(CMF.HOST_UNREACHABLE, Caller.info(), "'%s' does not respond", muxName).FAIL();
                }
            }
        } catch (ISOException e) {
            return result.fail(CMF.SYSTEM_ERROR, Caller.info(), e.getMessage()).FAIL();
        }
    } else {
        return result.fail(CMF.HOST_UNREACHABLE, Caller.info(), "'%s' is not connected", muxName).FAIL();
    }
}
Also used : Context(org.jpos.transaction.Context) Chronometer(org.jpos.util.Chronometer) Result(org.jpos.rc.Result)

Aggregations

Result (org.jpos.rc.Result)1 Context (org.jpos.transaction.Context)1 Chronometer (org.jpos.util.Chronometer)1