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 synchronized void handleRpcList(Request req) { Values dst = req.returnValues(); dst.add(new StringArray(names.toArray(new String[names.size()]))); }
@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 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; }
protected Request createRequest(String method,List<String> arguments) { Request request=new Request(method); if (arguments!=null) { for (String argument : arguments) request.parameters().add(getArgument(request,argument)); } return request; }
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"); } }
public void getMethodList(Request req) { int cnt = parent.methodMap().size(); String[] ret0_names = new String[cnt]; String[] ret1_params = new String[cnt]; String[] ret2_return = new String[cnt]; int i = 0; Iterator<Method> itr = parent.methodMap().values().iterator(); while (itr.hasNext()) { Method m = itr.next(); ret0_names[i] = m.name(); ret1_params[i] = m.paramTypes(); ret2_return[i] = m.returnTypes(); i++; } req.returnValues().add(new StringArray(ret0_names)); req.returnValues().add(new StringArray(ret1_params)); req.returnValues().add(new StringArray(ret2_return)); }
void addBucketIdListResult(BucketIdListResult result, Request req) { addResult(result, req); long[] retVal = new long[result.getBuckets().size()]; for (int i = 0; i < retVal.length; ++i) { retVal[i] = result.getBuckets().get(i).getRawId(); } req.returnValues().add(new Int64Array(retVal)); }
@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)); }
@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)); }
public void RPC_getPartitionStates(Request req) { PartitionStateListResult result = provider.getPartitionStates(); addResult(result, req); int[] states = new int[result.getPartitionStates().size()]; String[] reasons = new String[result.getPartitionStates().size()]; for (int i = 0; i < states.length; ++i) { states[i] = result.getPartitionStates().get(i).getState().ordinal(); reasons[i] = result.getPartitionStates().get(i).getReason(); } req.returnValues().add(new Int32Array(states)); req.returnValues().add(new StringArray(reasons)); }
public void addRemoveResult(RemoveResult result, Request req) { addResult(result, req); req.returnValues().add(new Int8Value(result.wasFound() ? (byte)1 : (byte)0)); }
@Override public void invoke(Request request) { request.returnValues().add(new StringValue(getVersion().toString())); }
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)); }
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); } }
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); } }
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()))); }
@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)); }