@Override public BasicIoTaskBuilder<I, O> setCredentialsMap(final Map<String, String> credentials) { if(credentials != null) { this.credentialsMap = credentials; setSecretSupplier(null); } return this; }
@Override public BasicIoTask<I> getResult() { buildItemPath(item, dstPath == null ? srcPath : dstPath); return new BasicIoTask<>(this); }
@Override @SuppressWarnings("unchecked") public O getInstance(final I item) throws IOException { final String uid; return (O) new BasicIoTask<>( originCode, ioType, item, inputPath, getNextOutputPath(), Credential.getInstance(uid = getNextUid(), getNextSecret(uid)) ); }
static <I extends DataItem, O extends DataIoTask<I>> boolean invokeCreate( final I fileItem, final O ioTask, final FileChannel dstChannel ) throws IOException { long countBytesDone = ioTask.getCountBytesDone(); final long contentSize = fileItem.size(); if(countBytesDone < contentSize && IoTask.Status.ACTIVE.equals(ioTask.getStatus())) { countBytesDone += fileItem.writeToFileChannel(dstChannel, contentSize - countBytesDone); ioTask.setCountBytesDone(countBytesDone); } return countBytesDone >= contentSize; }
private boolean invokeDelete(final O ioTask) throws IOException { final String dstPath = ioTask.getDstPath(); final I fileItem = ioTask.getItem(); FS_PROVIDER.delete(dstPath == null ? Paths.get(fileItem.getName()) : Paths.get(dstPath, fileItem.getName())); return true; }
@Override public final boolean put(final O ioResult) throws IOException { if(ioResult == null) { // poison close(); return true; } return itemInfoOutput.put(ioResult.getItem().toString()); }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); countBytesDone = in.readLong(); respDataTimeStart = in.readLong(); }
@Override public void writeExternal(final ObjectOutput out) throws IOException { super.writeExternal(out); out.writeLong(countBytesDone); out.writeLong(respDataTimeStart); }
@Override public void close() throws IOException { super.close(); if(srcItemsForConcat != null) { srcItemsForConcat.clear(); srcItemsForConcat = null; } if(fixedRanges != null) { fixedRanges.clear(); fixedRanges = null; } }
@Override public final void operationComplete(final Future<Void> future) throws Exception { try { ioTask.finishRequest(); } catch(final IllegalStateException e) { LogUtil.exception(Level.DEBUG, e, "{}", ioTask.toString()); } } }
@Override public void writeExternal(final ObjectOutput out) throws IOException { out.writeInt(originCode); out.writeInt(ioType.ordinal()); out.writeObject(item); out.writeUTF(srcPath == null ? "" : srcPath); out.writeUTF(dstPath == null ? "" : dstPath); out.writeObject(credential); out.writeUTF(nodeAddr == null ? "" : nodeAddr); out.writeInt(status == null ? Status.PENDING.ordinal() : status.ordinal()); out.writeLong(reqTimeStart); out.writeLong(reqTimeDone); out.writeLong(respTimeStart); out.writeLong(respTimeDone); }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { originCode = in.readInt(); ioType = IoType.values()[in.readInt()]; item = (I) in.readObject(); srcPath = in.readUTF(); dstPath = in.readUTF(); credential = (Credential) in.readObject(); nodeAddr = in.readUTF(); status = Status.values()[in.readInt()]; reqTimeStart = in.readLong(); reqTimeDone = in.readLong(); respTimeStart = in.readLong(); respTimeDone = in.readLong(); }
@Override public void complete(final Channel channel, final O ioTask) { ThreadContext.put(KEY_CLASS_NAME, CLS_NAME); ThreadContext.put(KEY_TEST_STEP_ID, stepId); try { ioTask.finishResponse(); } catch (final IllegalStateException e) { LogUtil.exception(Level.DEBUG, e, "{}: invalid I/O task state", ioTask.toString()); } if (channel != null) { connPool.release(channel); } ioTaskCompleted(ioTask); }
static <I extends DataItem, O extends DataIoTask<I>> boolean invokeCopy( final I fileItem, final O ioTask, final FileChannel srcChannel, final FileChannel dstChannel ) throws IOException { long countBytesDone = ioTask.getCountBytesDone(); final long contentSize = fileItem.size(); if(countBytesDone < contentSize && IoTask.Status.ACTIVE.equals(ioTask.getStatus())) { countBytesDone += srcChannel.transferTo( countBytesDone, contentSize - countBytesDone, dstChannel ); ioTask.setCountBytesDone(countBytesDone); } return countBytesDone >= contentSize; }
@Override @SuppressWarnings("unchecked") public void getInstances(final List<I> items, final List<O> buff) throws IOException { String uid; for(final I item : items) { buff.add( (O) new BasicIoTask<>( originCode, ioType, item, inputPath, getNextOutputPath(), Credential.getInstance(uid = getNextUid(), getNextSecret(uid)) ) ); } }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); countBytesDone = in.readLong(); respDataTimeStart = in.readLong(); }
@Override public void writeExternal(final ObjectOutput out) throws IOException { super.writeExternal(out); out.writeLong(countBytesDone); out.writeLong(respDataTimeStart); }
static <I extends DataItem, O extends DataIoTask<I>> boolean invokeOverwrite( final I fileItem, final O ioTask, final FileChannel dstChannel ) throws IOException { long countBytesDone = ioTask.getCountBytesDone(); if(countBytesDone == 0) { dstChannel.position(countBytesDone); } final long fileSize = fileItem.size(); if(countBytesDone < fileSize && IoTask.Status.ACTIVE.equals(ioTask.getStatus())) { countBytesDone += fileItem.writeToFileChannel(dstChannel, fileSize - countBytesDone); ioTask.setCountBytesDone(countBytesDone); } return countBytesDone >= fileSize; } }
private void invokeCreate( final I fileItem, final O ioTask, final FileChannel dstChannel ) throws IOException { long countBytesDone = ioTask.getCountBytesDone(); final long contentSize = fileItem.size(); if(countBytesDone < contentSize && Status.ACTIVE.equals(ioTask.getStatus())) { countBytesDone += fileItem.writeToFileChannel(dstChannel, contentSize - countBytesDone); ioTask.setCountBytesDone(countBytesDone); } if(countBytesDone == contentSize) { finishIoTask(ioTask); } }
private void invokeCopy( final I fileItem, final O ioTask, final FileChannel srcChannel, final FileChannel dstChannel ) throws IOException { long countBytesDone = ioTask.getCountBytesDone(); final long contentSize = fileItem.size(); if(countBytesDone < contentSize && Status.ACTIVE.equals(ioTask.getStatus())) { countBytesDone += srcChannel.transferTo( countBytesDone, contentSize - countBytesDone, dstChannel ); ioTask.setCountBytesDone(countBytesDone); } if(countBytesDone == contentSize) { finishIoTask(ioTask); } }