public method IO2GSessionStatus.onSessionStatusChanged

Brief

Processes notifications about session status changes.

Declaration
Java
void  onSessionStatusChanged (O2GSessionStatusCode status)

Parameters
status

The new session status. During the session lifetime, the session status changes. For a detailed explanation of the session statuses, refer to the Session Statuses section. For the implementation details, see the example below.

Details

In order to process notifications about session status cahanges, an instance of the class implementing the IO2GSessionStatus interface must be subscribed to the session object before calling the O2GSession.login method. It is accomplished by calling the O2GSession.subscribeSessionStatus method.

Example

Processing session status updates during login and logout [hide]

     // Create a session, subscribe to session listener, login, logout
        try {
            mSession = O2GTransport.createSession();
            SessionStatusListener statusListener = new SessionStatusListener(mSession, mDBName, mPin);
            mSession.subscribeSessionStatus(statusListener);
            mSession.login(mUserID, mPassword, mURL, mConnection);
            while (!statusListener.isConnected() && !statusListener.hasError()) {
                    Thread.sleep(50);
            }
            if (!statusListener.hasError()) {
                mSession.logout();
                while (!statusListener.isDisconnected()) {
                    Thread.sleep(50);
                }
            }
            mSession.unsubscribeSessionStatus(statusListener);
            mSession.dispose();
            System.exit(1);
        } catch (Exception e) {
            System.out.println ("Exception: " + e.getMessage());
            System.exit(1);
        }
 
    // Implementation of IO2GSessionStatus interface public method onSessionStatusChanged
    public final void onSessionStatusChanged(O2GSessionStatusCode status) {
        mStatus = status;
        System.out.println("Status: " + mStatus.toString());
        if (mStatus == O2GSessionStatusCode.TRADING_SESSION_REQUESTED) {
            O2GSessionDescriptorCollection descs = mSession.getTradingSessionDescriptors();
            System.out.println("\nSession descriptors");
            System.out.println("id, name, description, requires pin");
            for (O2GSessionDescriptor desc : descs) {
                System.out.println(desc.getId() + " " + desc.getName() + " " + desc.getDescription() + " " + desc.isPinRequired());
            }
            if (mDBName.equals("")) {
                System.out.println("Argument for database is missing");
            }
            else {
                mSession.setTradingSession(mDBName, mPin);
            }
        }
    }

Declared in IO2GSessionStatus

back