com.sixestates.rest.v1.CallBackSocketServer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of idp-sdk Show documentation
Show all versions of idp-sdk Show documentation
A Java SDK for communicating with the 6Estates Intelligent Document Processing(IDP) Platform
package com.sixestates.rest.v1;
import com.sixestates.http.CallBackHttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
public class CallBackSocketServer {
private HttpServer httpServer;
private ConcurrentHashMap jsonStrMap;
private ConcurrentHashMap fileBytesMap;
/**
* Construct a new CallBackSocketServer.
*
* @param host Server host
* @param port Server port
*/
public CallBackSocketServer(String host, int port) throws IOException {
httpServer = HttpServer.create(new InetSocketAddress(host, port), 0);
this.jsonStrMap = new ConcurrentHashMap();
this.fileBytesMap = new ConcurrentHashMap();
}
/**
* Start a callback socket server asynchronously.
*/
public void asynStartServer() {
CallBackHttpHandler callBackHttpHandler = new CallBackHttpHandler(this.jsonStrMap, this.fileBytesMap);
httpServer.createContext("/", callBackHttpHandler);
httpServer.setExecutor(Executors.newFixedThreadPool(10));
httpServer.start();
}
/**
* Start a callback socket server asynchronously.
*
* @param path Server host path
*/
public void asynStartServer(String path) {
CallBackHttpHandler callBackHttpHandler = new CallBackHttpHandler(this.jsonStrMap, this.fileBytesMap);
httpServer.createContext(path, callBackHttpHandler);
httpServer.setExecutor(Executors.newFixedThreadPool(10));
httpServer.start();
}
/**
* Close the callback socket server.
*/
public void stopServer() {
httpServer.stop(0);
}
public ConcurrentHashMap getJsonStrMap() {return jsonStrMap;}
public ConcurrentHashMap getFileBytesMap() {return fileBytesMap;}
}