code: public static OperationState await(MediaContract service, String operationId) throws ServiceException {
          if (operationId == null) {
              return OperationState.Succeeded;
          }
          OperationInfo opinfo;
          do {
              opinfo = service.get(Operation.get(operationId));            
              try {
                  Thread.sleep(2000);
              } catch (InterruptedException e) {
                  // intentionally do nothing
              }
          } while (opinfo.getState().equals(OperationState.InProgress));
          return opinfo.getState();
      }
docs: Awaits for an operation to be completed.
  
  @param service
  the media contract
  @param operationId
  the operation id to wait for.
  @return the final state of the operation. If operationId is null, returns OperationState.Succeeded.
  @throws ServiceException