title: What's the Scala way to implement a retry-able call like this one?
body: <p>Still the newbie in Scala and I'm now looking for a way to implement the following code on it:</p>
  
  <pre><code>@Override
  public void store(InputStream source, String destination, long size) {
  
      ObjectMetadata metadata = new ObjectMetadata();
      metadata.setContentLength(size);
      final PutObjectRequest request = new PutObjectRequest(
              this.configuration.getBucket(), destination, source, metadata);
  
      new RetryableService(3) {
  
          @Override
          public void call() throws Exception {
              getClient().putObject(request);
          }
      };
  
  }
  </code></pre>
  
  <p>What would be the best way to implement the same funcionality that RetryableService implements but in Scala?</p>
  
  <p>It basically calls the <strong>call</strong> method N times, if all of them fail the exception is then raised, if they succeed it moves on. This one does not return anything but then I have another version that allows for returning a value (so, i have two classes in Java) and I believe I could do with a single class/function in Scala.</p>
  
  <p>Any ideas?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Current implementation in java is as follows:</p>
  
  <pre><code>public abstract class RetryableService {
  
  private static final JobsLogger log = JobsLogger
          .getLogger(RetryableService.class);
  
  private int times;
  
  public RetryableService() {
      this(3);
  }
  
  public RetryableService(int times) {
      this.times = times;
      this.run();
  }
  
  private void run() {
  
      RuntimeException lastExceptionParent = null;
  
      int x = 0;
  
      for (; x &lt; this.times; x++) {
  
          try {
              this.call();
              lastExceptionParent = null;
              break;
          } catch (Exception e) {
              lastExceptionParent = new RuntimeException(e);
              log.errorWithoutNotice( e, "Try %d caused exception %s", x, e.getMessage() );
  
              try {
                  Thread.sleep( 5000 );
              } catch (InterruptedException e1) {
                  log.errorWithoutNotice( e1, "Sleep inside try %d caused exception %s", x, e1.getMessage() );
              }
  
          }
  
      }
  
      try {
          this.ensure();
      } catch (Exception e) {
          log.error(e, "Failed while ensure inside RetryableService");
      }
  
      if ( lastExceptionParent != null ) {
          throw new IllegalStateException( String.format( "Failed on try %d of %s", x, this ), lastExceptionParent);
      }   
  
  }
  
  public void ensure() throws Exception {
      // blank implementation
  }
  
  public abstract void call() throws Exception;
  
  }
  </code></pre>