All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.hapjava.server.impl.http.impl.HomekitHttpServer Maven / Gradle / Ivy

There is a newer version: 2.0.7
Show newest version
package io.github.hapjava.server.impl.http.impl;

import io.github.hapjava.server.HomekitWebHandler;
import io.github.hapjava.server.impl.http.HomekitClientConnectionFactory;
import java.net.InetAddress;
import java.util.concurrent.CompletableFuture;

public class HomekitHttpServer implements HomekitWebHandler {

  private NettyHomekitHttpService service = null;
  private final InetAddress localAddress;
  private final int port;
  private final int nThreads;

  @Override
  public void stop() {
    if (this.service != null) {
      this.service.shutdown();
    }
  }

  public HomekitHttpServer(InetAddress localAddress, int port, int nThreads) {
    this.localAddress = localAddress;
    this.port = port;
    this.nThreads = nThreads;
  }

  @Override
  public CompletableFuture start(HomekitClientConnectionFactory clientConnectionFactory) {
    if (service == null) {
      this.service = NettyHomekitHttpService.create(localAddress, port, nThreads);
      return this.service.create(clientConnectionFactory);
    } else {
      throw new RuntimeException("HomekitHttpServer can only be started once");
    }
  }

  @Override
  public void resetConnections() {
    service.resetConnections();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy