@Override public BTreeFindPositionOperation bopFindPosition(String key, BTreeFindPosition get, OperationCallback cb) { return new BTreeFindPositionOperationImpl(key, get, cb); }
public BTreeFindPositionOperationImpl(String key, BTreeFindPosition get, OperationCallback cb) { super(cb); this.key = key; this.get = get; setAPIType(APIType.BOP_POSITION); setOperationType(OperationType.READ); }
@Override public void handleLine(String line) { if (getLogger().isDebugEnabled()) { getLogger().debug("Got line %s", line); } Integer position = null; if (line.startsWith("POSITION=")) { String[] stuff = line.split("="); assert stuff.length == 2; assert "POSITION".equals(stuff[0]); // FIXME exception-based conversion. try { // expected : POSITION=<position> : 0 or positive integer position = Integer.parseInt(stuff[1]); BTreeFindPositionOperation.Callback cb = (BTreeFindPositionOperation.Callback) getCallback(); cb.gotData(position); getCallback().receivedStatus(POSITION); } catch (Exception e) { // expected : <error_string> } } else { OperationStatus status = matchStatus(line, NOT_FOUND, UNREADABLE, BKEY_MISMATCH, TYPE_MISMATCH, NOT_FOUND_ELEMENT); if (getLogger().isDebugEnabled()) { getLogger().debug(status); } getCallback().receivedStatus(status); } transitionState(OperationState.COMPLETE); }
@Override public void initialize() { String cmd = get.getCommand(); String args = get.stringify(); ByteBuffer bb = ByteBuffer.allocate(KeyUtil.getKeyBytes(key).length + cmd.length() + args.length() + 16); setArguments(bb, cmd, key, args); bb.flip(); setBuffer(bb); if (getLogger().isDebugEnabled()) { getLogger().debug( "Request in ascii protocol: " + (new String(bb.array())) .replace("\r\n", "\\r\\n")); } }
@Override protected void wasCancelled() { getCallback().receivedStatus(GET_CANCELED); }