summaryrefslogblamecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/serversession/ServerSession.java
blob: 355fc0b302ec1920e893ac50acfc56a82df545d0 (plain) (tree)
1
2
3
4
5
6
7
8
9

                                              


                                               

                                                              
   
   

                          
                                                                                                                           




















                                                                           


                                       

                                               


                                  


                                          
package org.openslx.imagemaster.serversession;

import org.openslx.imagemaster.Globals;
import org.openslx.imagemaster.Globals.PropInt;

/**
 * Holds the session id of the server and manages the timeout.
 * 
 */
public class ServerSession
{
	private static final long TIMEOUT = Long.valueOf( Globals.getPropertyInt( PropInt.SESSIONTIMEOUTSERVER ) ) * 1000L;

	private long timeOut = 0;
	private final ServerUser serverUser;

	public ServerSession(final ServerUser serverUser)
	{
		this.serverUser = serverUser;
		this.timeOut = System.currentTimeMillis() + TIMEOUT;
	}

	public synchronized void refresh()
	{
		if ( timedOut() )
			return; // Don't allow refreshing timed out session
		this.timeOut = System.currentTimeMillis() + TIMEOUT;
	}

	public synchronized boolean timedOut()
	{
		return System.currentTimeMillis() > this.timeOut;
	}

	public String getOrganization()
	{
		return serverUser.organization;
	}

	public String getAddress()
	{
		return serverUser.address;
	}
}