Class AbstractClientContext

All Implemented Interfaces:
IClientContext, IEventSource
Direct Known Subclasses:
HeadlessClientContext

public abstract class AbstractClientContext extends AbstractContext implements IClientContext
Base context for official JEB clients. It is used by the RCP client context (GUI), the Controller (floating) context, as well as the headless runner.

On top of the abstract methods, which must be implemented, client code that override the following method must call the super-class method:
- initialize(String[])
- start()
- stop()

  • Field Details

    • defaultClientConfigPath

      public static final String defaultClientConfigPath
      See Also:
    • defaultEnginesConfigPath

      public static final String defaultEnginesConfigPath
      See Also:
    • defaultTelemetryDatabasePath

      public static final String defaultTelemetryDatabasePath
      See Also:
    • defaultScriptsFolderName

      public static final String defaultScriptsFolderName
      See Also:
    • defaultPluginsFolderName

      public static final String defaultPluginsFolderName
      See Also:
    • coreOptions

      protected CoreOptions coreOptions
      A reference to core options that will be used when the JEB core context is instantiated in start(). Clients which decide to provide non-standard options should set this field before calling start().
    • args

      protected String[] args
    • scriptpath

      protected String scriptpath
    • inputpath

      protected String inputpath
    • basicChecksPassed

      protected boolean basicChecksPassed
    • ugerrstr

      protected String ugerrstr
    • CLIENT_RUNNING_FILENAME_PREFIX

      public static final String CLIENT_RUNNING_FILENAME_PREFIX
      See Also:
    • INSTALLER_LOCK_FILENAME

      public static final String INSTALLER_LOCK_FILENAME
      See Also:
  • Constructor Details

    • AbstractClientContext

      protected AbstractClientContext()
  • Method Details

    • checkRunningInstaller

      public boolean checkRunningInstaller()
    • initialize

      public void initialize(String[] argv)
    • start

      public void start() throws JebException
      Install update, if any. Allow the display of client-specific material such as: EULA, changelog, etc. If loating, initialize the floating client. Performs a license check for release builds. If not a controller, initialize a JEB core and engines.
      Throws:
      JebException
    • stop

      public void stop()
    • assignCommandlineArguments

      protected void assignCommandlineArguments(String[] argv)
      Initialize the |configpath| and |inputpath|attributes.
      Parameters:
      argv -
    • getArguments

      public String[] getArguments()
      Description copied from interface: IClientContext
      Get the input arguments provided to this client context. The returned array depends on how the context was instantiated and called.
      Specified by:
      getArguments in interface IClientContext
      Returns:
      an array (possibly empty) or null if arguments are irrelevant in the current context
    • getInputpath

      public String getInputpath()
    • getScriptpath

      public String getScriptpath()
    • getNetworkUtility

      public Net getNetworkUtility()
    • getPropertyDefinitionManager

      public IPropertyDefinitionManager getPropertyDefinitionManager()
    • getPropertyManager

      public IPropertyManager getPropertyManager()
    • getConfiguration

      public org.apache.commons.configuration2.Configuration getConfiguration()
    • getTelemetry

      public ITelemetryDatabase getTelemetry()
    • isDevelopmentMode

      public boolean isDevelopmentMode()
    • setDevelopmentMode

      public void setDevelopmentMode(boolean enabled)
    • getLogLevel

      public int getLogLevel()
    • setLogLevel

      public void setLogLevel(int level)
    • getUuid

      public final long getUuid()
    • getPreferredLanguage

      public final String getPreferredLanguage()
    • setPreferredLanguage

      public final void setPreferredLanguage(String language)
    • shouldCheckUpdates

      public final boolean shouldCheckUpdates()
    • getUpdateChannel

      public final int getUpdateChannel()
    • setUpdateChannel

      public final void setUpdateChannel(int channel)
    • getLatestAvailableUpdate

      public final Version getLatestAvailableUpdate()
    • setLatestAvailableUpdate

      public final void setLatestAvailableUpdate(Version version)
    • shouldCheckPublicAnnouncements

      public final boolean shouldCheckPublicAnnouncements()
    • getProxyString

      public final String getProxyString()
    • setProxyString

      public final void setProxyString(String strProxyinfo)
    • getLastPublicAnnouncementId

      public final int getLastPublicAnnouncementId()
    • setLastPublicAnnouncementId

      public final void setLastPublicAnnouncementId(int id)
    • isHeadless

      public boolean isHeadless()
    • checkUpdate

      public abstract boolean checkUpdate()
      Not called locally: it is entirely up to the client to implement and decide who calls this method.
    • displayEula

      public abstract boolean displayEula(String eula)
      Called from start().
    • displayDemoInformation

      public abstract void displayDemoInformation(String demoInfo)
      Called from start().
    • onUpdatedSoftware

      public abstract void onUpdatedSoftware(String changelist, Version oldVersion)
      Notify a concrete client that a new version of JEB is being run for the first time.

      Called from start().

      Parameters:
      changelist - an optional change log
      oldVersion - the last version of JEB that was run (note: the current version is always available as a static public field)
    • retrieveLicenseKey

      public abstract String retrieveLicenseKey(String licdata)
      Called from start().
    • notifySupportExpired

      public abstract void notifySupportExpired()
      Called from start().
    • setupController

      public abstract boolean setupController()
      Called from start().
    • notifyFloatingClient

      public abstract void notifyFloatingClient(ControllerNotification notification)
      May be called from anywhere, any thread.
    • generateLicenseInformation

      public static final String generateLicenseInformation()
    • ping

      public final int ping(int downloadOrder, int clientChannel, SoftwareBuildInfo sbi, IProgressCallback progressCallback, boolean verbose)
      Ping the JEB update server, and optionally download a JEB update on a compatible update channel.
      Parameters:
      downloadOrder - orders:
      • 0= no download (pure ping)
      • 1=soft download (download only if not a major version bump; else a code 3 may be returned if an update is available; the client must call this method once more with downloadOrder=2 to download the files)
      • 2= always download
      clientChannel - current client channel, ie maximum allowed channel a build must confirm to; see Version for a list of available channels
      sbi - optional information about the update
      progressCallback - optional callback, used if the update package is to be downloaded
      verbose - if true, messages are logged; if false, only important messages are logged
      Returns:
      return values are:
      • -2: error, corrupt update
      • -1: error, unknown
      • 0: up to date
      • 1: update available, but caller does not want to download
      • 2: update available and downloaded
      • 2: update available, not downloaded, (currently: the only reason is, it is a major update, eg v3 to v4) - use downloadOrder=2 to force the download and install
    • dumpUpdateToDisk

      public final void dumpUpdateToDisk(byte[] data, String password) throws IOException
      Throws:
      IOException
    • retrieveLatestPublicAnnouncement

      public final PublicAnnouncement retrieveLatestPublicAnnouncement()
    • getScriptsDirectory

      public final String getScriptsDirectory()
      Retrieve the JEB scripts directory path.
      Returns:
      never null, however, the path returned may not reference an existing directory
    • getScriptsDirfile

      public final File getScriptsDirfile()
      Retrieve and if necessary create the JEB scripts directory.
      Returns:
      the script directory
    • setScriptsDirectory

      public final void setScriptsDirectory(String folder)
    • getUsedMemory

      public long getUsedMemory()
      Description copied from interface: IClientContext
      Get the amount of memory currently used by JEB.
      Specified by:
      getUsedMemory in interface IClientContext
      Returns:
      used memory in bytes
    • getMaxMemory

      public long getMaxMemory()
      Description copied from interface: IClientContext
      Get the theoretical maximum amount of memory that JEB can allocate and use.
      Specified by:
      getMaxMemory in interface IClientContext
      Returns:
      total theoretical memory that JEB could use, in bytes
    • getProcessId

      public long getProcessId()
      Description copied from interface: IClientContext
      Retrieve the process id of the Java VM executing JEB.
      Specified by:
      getProcessId in interface IClientContext
      Returns:
      JEB's PID
    • logMemoryUsage

      public final void logMemoryUsage()
    • formatMemoryUsage

      public static String formatMemoryUsage()
    • formatProcessInfo

      public static String formatProcessInfo(boolean inclPid, boolean inclMeminfo, boolean inclTimes, boolean inclCmdline)
      Format various process information bits. Each bit is formatted on a single line.
      Parameters:
      inclPid -
      inclMeminfo -
      inclTimes -
      inclCmdline -
      Returns:
    • initializeEngines

      protected final void initializeEngines() throws JebException
      Initialize the core context and an engines context.
      Throws:
      JebException
    • getCoreContext

      public final ICoreContext getCoreContext()
      Get the JEB core instance. Should never be null unless an error happened in start() or the context is one of a floating controller.
      Returns:
    • getEnginesContext

      public final IEnginesContext getEnginesContext()
      Get the JEB engines instance. Should never be null unless an error happened in start() or the context is one of a floating controller.
      Specified by:
      getEnginesContext in interface IClientContext
      Returns:
      the primary engines context, possibly null if none was initialized
    • hasOpenedProject

      public final boolean hasOpenedProject()
    • getOpenedProject

      public final IRuntimeProject getOpenedProject()
      Retrieve the current project, if any. Same as getMainProject().
      Returns:
      may be null
    • closeOpenedProject

      public final boolean closeOpenedProject()
    • getMainProject

      public IRuntimeProject getMainProject()
      Specified by:
      getMainProject in interface IClientContext
      Returns:
      the main project or null
    • closeMainProject

      public boolean closeMainProject()
      Description copied from interface: IClientContext
      Convenience method used to close the main project (if any), that is, the first project of the first engines context managed by the JEB back-end. If no project is opened, this method will return false.
      Specified by:
      closeMainProject in interface IClientContext
      Returns:
      success indicator
    • open

      public IUnit open(String path) throws IOException
      Description copied from interface: IClientContext
      Convenience method used to create a JEB project (or retrieve the current project if one is opened), load a file artifact into the project, process it, and return the resulting top-level unit.

      If the input file is a JDB2 saved project, that project is opened and returned. The method will throw IllegalStateException if a project is already opened.

      Specified by:
      open in interface IClientContext
      Parameters:
      path - input file to be analyzed, or an existing project saved as a JDB2 database (*.jdb2)
      Returns:
      the top-level unit yielded from the analysis of the provided artifact; if the input path was a JDB2 project, the top-level unit of the first project's artifact is returned
      Throws:
      IOException - on IO error
    • getTransientStore

      public Map<Object,Object> getTransientStore()
      Description copied from interface: IClientContext
      Retrieve a reference to the transient store provided by this context. Clients may use this map to store context-level global objects. The store and its objects are not persisted with a project JDB2 database.

      Interface specifications for implementations:
      - Null keys are forbidden, null values are allowed
      - Insertion, retrieval and deletion are thread-safe
      - Iterating is not thread-safe
      - The insertion order is not guaranteed during iteration

      Specified by:
      getTransientStore in interface IClientContext
      Returns:
      a non-null read-write map
    • getControllerInterface

      public String getControllerInterface()
    • setControllerInterface

      public void setControllerInterface(String iface)
    • getControllerPort

      public int getControllerPort()
    • setControllerPort

      public void setControllerPort(int port)
    • getControllerProtocol

      public int getControllerProtocol()
    • setControllerProtocol

      public void setControllerProtocol(int protocol)
    • getControllerMessage

      public String getControllerMessage()