Skip to content

Commit

Permalink
Share MessageRetrievalService's pipe by reference.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitris Papavasiliou authored and dpapavasiliou committed Sep 27, 2018
1 parent b4af5da commit 0a91b83
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,8 @@ synchronized SignalServiceMessageSender provideSignalMessageSender() {
new DynamicCredentialsProvider(context),
new SignalProtocolStoreImpl(context),
BuildConfig.USER_AGENT,
Optional.fromNullable(MessageRetrievalService.getPipe()),
MessageRetrievalService.getPipeReference(),
Optional.of(new SecurityEventListener(context)));
} else {
this.messageSender.setMessagePipe(MessageRetrievalService.getPipe());
}

return this.messageSender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

import javax.inject.Inject;

Expand Down Expand Up @@ -63,6 +64,7 @@ public class MessageRetrievalService extends Service implements InjectableType,
private MessageRetrievalThread retrievalThread = null;

public static SignalServiceMessagePipe pipe = null;
public static AtomicReference<SignalServiceMessagePipe> pipeReference = new AtomicReference<>();

@Override
public void onCreate() {
Expand Down Expand Up @@ -283,6 +285,10 @@ public static void registerActivityStopped(Context activity) {
return pipe;
}

public static AtomicReference<SignalServiceMessagePipe> getPipeReference() {
return pipeReference;
}

private class MessageRetrievalThread extends Thread implements Thread.UncaughtExceptionHandler {

private AtomicBoolean stopThread = new AtomicBoolean(false);
Expand All @@ -299,9 +305,10 @@ public void run() {
waitForConnectionNecessary();

Log.i(TAG, "Making websocket connection....");
pipe = receiver.createMessagePipe();
final SignalServiceMessagePipe localPipe = receiver.createMessagePipe();

SignalServiceMessagePipe localPipe = pipe;
pipe = localPipe;
pipeReference.set(localPipe);

try {
while (isConnectionNecessary() && !stopThread.get() && !interrupted()) {
Expand Down

0 comments on commit 0a91b83

Please sign in to comment.