private Value getArgument(Request request, String parameter) { if (parameter.length()<=1 || parameter.charAt(1)!=':') return new StringValue(parameter); String value=parameter.substring(2); switch (parameter.charAt(0)) { case 'b': return new Int8Value(Byte.parseByte(value)); case 'h': return new Int16Value(Short.parseShort(value)); case 'i': return new Int32Value(Integer.parseInt(value)); case 'l': return new Int64Value(Long.parseLong(value)); case 'f': return new FloatValue(Float.parseFloat(value)); case 'd': return new DoubleValue(Double.parseDouble(value)); case 's': return new StringValue(value); } throw new IllegalArgumentException("The first letter in '" + parameter + "' must be a type argument. " + "There is no jrt type identified by '" + parameter.charAt(0) + "'"); }
public void RPC_update(Request req) { try { GrowableByteBuffer buffer = new GrowableByteBuffer(ByteBuffer.wrap(req.parameters().get(3).asData())); DocumentUpdate update = new DocumentUpdate(DocumentDeserializerFactory.createHead(docTypeManager, buffer)); UpdateResult result = provider.update(getBucket(req, 0), req.parameters().get(2).asInt64(), update); addResult(result, req); req.returnValues().add(new Int64Value(result.getExistingTimestamp())); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
void receive(FileReference reference, String filename, byte[] content) { log.log(LogLevel.INFO, "Preparing receive call for " + reference.value() + " and file " + filename); XXHash64 hasher = XXHashFactory.fastestInstance().hash64(); Request fileBlob = new Request("filedistribution.receiveFile"); log.log(LogLevel.INFO, "Calling " + fileBlob.methodName() + " with target " + target); fileBlob.parameters().add(new StringValue(reference.value())); fileBlob.parameters().add(new StringValue(filename)); fileBlob.parameters().add(new DataValue(content)); fileBlob.parameters().add(new Int64Value(hasher.hash(ByteBuffer.wrap(content), 0))); fileBlob.parameters().add(new Int32Value(0)); fileBlob.parameters().add(new StringValue("OK")); log.log(LogLevel.INFO, "Doing invokeSync"); target.invokeSync(fileBlob, 5); log.log(LogLevel.INFO, "Done with invokeSync"); } }
req.returnValues().add(new Int64Value(result.getIteratorId())); } catch (ParseException e) { addResult(new Result(Result.ErrorType.PERMANENT_ERROR, "Unparseable document selection expression"), req); req.returnValues().add(new Int64Value(0)); } catch (Exception e) { e.printStackTrace();
/** * Decode a value from the given buffer. This method also acts as * a factory for value objects * * @return the decoded value * @param type value type identifier * @param src where the value is stored * @throws IllegalArgumentException if the given type identifier is illegal **/ static Value decode(byte type, ByteBuffer src) { switch (type) { case INT8: return new Int8Value(src); case INT8_ARRAY: return new Int8Array(src); case INT16: return new Int16Value(src); case INT16_ARRAY: return new Int16Array(src); case INT32: return new Int32Value(src); case INT32_ARRAY: return new Int32Array(src); case INT64: return new Int64Value(src); case INT64_ARRAY: return new Int64Array(src); case FLOAT: return new FloatValue(src); case FLOAT_ARRAY: return new FloatArray(src); case DOUBLE: return new DoubleValue(src); case DOUBLE_ARRAY: return new DoubleArray(src); case STRING: return new StringValue(src); case STRING_ARRAY: return new StringArray(src); case DATA: return new DataValue(src); case DATA_ARRAY: return new DataArray(src); } throw new IllegalArgumentException(); }
public void RPC_get(Request req) { GetResult result = provider.get(getBucket(req, 0), getFieldSet(req, 2), new DocumentId(req.parameters().get(3).asString())); addResult(result, req); req.returnValues().add(new Int64Value(result.getLastModifiedTimestamp())); req.returnValues().add(new DataValue(serializeDocument(result.getDocument()))); }
@Override protected Request encodeRequest(Version version, Route route, RPCServiceAddress address, Message msg, long timeRemaining, byte[] payload, int traceLevel) { Request req = new Request(METHOD_NAME); Values v = req.parameters(); v.add(new StringValue(version.toString())); v.add(new StringValue(route.toString())); v.add(new StringValue(address.getSessionName())); v.add(new Int8Value(msg.getRetryEnabled() ? (byte)1 : (byte)0)); v.add(new Int32Value(msg.getRetry())); v.add(new Int64Value(timeRemaining)); v.add(new StringValue(msg.getProtocol())); v.add(new DataValue(payload)); v.add(new Int32Value(traceLevel)); return req; }