Small refactoring of AsyncExecutionId (#61640)

- don't do encoding of asynchExecutionId if it is already provided in
the encoded form
- create a new instance of AsyncExecutionId after checks for
correctness are done
This commit is contained in:
Mayya Sharipova 2020-08-31 06:28:14 -04:00
parent 054a64d66f
commit fe9c66096c
1 changed files with 10 additions and 4 deletions

View File

@ -25,9 +25,13 @@ public final class AsyncExecutionId {
private final String encoded; private final String encoded;
public AsyncExecutionId(String docId, TaskId taskId) { public AsyncExecutionId(String docId, TaskId taskId) {
this(docId, taskId, encode(docId, taskId));
}
private AsyncExecutionId(String docId, TaskId taskId, String encoded) {
this.docId = docId; this.docId = docId;
this.taskId = taskId; this.taskId = taskId;
this.encoded = encode(docId, taskId); this.encoded = encoded;
} }
/** /**
@ -98,15 +102,17 @@ public final class AsyncExecutionId {
} catch (Exception e) { } catch (Exception e) {
throw new IllegalArgumentException("invalid id: [" + id + "]", e); throw new IllegalArgumentException("invalid id: [" + id + "]", e);
} }
final AsyncExecutionId searchId; String docId;
String taskId;
try (StreamInput in = new ByteBufferStreamInput(byteBuffer)) { try (StreamInput in = new ByteBufferStreamInput(byteBuffer)) {
searchId = new AsyncExecutionId(in.readString(), new TaskId(in.readString())); docId = in.readString();
taskId = in.readString();
if (in.available() > 0) { if (in.available() > 0) {
throw new IllegalArgumentException("invalid id: [" + id + "]"); throw new IllegalArgumentException("invalid id: [" + id + "]");
} }
} catch (IOException e) { } catch (IOException e) {
throw new IllegalArgumentException("invalid id: [" + id + "]", e); throw new IllegalArgumentException("invalid id: [" + id + "]", e);
} }
return searchId; return new AsyncExecutionId(docId, new TaskId(taskId), id);
} }
} }