Search in sources :

Example 1 with Answer

use of com.github.dedis.popstellar.model.network.answer.Answer in project popstellar by dedis.

the class LAONetworkManager method subscribe.

@Override
public Completable subscribe(Channel channel) {
    Log.d(TAG, "sending a subscribe on the channel " + channel);
    Subscribe subscribe = new Subscribe(channel, requestCounter.incrementAndGet());
    return request(subscribe).doOnSuccess(answer -> subscribedChannels.add(channel)).doAfterSuccess(answer -> catchup(channel).subscribe()).ignoreElement();
}
Also used : Publish(com.github.dedis.popstellar.model.network.method.Publish) Answer(com.github.dedis.popstellar.model.network.answer.Answer) Completable(io.reactivex.Completable) ResultMessages(com.github.dedis.popstellar.model.network.answer.ResultMessages) Subscribe(com.github.dedis.popstellar.model.network.method.Subscribe) Single(io.reactivex.Single) LAORepository(com.github.dedis.popstellar.repository.LAORepository) Unsubscribe(com.github.dedis.popstellar.model.network.method.Unsubscribe) DataHandlingException(com.github.dedis.popstellar.utility.error.DataHandlingException) WebSocket(com.tinder.scarlet.WebSocket) GenericMessage(com.github.dedis.popstellar.model.network.GenericMessage) JsonRPCErrorException(com.github.dedis.popstellar.utility.error.JsonRPCErrorException) Error(com.github.dedis.popstellar.model.network.answer.Error) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KeyPair(com.github.dedis.popstellar.model.objects.security.KeyPair) Gson(com.google.gson.Gson) Broadcast(com.github.dedis.popstellar.model.network.method.Broadcast) Observable(io.reactivex.Observable) LinkedList(java.util.LinkedList) Log(android.util.Log) Subject(io.reactivex.subjects.Subject) Channel(com.github.dedis.popstellar.model.objects.Channel) Catchup(com.github.dedis.popstellar.model.network.method.Catchup) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) Data(com.github.dedis.popstellar.model.network.method.message.data.Data) Query(com.github.dedis.popstellar.model.network.method.Query) SchedulerProvider(com.github.dedis.popstellar.utility.scheduler.SchedulerProvider) MessageHandler(com.github.dedis.popstellar.utility.handler.MessageHandler) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) PublishSubject(io.reactivex.subjects.PublishSubject) Subscribe(com.github.dedis.popstellar.model.network.method.Subscribe)

Example 2 with Answer

use of com.github.dedis.popstellar.model.network.answer.Answer in project popstellar by dedis.

the class LAONetworkManager method unsubscribe.

@Override
public Completable unsubscribe(Channel channel) {
    Log.d(TAG, "sending an unsubscribe on the channel " + channel);
    Unsubscribe unsubscribe = new Unsubscribe(channel, requestCounter.incrementAndGet());
    return request(unsubscribe).doOnSuccess(answer -> subscribedChannels.remove(channel)).ignoreElement();
}
Also used : Publish(com.github.dedis.popstellar.model.network.method.Publish) Answer(com.github.dedis.popstellar.model.network.answer.Answer) Completable(io.reactivex.Completable) ResultMessages(com.github.dedis.popstellar.model.network.answer.ResultMessages) Subscribe(com.github.dedis.popstellar.model.network.method.Subscribe) Single(io.reactivex.Single) LAORepository(com.github.dedis.popstellar.repository.LAORepository) Unsubscribe(com.github.dedis.popstellar.model.network.method.Unsubscribe) DataHandlingException(com.github.dedis.popstellar.utility.error.DataHandlingException) WebSocket(com.tinder.scarlet.WebSocket) GenericMessage(com.github.dedis.popstellar.model.network.GenericMessage) JsonRPCErrorException(com.github.dedis.popstellar.utility.error.JsonRPCErrorException) Error(com.github.dedis.popstellar.model.network.answer.Error) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KeyPair(com.github.dedis.popstellar.model.objects.security.KeyPair) Gson(com.google.gson.Gson) Broadcast(com.github.dedis.popstellar.model.network.method.Broadcast) Observable(io.reactivex.Observable) LinkedList(java.util.LinkedList) Log(android.util.Log) Subject(io.reactivex.subjects.Subject) Channel(com.github.dedis.popstellar.model.objects.Channel) Catchup(com.github.dedis.popstellar.model.network.method.Catchup) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) Data(com.github.dedis.popstellar.model.network.method.message.data.Data) Query(com.github.dedis.popstellar.model.network.method.Query) SchedulerProvider(com.github.dedis.popstellar.utility.scheduler.SchedulerProvider) MessageHandler(com.github.dedis.popstellar.utility.handler.MessageHandler) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) PublishSubject(io.reactivex.subjects.PublishSubject) Unsubscribe(com.github.dedis.popstellar.model.network.method.Unsubscribe)

