@Override public void execute(Controller controller) { FSImage fsi = controller.fsImages.get(fsiUuid); cm = controller.getCommandManager(); FileTransferManager ftm = controller.getFileTransferManager(); if (!fsi.isLocal()) { String message = "No such FSImage on the target side"; failed(new IllegalStateException(), message); return; } Path pathToRoot = fsi.getPathToRoot(); Path fullPath = pathToRoot.resolve(path.toPath()); // save memo about this operation on the target side ftm.addTarget(operationUuid, fullPath); try (RandomAccessFile f = new RandomAccessFile(fullPath.toFile(), "rw")) { f.setLength(size); // will send next command to the source cm.sendCommand(new QueryDownloadFile(operationUuid)); } catch (IOException e) { String message = String.format("Allocation memory failed: \r\n %s", e.toString()); failed(e, message); } }
@Override public SerializableCommand fromString(String representation) { String groupSeparator = "\u001E"; StringTokenizer st = new StringTokenizer(representation, groupSeparator, false); String fsiUuid = st.nextToken(); long size = Long.parseLong(st.nextToken()); String sourceId = st.nextToken(); String pathAsString = st.nextToken(); PseudoPath path = PseudoPath.deserialize(pathAsString); return new AllocateSpace(fsiUuid, path, size, sourceId); }
@Override public String getStringRepresentation() { StringBuilder builder = new StringBuilder(); char groupSeparator = '\u001E'; builder.append(fsiUuid); builder.append(groupSeparator); builder.append(size); builder.append(groupSeparator); builder.append(operationUuid); builder.append(groupSeparator); builder.append(path.serializeToString()); return builder.toString(); }