Skip to content

Commit 3204d70

Browse files
committed
Added Scope unit tests and switch internal children to new concurrent collection base
1 parent a8389e8 commit 3204d70

File tree

3 files changed

+149
-156
lines changed

3 files changed

+149
-156
lines changed

src/main/java/org/red5/server/api/scope/IScope.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ public interface IScope extends IBasicScope, ResourcePatternResolver, IServiceHa
111111
*/
112112
public IBroadcastScope getBroadcastScope(String name);
113113

114+
/**
115+
* Get a child scope by name.
116+
*
117+
* @param name Name of the child scope
118+
* @return the child scope, or null if no scope is found
119+
*/
120+
public IBasicScope getBasicScope(String name);
121+
114122
/**
115123
* Get a child scope by type and name.
116124
*

src/main/java/org/red5/server/scope/BasicScope.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public int getDepth() {
188188
*/
189189
@Override
190190
public String getPath() {
191-
return parent.getPath() + '/' + parent.getName();
191+
return String.format("%s/%s", parent.getPath(), parent.getName());
192192
}
193193

194194
/**
@@ -402,18 +402,28 @@ public boolean equals(Object obj) {
402402
}
403403

404404
public int compareTo(BasicScope that) {
405-
if (this.equals(that)) {
405+
if (equals(that)) {
406406
return 0;
407407
}
408-
return name.compareTo(that.getName());
408+
// check name first
409+
int c = name.compareTo(that.getName());
410+
if (c == 0) {
411+
// check type if names were equal
412+
c = type.compareTo(that.getType());
413+
if (c == 0) {
414+
// check path if we've gotten this far
415+
c = getPath().compareTo(that.getPath());
416+
}
417+
}
418+
return c;
409419
}
410420

411421
/**
412422
* Keeps the scope alive for a set number of seconds.
413423
*/
414424
private class KeepAliveJob implements IScheduledJob {
415425

416-
private IBasicScope scope = null;
426+
private final IBasicScope scope;
417427

418428
KeepAliveJob(IBasicScope scope) {
419429
this.scope = scope;

0 commit comments

Comments
 (0)