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

com.sixestates.rest.v1.CallBackSocketServer Maven / Gradle / Ivy

Go to download

A Java SDK for communicating with the 6Estates Intelligent Document Processing(IDP) Platform

There is a newer version: 8.2.3
Show newest version
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;}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy