Hi I have a class with two methods referring a session object. I want to modify it and make it work to handle two sessions running parallely. So based if a new session comes within a session I want to assign the new session to another variable. You know I don't want to modify the class severely. I just want to use a boolean variable that checks the status and assign the session to one of the two variables and the res of the logic will run smoothly. Here is the frameowrk of my class
So as you see the connect server side creates a session and should assign to the proper global variable. But in PassToServer method after the control gets back serverSession (which I think is refering to either the global serversession and global newserversession is still null). I hope my question is clear. Basically my question is how can I point an object from a method using the same type of object and modify the pointer and get the effect on the global object.Public class MyClass { private IoSession clientSession = null; private IoSession serverSession = null; private IoSession newServerSession = null; public void passToServer( RtspMessage message ) { //I include the following assignment statment and if statement to make is work for two sessions /* IoSession serverSession =null; if (this.sessionWithinASession==true) { serverSession=this.newServerSession; //This is my question } else { serverSession=this.serverSession; //This is my question. I want the variable serverSession (the local one to point to the two global variables). So, tell me if I'm wrong and how I can implement. ... if ( serverSession == null ) { RtspRequest request = (RtspRequest) message; try { connectServerSide( request.getUrl() ); } catch ( IOException e ) { log.error( e ); // closeAll(); } finally { if ( serverSession == null ) return; //I know connectServerSide Creates a new serversession and assigned it to the external one but it terminates b/c this is not referring the global one } } } private void connectServerSide( URL url ) throws IOException { //This is to also another code that i included for the same reason that I mentioned above IoSession serverSession =null; if (this.sessionWithinASession) serverSession=this.newServerSession; else serverSession=this.serverSession; ...... // Create TCP/IP connector. SocketConnector connector = new SocketConnector(); // Start communication. log.debug( "Trying to connect to '" + host + "' " + port + " URL is "+url); try { ConnectFuture future = connector.connect( new InetSocketAddress( host, port ), new ServerSide(), new RtspServerFilters() ); future.join(); serverSession = future.getSession(); //I suppose this will modify the local and also the global and was thinking that by the time it gets back to the previous method serverSession will not be null } catch ( UnresolvedAddressException e ) { return; } }
Thank you
}