michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.sync.repositories.delegates; michael@0: michael@0: import org.mozilla.gecko.sync.ThreadPool; michael@0: import org.mozilla.gecko.sync.repositories.RepositorySession; michael@0: michael@0: public abstract class DeferrableRepositorySessionCreationDelegate implements RepositorySessionCreationDelegate { michael@0: @Override michael@0: public RepositorySessionCreationDelegate deferredCreationDelegate() { michael@0: final RepositorySessionCreationDelegate self = this; michael@0: return new RepositorySessionCreationDelegate() { michael@0: michael@0: // TODO: rewrite to use ExecutorService. michael@0: @Override michael@0: public void onSessionCreated(final RepositorySession session) { michael@0: ThreadPool.run(new Runnable() { michael@0: @Override michael@0: public void run() { michael@0: self.onSessionCreated(session); michael@0: }}); michael@0: } michael@0: michael@0: @Override michael@0: public void onSessionCreateFailed(final Exception ex) { michael@0: ThreadPool.run(new Runnable() { michael@0: @Override michael@0: public void run() { michael@0: self.onSessionCreateFailed(ex); michael@0: }}); michael@0: } michael@0: michael@0: @Override michael@0: public RepositorySessionCreationDelegate deferredCreationDelegate() { michael@0: return this; michael@0: } michael@0: }; michael@0: } michael@0: }