mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Replace a few runnables with lambdas.
This commit is contained in:
@@ -150,17 +150,14 @@ public class LanTcpPluginTest extends BrambleTestCase {
|
|||||||
int port = ss.getLocalPort();
|
int port = ss.getLocalPort();
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
AtomicBoolean error = new AtomicBoolean(false);
|
AtomicBoolean error = new AtomicBoolean(false);
|
||||||
new Thread() {
|
new Thread(() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
ss.accept();
|
||||||
try {
|
latch.countDown();
|
||||||
ss.accept();
|
} catch (IOException e) {
|
||||||
latch.countDown();
|
error.set(true);
|
||||||
} catch (IOException e) {
|
|
||||||
error.set(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.start();
|
}).start();
|
||||||
// Tell the plugin about the port
|
// Tell the plugin about the port
|
||||||
TransportProperties p = new TransportProperties();
|
TransportProperties p = new TransportProperties();
|
||||||
p.put("ipPorts", addrString + ":" + port);
|
p.put("ipPorts", addrString + ":" + port);
|
||||||
@@ -243,17 +240,14 @@ public class LanTcpPluginTest extends BrambleTestCase {
|
|||||||
ss.bind(new InetSocketAddress(addrString, 0), 10);
|
ss.bind(new InetSocketAddress(addrString, 0), 10);
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
AtomicBoolean error = new AtomicBoolean(false);
|
AtomicBoolean error = new AtomicBoolean(false);
|
||||||
new Thread() {
|
new Thread(() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
ss.accept();
|
||||||
try {
|
latch.countDown();
|
||||||
ss.accept();
|
} catch (IOException e) {
|
||||||
latch.countDown();
|
error.set(true);
|
||||||
} catch (IOException e) {
|
|
||||||
error.set(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.start();
|
}).start();
|
||||||
// Tell the plugin about the port
|
// Tell the plugin about the port
|
||||||
BdfList descriptor = new BdfList();
|
BdfList descriptor = new BdfList();
|
||||||
descriptor.add(TRANSPORT_ID_LAN);
|
descriptor.add(TRANSPORT_ID_LAN);
|
||||||
|
|||||||
@@ -91,24 +91,21 @@ public class BriarService extends Service {
|
|||||||
b.setPriority(PRIORITY_MIN);
|
b.setPriority(PRIORITY_MIN);
|
||||||
startForeground(ONGOING_NOTIFICATION_ID, b.build());
|
startForeground(ONGOING_NOTIFICATION_ID, b.build());
|
||||||
// Start the services in a background thread
|
// Start the services in a background thread
|
||||||
new Thread() {
|
new Thread(() -> {
|
||||||
@Override
|
String nickname = databaseConfig.getLocalAuthorName();
|
||||||
public void run() {
|
StartResult result = lifecycleManager.startServices(nickname);
|
||||||
String nickname = databaseConfig.getLocalAuthorName();
|
if (result == SUCCESS) {
|
||||||
StartResult result = lifecycleManager.startServices(nickname);
|
started = true;
|
||||||
if (result == SUCCESS) {
|
} else if (result == ALREADY_RUNNING) {
|
||||||
started = true;
|
LOG.info("Already running");
|
||||||
} else if (result == ALREADY_RUNNING) {
|
stopSelf();
|
||||||
LOG.info("Already running");
|
} else {
|
||||||
stopSelf();
|
if (LOG.isLoggable(WARNING))
|
||||||
} else {
|
LOG.warning("Startup failed: " + result);
|
||||||
if (LOG.isLoggable(WARNING))
|
showStartupFailureNotification(result);
|
||||||
LOG.warning("Startup failed: " + result);
|
stopSelf();
|
||||||
showStartupFailureNotification(result);
|
|
||||||
stopSelf();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showStartupFailureNotification(StartResult result) {
|
private void showStartupFailureNotification(StartResult result) {
|
||||||
@@ -155,12 +152,9 @@ public class BriarService extends Service {
|
|||||||
LOG.info("Destroyed");
|
LOG.info("Destroyed");
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
// Stop the services in a background thread
|
// Stop the services in a background thread
|
||||||
new Thread() {
|
new Thread(() -> {
|
||||||
@Override
|
if (started) lifecycleManager.stopServices();
|
||||||
public void run() {
|
}).start();
|
||||||
if (started) lifecycleManager.stopServices();
|
|
||||||
}
|
|
||||||
}.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -123,25 +123,22 @@ public class BriarControllerImpl implements BriarController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void signOut(ResultHandler<Void> eventHandler) {
|
public void signOut(ResultHandler<Void> eventHandler) {
|
||||||
new Thread() {
|
new Thread(() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
// Wait for the service to finish starting up
|
||||||
try {
|
IBinder binder = serviceConnection.waitForBinder();
|
||||||
// Wait for the service to finish starting up
|
BriarService service =
|
||||||
IBinder binder = serviceConnection.waitForBinder();
|
((BriarService.BriarBinder) binder).getService();
|
||||||
BriarService service =
|
service.waitForStartup();
|
||||||
((BriarService.BriarBinder) binder).getService();
|
// Shut down the service and wait for it to shut down
|
||||||
service.waitForStartup();
|
LOG.info("Shutting down service");
|
||||||
// Shut down the service and wait for it to shut down
|
service.shutdown();
|
||||||
LOG.info("Shutting down service");
|
service.waitForShutdown();
|
||||||
service.shutdown();
|
} catch (InterruptedException e) {
|
||||||
service.waitForShutdown();
|
LOG.warning("Interrupted while waiting for service");
|
||||||
} catch (InterruptedException e) {
|
|
||||||
LOG.warning("Interrupted while waiting for service");
|
|
||||||
}
|
|
||||||
eventHandler.onResult(null);
|
|
||||||
}
|
}
|
||||||
}.start();
|
eventHandler.onResult(null);
|
||||||
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void unbindService() {
|
private void unbindService() {
|
||||||
|
|||||||
Reference in New Issue
Block a user