code: public void waitForState( final long bundleId,
                                final int state,
                                final long timeoutInMillis )
          throws TimeoutException
      {
          Bundle bundle = m_bundleContext.getBundle( bundleId );
          if( timeoutInMillis == NO_WAIT && (bundle == null || bundle.getState() < state ))
          {
              throw new TimeoutException(
                  "There is no waiting timeout set and bundle has state '" + bundleStateToString( bundle.getState() )
                  + "' not '" + bundleStateToString( state ) + "' as expected"
              );
          }
          long startedTrying = System.currentTimeMillis();
          do
          {
             bundle = m_bundleContext.getBundle( bundleId );
             try
             {
                Thread.sleep(50);
             }
             catch (InterruptedException e)
             {
                Thread.currentThread().interrupt();
                break;
             }
          }
          while( (bundle == null || bundle.getState() < state)
                 && ( timeoutInMillis == WAIT_FOREVER
                      || System.currentTimeMillis() < startedTrying + timeoutInMillis ) );
          // bundle != null && bundle.getState() >= state
          // or
          // timeoutInMillis != WAIT_FOREVER && System.currentTimeMillis() >= startedTrying + timeoutInMillis
          if( bundle == null || bundle.getState() < state )
          {
              throw new TimeoutException(
                  "Timeout passed and bundle has state '" + bundleStateToString( bundle.getState() )
                  + "' not '" + bundleStateToString( state ) + "' as expected"
              );
          }
      }
docs: {@inheritDoc}