Skip to content

Commit

Permalink
[sre] Synchronizing NoNetworkService.
Browse files Browse the repository at this point in the history
see #470
see #546

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Jan 25, 2017
1 parent 419af3f commit 1b4e2c9
Showing 1 changed file with 21 additions and 7 deletions.
Expand Up @@ -64,21 +64,31 @@ public NoNetworkService() {
//
}

/** Replies the mutex for synchronizing on the service.
*
* @return the mutex.
*/
protected final Object getServiceMutex() {
return this;
}

@Override
public synchronized URI getURI() {
return this.localHost;
public URI getURI() {
synchronized (getServiceMutex()) {
return this.localHost;
}
}

@Override
public void addNetworkServiceListener(NetworkServiceListener listener) {
synchronized (this.listeners) {
synchronized (getServiceMutex()) {
this.listeners.add(listener);
}
}

@Override
public void removeNetworkServiceListener(NetworkServiceListener listener) {
synchronized (this.listeners) {
synchronized (getServiceMutex()) {
this.listeners.remove(listener);
}
}
Expand All @@ -104,16 +114,20 @@ public void disconnectPeer(URI peer) throws Exception {
}

@Override
protected synchronized void doStart() {
protected void doStart() {
final InetAddress adr = NetworkUtil.getLoopbackAddress();
final URI newLocalHost;
if (adr == null) {
try {
this.localHost = NetworkUtil.toURI("tcp://127.0.0.1:0"); //$NON-NLS-1$
newLocalHost = NetworkUtil.toURI("tcp://127.0.0.1:0"); //$NON-NLS-1$
} catch (URISyntaxException e) {
throw new Error(e);
}
} else {
this.localHost = NetworkUtil.toURI(adr, 0);
newLocalHost = NetworkUtil.toURI(adr, 0);
}
synchronized (getServiceMutex()) {
this.localHost = newLocalHost;
}
notifyStarted();
}
Expand Down

0 comments on commit 1b4e2c9

Please sign in to comment.