Class ServiceEngine

java.lang.Object
org.faceless.publisher.web.ServiceEngine

public class ServiceEngine extends Object
The core "engine" that drives the Web Service, which has HttpController and WebsocketController interfaces onto it
  • Constructor Details

    • ServiceEngine

      public ServiceEngine()
      Create a new ServiceEngine
  • Method Details

    • getInstance

      public static ServiceEngine getInstance()
      Return a shared instance of a ServiceEngine, creating it if necessary
      Returns:
      this;
    • setSecure

      public void setSecure(boolean secure)
      This method should be called to enable options which would allow various actions (such as allowing access to the filesystem) which would be insecure if they were left unrestricted. Calling this method indicates that the adminstrator is aware of the security implications of allowing thse.
      Parameters:
      secure - the secure flag
    • isSecure

      public boolean isSecure()
      Return the value of the "secure" flag, as set by setSecure(boolean)
      Returns:
      the secure flag
    • getHttpController

      public HttpController getHttpController()
      Return the HttpController
    • getWebsocketController

      public WebsocketController getWebsocketController()
      Return the WebsocketController
    • isPaused

      public boolean isPaused()
      Return true if this ServiceEngine is paused. When paused jobs can be queued, but no new jobs will execute
    • pause

      public void pause(Runnable r, long timeout)
      Pause the ServiceEngine. No new jobs will be executed, although existing jobs will be left to finish. When all the currently executing jobs are completed or when the timeout period is reached (whichever is first), the supplied task will be run.
      Parameters:
      r - the Runnable to run when all jobs are completed or the timeout is reached. May be null.
      timeout - the time in milliseconds to wait for jobs to complete before running "r"
    • resume

      public void resume()
      Resume the ServiceEngine after previously being paused
    • cacheClear

      public void cacheClear()
      Clear the Resource cache used by the ReportFactory
      Since:
      1.2
    • start

      public Future<Void> start()
      Start the server, or if it's alrady started, return the future that can be used to monitor or stop it.
      Returns:
      a future that can be used to monitor or stop the server
    • shutdown

      public Future<Void> shutdown(boolean mayInterrupt)
      Shutdown the ServiceEngine
      Returns:
      the same future returned from start()
    • getPendingTasks

      public List<org.faceless.publisher.web.ReportHandle> getPendingTasks()
      Get a list of tasks that are pending, waiting for the ExecutorService
    • getRunningTasks

      public List<org.faceless.publisher.web.ReportHandle> getRunningTasks()
      Get a list of tasks that are running currently, waiting for the ExecutorService
    • configure

      public boolean configure(Json json)
      Configure this ServiceEngine. If tasks are currently running this method will return false and no configuration takes place. Otherwise the engine is paused, the configuration is applied and the engine resumed if it was resumed when this method was called.
    • toString

      public String toString()
      Return a String value representing this ServiceEngine. Calls toString(false)
      Overrides:
      toString in class Object
    • toString

      public String toString(boolean admin)
      Return a String value representing this ServiceEngine
      Parameters:
      admin - whether to include admin-only details
    • setStore

      public void setStore(Store store)
      Set the Store on this object and call Store.setServiceEngine(org.faceless.publisher.web.ServiceEngine) on the new object. Any existing store is unchanged, it's the callers responsibility to shut it down cleanly
    • getStore

      public Store getStore()
      Return the Store used by this ServiceEngine
    • getAuthorities

      public List<Authority> getAuthorities()
      Return the list of Authority objects used by this ServiceEngine to allow tasks to be run. The list is live and can be modified
    • getProxyServers

      public List<String> getProxyServers()
      Return the list of IP addresses that will be accepted as valid proxies. Incoming HTTP or WebSocket requests that come from one of these addresses will be checked for an X-Forwarded-For HTTP header, and if found that address will be used instead. The list is live and can be modified. Any IP addresses added should be in lower case, and must be IPv4 or IPv5 addresses, not hostnames.
      Since:
      1.1
    • setSimpleAPI

      public void setSimpleAPI(boolean simpleapi)
      Set whether the "simple" HTTP API can be used (default is true)
      Parameters:
      simpelapi - whether the simple API can be used
    • isSimpleAPI

      public boolean isSimpleAPI()
      Return whether the "simple" HTTP API can be used.
    • setMaxThreads

      public void setMaxThreads(int numthreads)
      Set the maximum number of threads that can be used to execute tasks
      Parameters:
      numthreads - the number of threads, which must be at least one
    • getMaxThreads

      public int getMaxThreads()
      Return the maximum number of threads that can be used to execute tasks, as set by setMaxThreads(int)
      Returns:
      the number of threads
    • setMaxQueueSize

      public void setMaxQueueSize(int queuesize)
      Set the maximum number of tasks that can be queued waiting for an executor. The size may be reduced to below the number of currently queued tasks without error.
      Parameters:
      queuesize - the maximum number of tasks to queue, which must be at least one
    • getMaxQueueSize

      public int getMaxQueueSize()
      Return the maximum number of tasks that can be queued, as set by setMaxQueueSize(int)
      Returns:
      the maximum number of tasks to queue
    • setMaxBufferSize

      public void setMaxBufferSize(long buffersize)
      Set the maximum amount of data that can be uploaded.
    • getMaxBufferSize

      public long getMaxBufferSize()
      Return the maximum buffer size, as set by setMaxBufferSize(long)
      Returns:
      the maximum buffer size
    • getReportFactory

      public ReportFactory getReportFactory()
      Return the ReportFactory used by this ServiceEngine
    • getAuthorization

      public Authorization getAuthorization(String accessToken, String origin, InetAddress ip)
      Return the list of authorizations for the specified token. If the token is null, invalid or damaged, returns the authorization granted anonymous users. The supplied JWT access tokens must be signed by a key specified by an Authority known to this class (see getAuthorities()
      Parameters:
      accessToken - the JWT access token that's claiming to authorize this action, or null for anon
      origin - the Origin header for the HTTP connection that originated this session, or null if unspecified
      ip - the IP address the request has come from, or null if that is not available
    • initializeConvert

      public org.faceless.publisher.web.ReportHandle initializeConvert(Json json, Authorization auth) throws IOException
      See docs
      Throws:
      IOException
    • find

      public org.faceless.publisher.web.ReportHandle find(String folder, Authorization auth)
      Return an active job, one which is currently queued or running. The store is not accessed
      Parameters:
      folder - the job folder
      auth - the secret required to access the job, or "*" for admin access
      Returns:
      the handle if it's in any state between "Pending" and "Error", or null if it's not yet enqueued, has been deleted, doesn't exist or if the secret token is incorrect.