Skip to content

Commit

Permalink
Added API to get specific service + synchronized services list operat…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
devgianlu committed Jun 20, 2021
1 parent 88b9e80 commit ac30381
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main/java/xyz/gianlu/zeroconf/Zeroconf.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xyz.gianlu.zeroconf;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -555,7 +556,9 @@ private void addRelated(@NotNull Record record) {
if (!record.getName().endsWith(serviceName))
return;

services.stream().filter(s -> s.serviceName.equals(record.getName())).forEach(s -> s.addRelatedRecord(record));
synchronized (services) {
services.stream().filter(s -> s.serviceName.equals(record.getName())).forEach(s -> s.addRelatedRecord(record));
}
}

private void addService(@NotNull RecordSRV record) {
Expand All @@ -575,6 +578,17 @@ public Collection<DiscoveredService> getServices() {
return Collections.unmodifiableCollection(services);
}

@Nullable
public DiscoveredService getService(@NotNull String name) {
synchronized (services) {
for (DiscoveredService service : services)
if (service.name.equals(name))
return service;

return null;
}
}

@Override
public void run() {
while (!shouldStop) {
Expand Down

0 comments on commit ac30381

Please sign in to comment.