Class Browser

java.lang.Object
com.tccc.kos.core.service.browser.Browser

public class Browser extends Object
A logical browser control object. This can be used to navigate a browser to an arbitrary url. A Browser can be created independent of an actual browser instance as this is simply a logical representation of a browser. Actual browser instances connect to BrowserService where they are linked to Browser objects with the same BrowserId. Once a BrowserSession connects and is online, the last navigation event sent to the Browser will be forwarded to the browser instance.

Browser objects can represent actual browser instances running on other nodes. If the nodes are powered off then the browser instances won't be available but the Browser object will still be usable, it will simply be offline. It's possible for a BrowserSession to be connected to a Browser but still be offline depending on the implementation of the BrowserSession. For example, the chrome adapter used to control the chrome browser can be running while chrome itself is not. This is reflected in the online flag.

Every Browser has a default host and port. These defaults will be used any time a url is specified without a scheme (http://host:port). This allows the Browser to be configured once at startup and all urls without scheme data will automatically be sent to the default host. This is an easy way to eliminate the need for application code to understand how a cluster of nodes is wired up and how to get access to host/port data. Instead, user logic can simply construct path-only urls and let the Browser fill in the scheme. By default, all Browser objects use the local node as the default host.

Since:
1.0
Version:
2023-02-26
  • Method Details

    • connect

      public void connect(BrowserSession session)
      Called to link a BrowserSession to the Browser . This should be followed by a call to online() when the browser is actually available to show content.
      Parameters:
      session - the session to back this browser
    • disconnect

      public void disconnect(BrowserSession session)
      Called to unlink a BrowserSession from the Browser . Once called, the Browser will no longer be connected to an actual browser instance and this Browser object will be marked offline.
      Parameters:
      session - the session to disconnect
    • online

      public void online()
      Called by a BrowserSession to indicate that it can now display content on a browser instance. This will force the most recent url to be sent to the session.
    • offline

      public void offline()
      Called by BrowserSession to indicate that it can no longer display content on a browser instance. No navigation events will be sent to the session while it is offline.
    • isOnline

      public boolean isOnline()
      Return true if the actual browser is online and available for navigation. It is possible for a Browser to be connected but be offline and unable to navigate.
    • getDefaultHost

      public String getDefaultHost()
      Return the default hostname to use for urls that don't specify a hostname.
    • setDefaultNode

      public void setDefaultNode(NodeId nodeId)
      Set the default node to use for urls that don't specify a hostname. This leverages NodeResolverService to resolve the default nodeId to an address.
      Parameters:
      nodeId - the node to point the browser to
    • getDefaultPort

      public int getDefaultPort()
      Return the default port to use for urls that don't specify a hostname/port.
    • setDefaultPort

      public void setDefaultPort(int port)
      Set the default port to use for urls that don't specify a hostname/port.
      Parameters:
      port - the default port to use
    • goToUrl

      public void goToUrl(String url, boolean redirect)
      Loads the specified URL in the browser. If the redirect flag is true, the navigation is performed through a redirect.
      Parameters:
      url - the URL to show
      redirect - if true, navigate using a redirect
    • getService

      public BrowserService getService()
    • getId

      public BrowserId getId()
    • getLastUrl

      public String getLastUrl()