/** * Creates a service collection and starts it. * * @see AbstractLifecycle#onStart */ @Override protected void onStart() { m_serviceCollection = new ServiceCollection<T>( m_context, m_serviceClass, new CollectionListener() ); m_serviceCollection.start(); }
/** * Stops the service collection and releases resources. * * @see AbstractLifecycle#onStop */ @Override protected void onStop() { if( m_serviceCollection != null ) { m_serviceCollection.stop(); m_serviceCollection = null; } setService( null ); }
/** * Resolves a new service by serching the services collection for first available service. */ private synchronized void resolveService() { T newService = null; final Iterator<T> it = m_serviceCollection.iterator(); while( newService == null && it.hasNext() ) { final T candidateService = it.next(); if( !candidateService.equals( getService() ) ) { newService = candidateService; } } setService( newService ); }