BlazeDS StreamingAMF: how to determine when a flex client closes a connection?

I have a Flex application that connects to a BlazeDS server using the StreamingAMF channel. On the server side, the logic is handled by a user adapter that extends the ActionScriptAdapter and implements the FlexSessionListener and FlexClientListener interfaces.

I ask how to determine which of the "flex-client" closed the connection, for example, when the user closes the browser? (so that I can clear the information inside the database)

I tried using the following:

1. For manual command control:

    @Override
    public Object manage(final CommandMessage commandMessage) {
        switch (commandMessage.getOperation()) {
            case CommandMessage.SUBSCRIBE_OPERATION:
                System.out.println("SUBSCRIBE_OPERATION = " + commandMessage.getHeaders());
                break;
            case CommandMessage.UNSUBSCRIBE_OPERATION:
                System.out.println("UNSUBSCRIBE_OPERATION = " + commandMessage.getHeaders());               
                break;
        }
        return super.manage(commandMessage);
    }

But the customer ID is always different from those that came.

2. Listening for sessionDestroyed and clientDestroyed events

    @Override
    public void clientCreated(final FlexClient client) {
        client.addClientDestroyedListener(this);
        System.out.println("clientCreated = " + client.getId());
    }

    @Override
    public void clientDestroyed(final FlexClient client) {
        System.out.println("clientDestroyed = " + client.getId());
    }

    @Override
    public void sessionCreated(final FlexSession session) {
        System.out.println("sessionCreated = " + session.getId());
        session.addSessionDestroyedListener(this);
    }

    @Override
    public void sessionDestroyed(final FlexSession session) {
        System.out.println("sessionDestroyed = " + session.getId());
    }

But these sessionDestroyed and clientDestroyed methods are never called. :(

+3
3

, .

@Override
public Object manage(final CommandMessage commandMessage) {
    switch (commandMessage.getOperation()) {
        case CommandMessage.SUBSCRIBE_OPERATION:
                // add user info
                // be aware - each time the selector changes this method is called. So when you add user info check to see if you are not duplicating the clients.
                addInfoAboutUser(commandMessage.getHeader("DSId").toString(), commandMessage.getClientId().toString());
                break;
        case CommandMessage.UNSUBSCRIBE_OPERATION:
                clearUserInfo(commandMessage.getClientId().toString());
                break;
    }
    return null;
}

-

INFO: addInfoAboutUser() clearUserinfo() - , .

-

:, flex, manage() : 1- 2- .

+2

onbeforeunload , . Flex , .

... web.xml .

+1

Source: https://habr.com/ru/post/1745268/


All Articles