YARN-8506. Make GetApplicationsRequestPBImpl thread safe. (wangda)

Change-Id: If304567abb77a01b686d82c769bdf50728484163
This commit is contained in:
Wangda Tan 2018-07-09 11:30:08 -07:00
parent 0838fe8337
commit 83cd84b70b

View File

@ -65,7 +65,7 @@ public GetApplicationsRequestPBImpl(GetApplicationsRequestProto proto) {
viaProto = true; viaProto = true;
} }
public GetApplicationsRequestProto getProto() { public synchronized GetApplicationsRequestProto getProto() {
mergeLocalToProto(); mergeLocalToProto();
proto = viaProto ? proto : builder.build(); proto = viaProto ? proto : builder.build();
viaProto = true; viaProto = true;
@ -175,13 +175,13 @@ private void initQueues() {
} }
@Override @Override
public Set<String> getApplicationTypes() { public synchronized Set<String> getApplicationTypes() {
initApplicationTypes(); initApplicationTypes();
return this.applicationTypes; return this.applicationTypes;
} }
@Override @Override
public void setApplicationTypes(Set<String> applicationTypes) { public synchronized void setApplicationTypes(Set<String> applicationTypes) {
maybeInitBuilder(); maybeInitBuilder();
if (applicationTypes == null) if (applicationTypes == null)
builder.clearApplicationTypes(); builder.clearApplicationTypes();
@ -198,13 +198,13 @@ private void initApplicationTags() {
} }
@Override @Override
public Set<String> getApplicationTags() { public synchronized Set<String> getApplicationTags() {
initApplicationTags(); initApplicationTags();
return this.applicationTags; return this.applicationTags;
} }
@Override @Override
public void setApplicationTags(Set<String> tags) { public synchronized void setApplicationTags(Set<String> tags) {
maybeInitBuilder(); maybeInitBuilder();
if (tags == null || tags.isEmpty()) { if (tags == null || tags.isEmpty()) {
builder.clearApplicationTags(); builder.clearApplicationTags();
@ -219,7 +219,7 @@ public void setApplicationTags(Set<String> tags) {
} }
@Override @Override
public EnumSet<YarnApplicationState> getApplicationStates() { public synchronized EnumSet<YarnApplicationState> getApplicationStates() {
initApplicationStates(); initApplicationStates();
return this.applicationStates; return this.applicationStates;
} }
@ -233,12 +233,12 @@ private void initScope() {
} }
@Override @Override
public ApplicationsRequestScope getScope() { public synchronized ApplicationsRequestScope getScope() {
initScope(); initScope();
return this.scope; return this.scope;
} }
public void setScope(ApplicationsRequestScope scope) { public synchronized void setScope(ApplicationsRequestScope scope) {
maybeInitBuilder(); maybeInitBuilder();
if (scope == null) { if (scope == null) {
builder.clearScope(); builder.clearScope();
@ -247,7 +247,7 @@ public void setScope(ApplicationsRequestScope scope) {
} }
@Override @Override
public void setApplicationStates(EnumSet<YarnApplicationState> applicationStates) { public synchronized void setApplicationStates(EnumSet<YarnApplicationState> applicationStates) {
maybeInitBuilder(); maybeInitBuilder();
if (applicationStates == null) { if (applicationStates == null) {
builder.clearApplicationStates(); builder.clearApplicationStates();
@ -256,7 +256,7 @@ public void setApplicationStates(EnumSet<YarnApplicationState> applicationStates
} }
@Override @Override
public void setApplicationStates(Set<String> applicationStates) { public synchronized void setApplicationStates(Set<String> applicationStates) {
EnumSet<YarnApplicationState> appStates = null; EnumSet<YarnApplicationState> appStates = null;
for (YarnApplicationState state : YarnApplicationState.values()) { for (YarnApplicationState state : YarnApplicationState.values()) {
if (applicationStates.contains( if (applicationStates.contains(
@ -272,12 +272,12 @@ public void setApplicationStates(Set<String> applicationStates) {
} }
@Override @Override
public Set<String> getUsers() { public synchronized Set<String> getUsers() {
initUsers(); initUsers();
return this.users; return this.users;
} }
public void setUsers(Set<String> users) { public synchronized void setUsers(Set<String> users) {
maybeInitBuilder(); maybeInitBuilder();
if (users == null) { if (users == null) {
builder.clearUsers(); builder.clearUsers();
@ -286,13 +286,13 @@ public void setUsers(Set<String> users) {
} }
@Override @Override
public Set<String> getQueues() { public synchronized Set<String> getQueues() {
initQueues(); initQueues();
return this.queues; return this.queues;
} }
@Override @Override
public void setQueues(Set<String> queues) { public synchronized void setQueues(Set<String> queues) {
maybeInitBuilder(); maybeInitBuilder();
if (queues == null) { if (queues == null) {
builder.clearQueues(); builder.clearQueues();
@ -301,7 +301,7 @@ public void setQueues(Set<String> queues) {
} }
@Override @Override
public long getLimit() { public synchronized long getLimit() {
if (this.limit == Long.MAX_VALUE) { if (this.limit == Long.MAX_VALUE) {
GetApplicationsRequestProtoOrBuilder p = viaProto ? proto : builder; GetApplicationsRequestProtoOrBuilder p = viaProto ? proto : builder;
this.limit = p.hasLimit() ? p.getLimit() : Long.MAX_VALUE; this.limit = p.hasLimit() ? p.getLimit() : Long.MAX_VALUE;
@ -310,13 +310,13 @@ public long getLimit() {
} }
@Override @Override
public void setLimit(long limit) { public synchronized void setLimit(long limit) {
maybeInitBuilder(); maybeInitBuilder();
this.limit = limit; this.limit = limit;
} }
@Override @Override
public Range<Long> getStartRange() { public synchronized Range<Long> getStartRange() {
if (this.start == null) { if (this.start == null) {
GetApplicationsRequestProtoOrBuilder p = viaProto ? proto: builder; GetApplicationsRequestProtoOrBuilder p = viaProto ? proto: builder;
if (p.hasStartBegin() || p.hasStartEnd()) { if (p.hasStartBegin() || p.hasStartEnd()) {
@ -329,12 +329,12 @@ public Range<Long> getStartRange() {
} }
@Override @Override
public void setStartRange(Range<Long> range) { public synchronized void setStartRange(Range<Long> range) {
this.start = range; this.start = range;
} }
@Override @Override
public void setStartRange(long begin, long end) public synchronized void setStartRange(long begin, long end)
throws IllegalArgumentException { throws IllegalArgumentException {
if (begin > end) { if (begin > end) {
throw new IllegalArgumentException("begin > end in range (begin, " + throw new IllegalArgumentException("begin > end in range (begin, " +
@ -344,7 +344,7 @@ public void setStartRange(long begin, long end)
} }
@Override @Override
public Range<Long> getFinishRange() { public synchronized Range<Long> getFinishRange() {
if (this.finish == null) { if (this.finish == null) {
GetApplicationsRequestProtoOrBuilder p = viaProto ? proto: builder; GetApplicationsRequestProtoOrBuilder p = viaProto ? proto: builder;
if (p.hasFinishBegin() || p.hasFinishEnd()) { if (p.hasFinishBegin() || p.hasFinishEnd()) {
@ -357,12 +357,12 @@ public Range<Long> getFinishRange() {
} }
@Override @Override
public void setFinishRange(Range<Long> range) { public synchronized void setFinishRange(Range<Long> range) {
this.finish = range; this.finish = range;
} }
@Override @Override
public void setFinishRange(long begin, long end) { public synchronized void setFinishRange(long begin, long end) {
if (begin > end) { if (begin > end) {
throw new IllegalArgumentException("begin > end in range (begin, " + throw new IllegalArgumentException("begin > end in range (begin, " +
"end): (" + begin + ", " + end + ")"); "end): (" + begin + ", " + end + ")");