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 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) + "'"); }
@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)); }
private void handleFetchMirrorTimeout(FetchMirror fetch) { pendingFetch.remove(fetch); fetch.req.returnValues().add(new StringArray(new String[0])); fetch.req.returnValues().add(new StringArray(new String[0])); fetch.req.returnValues().add(new Int32Value(gencnt)); fetch.req.returnRequest(); }
public void RPC_getBucketInfo(Request req) { BucketInfoResult result = provider.getBucketInfo(getBucket(req, 0)); addResult(result, req); req.returnValues().add(new Int32Value(result.getBucketInfo().getChecksum())); req.returnValues().add(new Int32Value(result.getBucketInfo().getDocumentCount())); req.returnValues().add(new Int32Value(result.getBucketInfo().getDocumentSize())); req.returnValues().add(new Int32Value(result.getBucketInfo().getEntryCount())); req.returnValues().add(new Int32Value(result.getBucketInfo().getUsedSize())); req.returnValues().add(new Int8Value(result.getBucketInfo().isReady() ? (byte)1 : (byte)0)); req.returnValues().add(new Int8Value(result.getBucketInfo().isActive() ? (byte)1 : (byte)0)); }
@SuppressWarnings({"UnusedDeclaration"}) public final void receiveFileMeta(Request req) { log.log(LogLevel.DEBUG, () -> "Received method call '" + req.methodName() + "' with parameters : " + req.parameters()); FileReference reference = new FileReference(req.parameters().get(0).asString()); String fileName = req.parameters().get(1).asString(); String type = req.parameters().get(2).asString(); long fileSize = req.parameters().get(3).asInt64(); int sessionId = nextSessionId.getAndIncrement(); int retval = 0; synchronized (sessions) { if (sessions.containsKey(sessionId)) { retval = 1; log.severe("Session id " + sessionId + " already exist, impossible. Request from(" + req.target() + ")"); } else { try { sessions.put(sessionId, new Session(downloadDirectory, tmpDirectory, sessionId, reference, FileReferenceData.Type.valueOf(type),fileName, fileSize)); } catch (Exception e) { retval = 1; } } } req.returnValues().add(new Int32Value(retval)); req.returnValues().add(new Int32Value(sessionId)); }
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); } }
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.parameters().add(new Int32Value(specsGeneration)); // gencnt req.parameters().add(new Int32Value(5000)); // mstimeout target.invokeAsync(req, 40.0, reqWait);
@SuppressWarnings({"UnusedDeclaration"}) public final void receiveFilePart(Request req) { log.log(LogLevel.DEBUG, () -> "Received method call '" + req.methodName() + "' with parameters : " + req.parameters()); FileReference reference = new FileReference(req.parameters().get(0).asString()); int sessionId = req.parameters().get(1).asInt32(); int partId = req.parameters().get(2).asInt32(); byte [] part = req.parameters().get(3).asData(); Session session = getSession(sessionId); int retval = verifySession(session, sessionId, reference); try { session.addPart(partId, part); } catch (Exception e) { log.severe("Got exception " + e); retval = 1; } double completeness = (double) session.currentFileSize / (double) session.fileSize; log.log(LogLevel.DEBUG, () -> String.format("%.1f percent of '%s' downloaded", completeness * 100, reference.value())); downloader.setDownloadStatus(reference, completeness); req.returnValues().add(new Int32Value(retval)); }
@SuppressWarnings({"UnusedDeclaration"}) public final void receiveFileEof(Request req) { log.log(LogLevel.DEBUG, () -> "Received method call '" + req.methodName() + "' with parameters : " + req.parameters()); FileReference reference = new FileReference(req.parameters().get(0).asString()); int sessionId = req.parameters().get(1).asInt32(); long xxhash = req.parameters().get(2).asInt64(); Session session = getSession(sessionId); int retval = verifySession(session, sessionId, reference); File file = session.close(xxhash); downloader.completedDownloading(reference, file); synchronized (sessions) { sessions.remove(sessionId); } req.returnValues().add(new Int32Value(retval)); }
private boolean startDownloadRpc(FileReferenceDownload fileReferenceDownload, int retryCount) { Connection connection = connectionPool.getCurrent(); Request request = new Request("filedistribution.serveFile"); String fileReference = fileReferenceDownload.fileReference().value(); request.parameters().add(new StringValue(fileReference)); request.parameters().add(new Int32Value(fileReferenceDownload.downloadFromOtherSourceIfNotFound() ? 0 : 1)); execute(request, connection); Level logLevel = (retryCount > 0 ? LogLevel.INFO : LogLevel.DEBUG); if (validateResponse(request)) { log.log(logLevel, () -> "Request callback, OK. Req: " + request + "\nSpec: " + connection); if (request.returnValues().get(0).asInt32() == 0) { log.log(logLevel, () -> "Found file reference '" + fileReference + "' available at " + connection.getAddress()); return true; } else { log.log(logLevel, "File reference '" + fileReference + "' not found for " + connection.getAddress()); connectionPool.setNewCurrentConnection(); return false; } } else { log.log(logLevel, "Request failed. Req: " + request + "\nSpec: " + connection.getAddress() + ", error code: " + request.errorCode() + ", set error for connection and use another for next request"); connectionPool.setError(connection, request.errorCode()); return false; } }
@Override public void getDocsums(List<FastHit> hits, NodeConnection node, CompressionType compression, int uncompressedLength, byte[] compressedSlime, RpcFillInvoker.GetDocsumsResponseReceiver responseReceiver, double timeoutSeconds) { Request request = new Request("proton.getDocsums"); request.parameters().add(new Int8Value(compression.getCode())); request.parameters().add(new Int32Value(uncompressedLength)); request.parameters().add(new DataValue(compressedSlime)); request.setContext(hits); RpcNodeConnection rpcNode = ((RpcNodeConnection) node); rpcNode.invokeAsync(request, timeoutSeconds, new RpcResponseWaiter(rpcNode, responseReceiver)); }
@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; }
/** * 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(); }
@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 Int8Value(CompressionType.NONE.getCode())); v.add(new Int32Value(0)); v.add(new DataValue(new byte[0])); Slime slime = new Slime(); Cursor root = slime.setObject(); root.setString(VERSION_F, version.toString()); root.setString(ROUTE_F, route.toString()); root.setString(SESSION_F, address.getSessionName()); root.setString(PROTOCOL_F, msg.getProtocol().toString()); root.setBool(USERETRY_F, msg.getRetryEnabled()); root.setLong(RETRY_F, msg.getRetry()); root.setLong(TIMEREMAINING_F, msg.getTimeRemaining()); root.setLong(TRACELEVEL_F, traceLevel); root.setData(BLOB_F, payload); byte[] serializedSlime = BinaryFormat.encode(slime); Compressor.Compression compressionResult = compressor.compress(serializedSlime); v.add(new Int8Value(compressionResult.type().getCode())); v.add(new Int32Value(compressionResult.uncompressedSize())); v.add(new DataValue(compressionResult.data())); return req; }
@Override protected void createResponse(Values ret, Reply reply, Version version, byte [] payload) { ret.add(new Int8Value(CompressionType.NONE.getCode())); ret.add(new Int32Value(0)); ret.add(new DataValue(new byte[0])); ret.add(new Int32Value(compressionResult.uncompressedSize())); ret.add(new DataValue(compressionResult.data()));