private void rpc_fetchIncremental(Request req) { int gencnt = req.parameters().get(0).asInt32(); int timeout = req.parameters().get(1).asInt32(); // for now, always make "full diff" from generation 0 req.returnValues().add(new Int32Value(0)); req.returnValues().add(new StringArray(new String[0])); if (gencnt == this.gencnt) { pendingFetch.add(new FetchMirror(req, timeout)); } else { dumpServices(req); } }
/** * Check whether the values stored in this object satisfies the * given type string. * * @return true if this value sequence satisfies 'types' * @param types type string **/ public boolean satisfies(String types) { int off = 0; int len = Math.min(types.length(), size()); while (off < len && types.charAt(off) == get(off).type()) { off++; } return ((off == types.length() && off == size()) || (off + 1 == types.length() && types.charAt(off) == '*')); }
/** * Create a new empty set of parameters for this request. The old * set of parameters will still be valid, but will no longer be * part of this request. This method may be used to allow earlier * garbage collection of large parameters that are no longer * needed. While the obvious use of this method is to get rid of * parameters when being an RPC server it can also be used after * starting an RPC request on a client. **/ public void discardParameters() { parameters = new Values(); }
/** * Determine the number of bytes needed to store this value * sequence when encoded into a buffer * * @return number of bytes needed for encoding this value sequence **/ int bytes() { int bytes = 4 + values.size(); for (int i = 0; i < values.size(); i++) { bytes += get(i).bytes(); } return bytes; }
private void dumpServices(Request req) { List<String> names = new ArrayList<>(); List<String> specs = new ArrayList<>(); for (Map.Entry<String,String> entry : services.entrySet()) { names.add(entry.getKey()); specs.add(entry.getValue()); } req.returnValues().add(new StringArray(names.toArray(new String[names.size()]))); req.returnValues().add(new StringArray(specs.toArray(new String[specs.size()]))); req.returnValues().add(new Int32Value(gencnt)); }
private void handleUpdate() { if (req.errorCode() == ErrorCode.NONE && req.returnValues().satisfies("SSi") && req.returnValues().get(0).count() == req.returnValues().get(1).count()) if (specsGeneration != answer.get(2).asInt32()) { int numNames = answer.get(0).count(); String[] n = answer.get(0).asStringArray(); String[] s = answer.get(1).asStringArray(); Entry[] newSpecs = new Entry[numNames]; specsGeneration = answer.get(2).asInt32(); int u = (updates + 1); if (u == 0) { || (req.returnValues().get(2).count() != req.returnValues().get(3).count())) int diffFromGeneration = answer.get(0).asInt32(); int diffToGeneration = answer.get(4).asInt32(); if (specsGeneration != diffToGeneration) { int nRemoves = answer.get(1).count(); String[] r = answer.get(1).asStringArray(); int numNames = answer.get(2).count(); String[] n = answer.get(2).asStringArray(); String[] s = answer.get(3).asStringArray();
@Override public String toString() { return "request " + methodName + "(" + parameters + ")" + ( returnValues.size()>0 ? ": " + returnValues : ""); }
public int bytes() { return (headerLength + returnValues.bytes()); }
/** * Create a sequence of values by decoding them from the given * buffer * * @param src buffer containing a contained value sequence **/ Values(ByteBuffer src) { decode(src); }
/** * Encode this value sequence into the given buffer * * @param dst where to encode this value sequence **/ void encode(ByteBuffer dst) { byte[] types = new byte[values.size()]; for (int i = 0; i < types.length; i++) { types[i] = get(i).type(); } dst.putInt(types.length); dst.put(types); for (int i = 0; i < types.length; i++) { get(i).encode(dst); } }
private synchronized void handleRpcList(Request req) { Values dst = req.returnValues(); dst.add(new StringArray(names.toArray(new String[names.size()]))); }
private boolean validateResponse(Request request) { if (request.isError()) { return false; } else if (request.returnValues().size() == 0) { return false; } else if (!request.checkReturnTypes("is")) { // TODO: Do not hard-code return type log.log(LogLevel.WARNING, "Invalid return types for response: " + request.errorMessage()); return false; } return true; }
public int bytes() { return (headerLength + methodName.bytes() + parameters.bytes()); }
@SuppressWarnings({"UnusedDeclaration"}) public final void setFileReferencesToDownload(Request req) { log.log(LogLevel.DEBUG, () -> "Received method call '" + req.methodName() + "' with parameters : " + req.parameters()); Arrays.stream(req.parameters().get(0).asStringArray()) .map(FileReference::new) .forEach(fileReference -> downloader.downloadIfNeeded(new FileReferenceDownload(fileReference))); req.returnValues().add(new Int32Value(0)); }
protected Params toParams(Values args) { Params p = new Params(); p.version = new Version(args.get(0).asUtf8Array()); p.route = args.get(1).asString(); p.session = args.get(2).asString(); p.retryEnabled = (args.get(3).asInt8() != 0); p.retry = args.get(4).asInt32(); p.timeRemaining = args.get(5).asInt64(); p.protocolName = args.get(6).asUtf8Array(); p.payload = args.get(7).asData(); p.traceLevel = args.get(8).asInt32(); return p; }
@SuppressWarnings({"UnusedDeclaration"}) public final void getActiveFileReferencesStatus(Request req) { Map<FileReference, Double> downloadStatus = downloader.downloadStatus(); String[] fileRefArray = new String[downloadStatus.keySet().size()]; fileRefArray = downloadStatus.keySet().stream() .map(FileReference::value) .collect(Collectors.toList()) .toArray(fileRefArray); double[] downloadStatusArray = new double[downloadStatus.values().size()]; int i = 0; for (Double d : downloadStatus.values()) { downloadStatusArray[i++] = d; } req.returnValues().add(new StringArray(fileRefArray)); req.returnValues().add(new DoubleArray(downloadStatusArray)); }
@Override public void handleRequestDone(Request requestWithResponse) { if (requestWithResponse.isError()) { handler.receive(GetDocsumsResponseOrError.fromError("Error response from " + node + ": " + requestWithResponse.errorMessage())); return; } Values returnValues = requestWithResponse.returnValues(); if (returnValues.size() < 3) { handler.receive(GetDocsumsResponseOrError.fromError("Invalid getDocsums response from " + node + ": Expected 3 return arguments, got " + returnValues.size())); return; } byte compression = returnValues.get(0).asInt8(); int uncompressedSize = returnValues.get(1).asInt32(); byte[] compressedSlimeBytes = returnValues.get(2).asData(); List<FastHit> hits = (List<FastHit>) requestWithResponse.getContext(); handler.receive(GetDocsumsResponseOrError.fromResponse(new GetDocsumsResponse(compression, uncompressedSize, compressedSlimeBytes, hits))); }
/** * Create a new Request with the given method name. * * @param methodName name of the method you want to invoke **/ public Request(String methodName) { this(methodName, new Values()); }
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); } }
private void handleRpcUnreg(Request req) { log.log(Level.WARNING, "unregistered name " + req.parameters().get(0).asString()); }