summaryrefslogblamecommitdiffstats
path: root/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OrganizationList.java
blob: e012e5e2d1a0f753dae694e6a31479d34841a9e2 (plain) (tree)
1
2
3
4
5
6
7
8


                                          
                           


                                                            
                                            






                                                                           
                                                                     








                                                                                







                                                                                                            



                                     
package org.openslx.bwlp.sat.thrift.cache;

import java.util.List;
import java.util.TimerTask;

import org.apache.thrift.TException;
import org.openslx.bwlp.sat.database.mappers.DbOrganization;
import org.openslx.bwlp.sat.util.QuickTimer;
import org.openslx.bwlp.thrift.iface.Organization;
import org.openslx.thrifthelper.ThriftManager;

/**
 * Holds the list of all known organizations. The list is synchronized with
 * the master server.
 */
public class OrganizationList extends CacheBase<List<Organization>> {

	private static final OrganizationList instance = new OrganizationList();

	public static List<Organization> get() {
		return instance.getInternal();
	}

	@Override
	protected List<Organization> getCallback() throws TException {
		final List<Organization> organizations = ThriftManager.getMasterClient().getOrganizations();
		// Also store the list in the local data base (asynchronous, in the timer thread)
		QuickTimer.scheduleOnce(new TimerTask() {
			@Override
			public void run() {
				DbOrganization.storeOrganizations(organizations);
			}
		});
		return organizations;
	}

}