Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package io.advantageous.qbit.admin;
  
  
 
 
 @SuppressWarnings("WeakerAccess")
 public class AdminBuilder {
 
 
     @SuppressWarnings("WeakerAccess")
     public static final String CONTEXT = "qbit.service.admin.";
 
     private int port = 7777;
     private String host;
     private String name;
     private Admin admin;
     private HealthServiceAsync healthService;
     private String htmlPageLocation = "/qbit/admin.html";
     private HttpServer httpServer;
     private String webPageContents;
 
 
     @SuppressWarnings("WeakerAccess")
     public AdminBuilder(final PropertyResolver propertyResolver) {
          = propertyResolver.getIntegerProperty("port");
          = propertyResolver.getStringProperty("host");
          = propertyResolver.getStringProperty("htmlPageLocation");
     }
 
 
     @SuppressWarnings("WeakerAccess")
     public AdminBuilder() {
 
         this(PropertyResolver.createSystemPropertyResolver());
     }
 
     public AdminBuilder(Properties properties) {
 
         this(PropertyResolver.createPropertiesPropertyResolver(properties));
     }
 
     public static AdminBuilder adminBuilder() {
         return new AdminBuilder();
     }
 
     public String getHtmlPageLocation() {
         return ;
     }
 
     public void setHtmlPageLocation(String htmlPageLocation) {
         this. = htmlPageLocation;
     }
 
 
     public AdminBuilder setWebCotentsSupplier(Supplier<StringwebPageContentsSupplier) {
         this. = webPageContentsSupplier;
         return this;
     }
 
         if ( == null) {
             final String webContents = getWebPageContents();
              = new Supplier<String>() {
                 @Override
                 public String get() {
                     return webContents;
                 }
             };
         }
         return ;
     }
 
     public AdminBuilder setWebPageContents(String webPageContents) {
         this. = webPageContents;
         return this;
     }
 
     public String getWebPageContents() {
 
         if (==null || .isEmpty()) {
 
             final String htmlPageLocationInitial = getHtmlPageLocation();
             final String pageLocation;
            pageLocation = htmlPageLocationInitial.startsWith("/") ?
                    htmlPageLocationInitial.substring(1, htmlPageLocationInitial.length()) :
                    htmlPageLocationInitial;
             = IO.read(
                    Thread.currentThread()
                            .getContextClassLoader()
                            .getResourceAsStream(pageLocation)
            );
        }
        return ;
    }
    public HttpServer getHttpServer() {
        if ( == null) {
             = getHttpServerBuilder()
                    .setPort(getPort())
                    .setHost(getHost())
                    .build();
            final Supplier<StringwebPageContentsSupplier = getWebPageContentsSupplier();
            .setShouldContinueHttpRequest(httpRequest -> {
                /* If not the page uri we want to then,
                 just continue by returning true. */
                if (!httpRequest.getUri().equals(getHtmlPageLocation())) {
                    return true;
                }
                final String webPageContents = webPageContentsSupplier.get();
                /* Send the HTML file out to the browser. */
                httpRequest.getReceiver().response(200, "text/html"webPageContents);
                return false;
            });
        }
        return ;
    }
    public void setHttpServer(HttpServer httpServer) {
        this. = httpServer;
    }
        if (==null) {
             = HttpServerBuilder.httpServerBuilder();
        }
        return ;
    }
    public void setHttpServerBuilder(HttpServerBuilder httpServerBuilder) {
        this. = httpServerBuilder;
    }
        if ( == null) {
             = getHealthServiceBuilder().buildAndStart();
        }
        return ;
    }
    public AdminBuilder setHealthService(HealthServiceAsync healthService) {
        this. = healthService;
        return this;
    }
        if ( == null) {
             = HealthServiceBuilder.healthServiceBuilder();
        }
        return ;
    }
    public AdminBuilder setHealthServiceBuilder(HealthServiceBuilder healthServiceBuilder) {
        this. = healthServiceBuilder;
        return this;
    }
    public Admin getAdmin() {
        if ( == null) {
             = new Admin(getHealthService());
        }
        return ;
    }
    public void setAdmin(Admin admin) {
        this. = admin;
    }
    public String getName() {
        return ;
    }
    public AdminBuilder setName(String name) {
        this. = name;
        return this;
    }
        if ( == null) {
                    .setHttpServer(getHttpServer()).build();
        }
        return ;
    }
    public void setServiceEndpointServer(ServiceEndpointServer serviceEndpointServer) {
        this. = serviceEndpointServer;
    }
    public int getPort() {
        return ;
    }
    public AdminBuilder setPort(int port) {
        this. = port;
        return this;
    }
    public String getHost() {
        return ;
    }
    public AdminBuilder setHost(String host) {
        this. = host;
        return this;
    }
        if ( == null) {
             = EndpointServerBuilder.endpointServerBuilder().setPort(this.getPort());
            if ( != null && !"".equals()) {
                .setHost();
            }
        }
        return ;
    }
    public AdminBuilder setEndpointServerBuilder(EndpointServerBuilder endpointServerBuilder) {
        this. = endpointServerBuilder;
        return this;
    }
    public ServiceEndpointServer build() {
        ServiceEndpointServer serviceEndpointServer = getServiceEndpointServer();
        if (getName() == null) {
            serviceEndpointServer.initServices(getAdmin());
        } else {
            serviceEndpointServer.addServiceObject(getName(), getAdmin());
        }
        return serviceEndpointServer;
    }
New to GrepCode? Check out our FAQ X