Example 3 with Answer

use of com.github.dedis.popstellar.model.network.answer.Answer in project popstellar by dedis.

the class LAONetworkManager method request.

private Single<Answer> request(Query query) {
    Single<Answer> answerSingle = connection.observeMessage().filter(// Filter the Answers
    Answer.class::isInstance).map(Answer.class::cast).filter(answer -> answer.getId() == query.getRequestId()).doOnNext(answer -> Log.d(TAG, "request id: " + answer.getId())).firstOrError().flatMap(answer -> {
        if (answer instanceof Error) {
            return Single.error(new JsonRPCErrorException((Error) answer));
        } else {
            return Single.just(answer);
        }
    }).subscribeOn(schedulerProvider.io()).observeOn(schedulerProvider.mainThread()).timeout(5, TimeUnit.SECONDS).cache();
    // Only send the message after the single is created to make sure it is already waiting
    // before the answer is received
    connection.sendMessage(query);
    return answerSingle;
}
Also used : Publish(com.github.dedis.popstellar.model.network.method.Publish) Answer(com.github.dedis.popstellar.model.network.answer.Answer) Completable(io.reactivex.Completable) ResultMessages(com.github.dedis.popstellar.model.network.answer.ResultMessages) Subscribe(com.github.dedis.popstellar.model.network.method.Subscribe) Single(io.reactivex.Single) LAORepository(com.github.dedis.popstellar.repository.LAORepository) Unsubscribe(com.github.dedis.popstellar.model.network.method.Unsubscribe) DataHandlingException(com.github.dedis.popstellar.utility.error.DataHandlingException) WebSocket(com.tinder.scarlet.WebSocket) GenericMessage(com.github.dedis.popstellar.model.network.GenericMessage) JsonRPCErrorException(com.github.dedis.popstellar.utility.error.JsonRPCErrorException) Error(com.github.dedis.popstellar.model.network.answer.Error) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KeyPair(com.github.dedis.popstellar.model.objects.security.KeyPair) Gson(com.google.gson.Gson) Broadcast(com.github.dedis.popstellar.model.network.method.Broadcast) Observable(io.reactivex.Observable) LinkedList(java.util.LinkedList) Log(android.util.Log) Subject(io.reactivex.subjects.Subject) Channel(com.github.dedis.popstellar.model.objects.Channel) Catchup(com.github.dedis.popstellar.model.network.method.Catchup) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) Data(com.github.dedis.popstellar.model.network.method.message.data.Data) Query(com.github.dedis.popstellar.model.network.method.Query) SchedulerProvider(com.github.dedis.popstellar.utility.scheduler.SchedulerProvider) MessageHandler(com.github.dedis.popstellar.utility.handler.MessageHandler) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) PublishSubject(io.reactivex.subjects.PublishSubject) Answer(com.github.dedis.popstellar.model.network.answer.Answer) JsonRPCErrorException(com.github.dedis.popstellar.utility.error.JsonRPCErrorException) Error(com.github.dedis.popstellar.model.network.answer.Error)

Aggregations

Log (android.util.Log)3 GenericMessage (com.github.dedis.popstellar.model.network.GenericMessage)3 Answer (com.github.dedis.popstellar.model.network.answer.Answer)3 Error (com.github.dedis.popstellar.model.network.answer.Error)3 ResultMessages (com.github.dedis.popstellar.model.network.answer.ResultMessages)3 Broadcast (com.github.dedis.popstellar.model.network.method.Broadcast)3 Catchup (com.github.dedis.popstellar.model.network.method.Catchup)3 Publish (com.github.dedis.popstellar.model.network.method.Publish)3 Query (com.github.dedis.popstellar.model.network.method.Query)3 Subscribe (com.github.dedis.popstellar.model.network.method.Subscribe)3 Unsubscribe (com.github.dedis.popstellar.model.network.method.Unsubscribe)3 MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)3 Data (com.github.dedis.popstellar.model.network.method.message.data.Data)3 Channel (com.github.dedis.popstellar.model.objects.Channel)3 KeyPair (com.github.dedis.popstellar.model.objects.security.KeyPair)3 LAORepository (com.github.dedis.popstellar.repository.LAORepository)3 DataHandlingException (com.github.dedis.popstellar.utility.error.DataHandlingException)3 JsonRPCErrorException (com.github.dedis.popstellar.utility.error.JsonRPCErrorException)3 MessageHandler (com.github.dedis.popstellar.utility.handler.MessageHandler)3 SchedulerProvider (com.github.dedis.popstellar.utility.scheduler.SchedulerProvider)3