Replace a few runnables with lambdas.

This commit is contained in:
akwizgran
2017-12-01 13:47:54 +00:00
parent c8326103b4
commit 030b52261d
3 changed files with 46 additions and 61 deletions

View File

@@ -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
public void run() {
try { try {
ss.accept(); ss.accept();
latch.countDown(); latch.countDown();
} catch (IOException e) { } catch (IOException e) {
error.set(true); 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
public void run() {
try { try {
ss.accept(); ss.accept();
latch.countDown(); latch.countDown();
} catch (IOException e) { } catch (IOException e) {
error.set(true); 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);

View File

@@ -91,9 +91,7 @@ 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
public void run() {
String nickname = databaseConfig.getLocalAuthorName(); String nickname = databaseConfig.getLocalAuthorName();
StartResult result = lifecycleManager.startServices(nickname); StartResult result = lifecycleManager.startServices(nickname);
if (result == SUCCESS) { if (result == SUCCESS) {
@@ -107,8 +105,7 @@ public class BriarService extends Service {
showStartupFailureNotification(result); showStartupFailureNotification(result);
stopSelf(); 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
public void run() {
if (started) lifecycleManager.stopServices(); if (started) lifecycleManager.stopServices();
} }).start();
}.start();
} }
@Override @Override

View File

@@ -123,9 +123,7 @@ public class BriarControllerImpl implements BriarController {
@Override @Override
public void signOut(ResultHandler<Void> eventHandler) { public void signOut(ResultHandler<Void> eventHandler) {
new Thread() { new Thread(() -> {
@Override
public void run() {
try { try {
// Wait for the service to finish starting up // Wait for the service to finish starting up
IBinder binder = serviceConnection.waitForBinder(); IBinder binder = serviceConnection.waitForBinder();
@@ -140,8 +138,7 @@ public class BriarControllerImpl implements BriarController {
LOG.warning("Interrupted while waiting for service"); LOG.warning("Interrupted while waiting for service");
} }
eventHandler.onResult(null); eventHandler.onResult(null);
} }).start();
}.start();
} }
private void unbindService() { private void unbindService() {