Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.lateralthoughts.stub;
  
  
  import java.util.Random;
Facade to easyly start an httpserverstub on available port.
 
 public class EasyHttpServerStub implements Service {
     private static int DEFAULT_PORT = 8080;
     private static final Log LOGGER = LogFactory.getLog(EasyHttpServerStub.class);
     private int port;
     private HttpServerStub server;
     private final Random random = new Random();
 
     public EasyHttpServerStub(String rulesFile) {
         final int TRY_COUNT = 50;
         for (int i = 0; i < TRY_COUNTi++) {
             try {
                  =  + .nextInt(1000);
                  = new HttpServerStub(rulesFile);
                 .startAndWait();
                 return;
             } catch (Exception e) {
                 .error("Unable to bind server:"e);
             }
         }
         throw new IllegalStateException("Unable to start server");
     }
 
     public static EasyHttpServerStub createAndStart(String rulesFile) {
         return new EasyHttpServerStub(rulesFile);
     }
 
     public int getPort() {
         return ;
     }
 
     public HttpServerStub getServer() {
         return ;
     }
 
     @Override
     public ListenableFuture<Statestart() {
         return .start();
     }
 
     @Override
     public State startAndWait() {
         return .startAndWait();
     }
 
     @Override
     public boolean isRunning() {
         return .isRunning();
     }
 
     @Override
     public State state() {
         return .state();
     }
 
     @Override
     public ListenableFuture<Statestop() {
         return .stop();
     }
 
     @Override
     public State stopAndWait() {
         return .stopAndWait();
     }
 
     @Override
     public void addListener(Listener listenerExecutor executor) {
        .addListener(listenerexecutor);
     }
 
     public Callable<BooleanserverCallCountIs(final int expected) {
         return .serverCallCountIs(expected);
     }
 
     public void pause() {
        .pause();
     }
 
     public void unpause() {
        .unpause();
     }
 
     public void clearCounts() {
        .clearCounts();
     }
 
    public int count(String ruleName) {
        return .count(ruleName);
    }
New to GrepCode? Check out our FAQ X