3

I have the following class:

@Autowired
private WebSocketStompClient client;

private volatile StompSession stompSession;

public ListenableFuture<StompSession> connect(String token) {
        .....
        //connecting
        return client.connect(settingsBean.getMarketPlaceUrl(),
                new WebSocketHttpHeaders(headers),
                stompHeadersConnect,
                new StompSessionHandlerAdapter() {
                    @Override
                    public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
                        stompSession = session;
                        ...
                        session.subscribe(stompHeadersSubscribe, myFrameHandler);
                         // As I understand I don't have guarantees that subscription was completed successfully
                    }

}

public void send(String url, Object obj) {
    stompSession.send(url, obj);
}

Sometimes send method invokes when connect has already been established, but subscribtion - was not yet.

How to await moment when subscription have been established?

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
  • your question is **really** hard to read, could you please rephrase it? I think asking someone who speaks english to help you might be a good idea – specializt Jun 27 '17 at 10:33
  • @specializt I tried to change a bit. Is it clear now? – gstackoverflow Jun 27 '17 at 10:47
  • ..... no, sorry - something about method invocations and subscriptions (?), thats about everything i can decipher. – specializt Jun 27 '17 at 13:02
  • @specializt not about invocation - about connection and about subscription. I need to know when subscription already established – gstackoverflow Jun 27 '17 at 16:07
  • simply create a new `boolean` instance / member variable *(something like `private volatile boolean isSubscribed = false;`, perhaps)* and set it to `true` during your very first call of `afterConnected` - and check it each time. Thats basic programming. – specializt Jun 28 '17 at 09:53
  • @specializt, afterConnect invokes after connect establishing. Connect and subscribe - 2 different operations. – gstackoverflow Jun 28 '17 at 10:01
  • not in your case - you are subscribing within `afterConnected`. – specializt Jun 28 '17 at 11:59
  • @specializt But if **session.subscribe** is executed -we don't have guarantees that subscription was established – gstackoverflow Jun 28 '17 at 12:07

0 Answers0