private void handleFetchMirrorFlush() { for (FetchMirror fetch : pendingFetch) { fetch.task.kill(); dumpServices(fetch.req); fetch.req.returnRequest(); } pendingFetch.clear(); }
private void handleRegisterCallbackDone(Request req, String name, String spec, Target target){ String stored = services.get(name); if (stored != null) { // too late if ( ! stored.equals(spec)) { req.setError(ErrorCode.METHOD_FAILED, "service '" + name + "' registered with another spec"); } req.returnRequest(); target.close(); return; } target.setContext(name); target.addWatcher(monitor); services.put(name, spec); targets.put(name, target); req.returnRequest(); updated(); }
private void downloadFile(Request req) { FileReference fileReference = new FileReference(req.parameters().get(0).asString()); log.log(LogLevel.DEBUG, () -> "getFile() called for file reference '" + fileReference.value() + "'"); Optional<File> pathToFile = downloader.getFile(fileReference); try { if (pathToFile.isPresent()) { req.returnValues().add(new StringValue(pathToFile.get().getAbsolutePath())); log.log(LogLevel.DEBUG, () -> "File reference '" + fileReference.value() + "' available at " + pathToFile.get()); } else { log.log(LogLevel.INFO, "File reference '" + fileReference.value() + "' not found, returning error"); req.setError(fileReferenceDoesNotExists, "File reference '" + fileReference.value() + "' not found"); } } catch (Throwable e) { log.log(LogLevel.WARNING, "File reference '" + fileReference.value() + "' got exception: " + e.getMessage()); req.setError(fileReferenceInternalError, "File reference '" + fileReference.value() + "' removed"); } req.returnRequest(); }
@Override public void handleRequestDone(Request req) { if ( ! req.checkReturnTypes("S")) { registerReq.setError(ErrorCode.METHOD_FAILED, "error during register callback: " + req.errorMessage()); registerReq.returnRequest(); target.close(); return; } String[] names = req.returnValues().get(0).asStringArray(); boolean found = false; for (String n : names) { if (n.equals(name)) { found = true; } } if (!found) { registerReq.setError(ErrorCode.METHOD_FAILED, "register failed: served names does not contain name"); registerReq.returnRequest(); target.close(); return; } handleRegisterCallbackDone(registerReq, name, spec, target); } }
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(); }
@Override public final void handleReply(Reply reply) { ReplyContext ctx = (ReplyContext)reply.getContext(); reply.setContext(null); // Add trace information. if (reply.getTrace().shouldTrace(TraceLevel.SEND_RECEIVE)) { reply.getTrace().trace(TraceLevel.SEND_RECEIVE, "Sending reply (version " + ctx.version + ") from " + serverIdent + "."); } // Encode and return the reply through the RPC request. byte[] payload = new byte[0]; if (reply.getType() != 0) { Protocol protocol = net.getOwner().getProtocol(reply.getProtocol()); if (protocol != null) { payload = protocol.encode(ctx.version, reply); } if (payload == null || payload.length == 0) { reply.addError(new Error(ErrorCode.ENCODE_ERROR, "An error occured while encoding the reply.")); } } createResponse(ctx.request.returnValues(), reply, ctx.version, payload); ctx.request.returnRequest(); }