Class AgentServer

java.lang.Object
aQute.remote.agent.AgentServer
All Implemented Interfaces:
Agent, Closeable, AutoCloseable, EventListener, org.osgi.framework.FrameworkListener

public class AgentServer extends Object implements Agent, Closeable, org.osgi.framework.FrameworkListener
Implementation of the Agent. This implementation implements the Agent interfaces and communicates with a Supervisor interfaces.
  • Constructor Details

    • AgentServer

      public AgentServer(String name, org.osgi.framework.BundleContext context, File cache)
      An agent server is based on a context and takes a name and cache directory
      Parameters:
      name - the name of the agent's framework
      context - a bundle context of the framework
      cache - the directory for caching
    • AgentServer

      public AgentServer(String name, org.osgi.framework.BundleContext context, File cache, StartLevelRuntimeHandler startlevels)
  • Method Details

    • getFramework

      public FrameworkDTO getFramework() throws Exception
      Get the framework's DTO
      Specified by:
      getFramework in interface Agent
      Throws:
      Exception
    • installWithData

      public BundleDTO installWithData(String location, byte[] data) throws Exception
      Description copied from interface: Agent
      Install or update a bundle from the specified byte array instance.

      This method does check if there is any existing bundle with the specified location identifier. If found, the existing bundle gets updated with the specified byte array instance. Otherwise, a new bundle gets installed with the specified byte array instance.

      Specified by:
      installWithData in interface Agent
      Parameters:
      location - The bundle location (cannot be null)
      data - The byte array instance from which this bundle will be read (cannot be null)
      Returns:
      A Bundle DTO (cannot be null)
      Throws:
      Exception - if the bundle cannot be installed or updated
    • install

      public BundleDTO install(String location, String sha) throws Exception
      Description copied from interface: Agent
      Install a new bundle at the given bundle location. The SHA identifies the file and should be retrievable through Supervisor.getFile(String) .
      Specified by:
      install in interface Agent
      Parameters:
      location - the bundle location
      sha - the sha of the bundle's JAR
      Returns:
      A Bundle DTO
      Throws:
      Exception
    • installFromURL

      public BundleDTO installFromURL(String location, String url) throws Exception
      Description copied from interface: Agent
      Install a new bundle at the given location using a url to get the stream.

      NOTICE: this method makes assumptions about the target e.g. that it will be able to use out-of-band communication to read from the URL and have the necessary url handlers to open the URL stream.

      Specified by:
      installFromURL in interface Agent
      Parameters:
      location - the bundle location
      url - url of the bundle that can retrived using url.openStream()
      Returns:
      A bundle DTO
      Throws:
      Exception
    • start

      public String start(long... ids)
      Description copied from interface: Agent
      Start a number of bundles
      Specified by:
      start in interface Agent
      Parameters:
      ids - the bundle ids
      Returns:
      any errors that occurred
    • stop

      public String stop(long... ids)
      Description copied from interface: Agent
      Stop a number of bundles
      Specified by:
      stop in interface Agent
      Parameters:
      ids - the bundle ids
      Returns:
      any errors that occurred
    • uninstall

      public String uninstall(long... ids)
      Description copied from interface: Agent
      Uninstall a number of bundles
      Specified by:
      uninstall in interface Agent
      Parameters:
      ids - the bundle ids
      Returns:
      any errors that occurred
    • update

      public String update(Map<String,String> bundles) throws InterruptedException
      Description copied from interface: Agent
      Update the bundles in the framework. Each agent compares this map against a map of installed bundles. The map maps a bundle location to SHA. Any differences are reflected in the installed bundles. That is, a change in the SHA will update, a new entry will install, and a removed entry will uninstall. This is the preferred way to keep the remote framework synchronized since it is idempotent.
      Specified by:
      update in interface Agent
      Parameters:
      bundles - the bundles to update
      Throws:
      InterruptedException
    • update

      public String update(long id, String sha) throws Exception
      Description copied from interface: Agent
      Updates a single bundle by id in the framework. The SHA identifies the file and should be retrievable through Supervisor.getFile(String)
      Specified by:
      update in interface Agent
      Parameters:
      id - the bundle id
      sha - the sha of the bundle
      Returns:
      any errors that occurred
      Throws:
      Exception
    • updateFromURL

      public String updateFromURL(long id, String url) throws Exception
      Description copied from interface: Agent
      Updates a single bundle from a url

      NOTICE: this method makes assumptions about the target e.g. that it will be able to use out-of-band communication to read from the URL and have the necessary url handlers to open the URL stream.

      Specified by:
      updateFromURL in interface Agent
      Parameters:
      id - bundle to update
      url - location of bundle contents
      Returns:
      any errors that occurred
      Throws:
      Exception
    • redirect

      public boolean redirect(int port) throws Exception
      Description copied from interface: Agent
      Redirect I/O from port. Port can be Agent.CONSOLE, Agent.COMMAND_SESSION, Agent.NONE, or a TCP Telnet port.
      Specified by:
      redirect in interface Agent
      Parameters:
      port - the port to redirect from
      Returns:
      if the redirection was changed
      Throws:
      Exception
    • stdin

      public boolean stdin(String s) throws Exception
      Description copied from interface: Agent
      Send a text to the potentially redirected stdin stream so that remotely executing code will read it from an InputStream.
      Specified by:
      stdin in interface Agent
      Parameters:
      s - text that should be read as input
      Returns:
      true if this was redirected
      Throws:
      Exception
    • shell

      public String shell(String cmd) throws Exception
      Description copied from interface: Agent
      Execute a remote command on Gogo (if present) and return the result.
      Specified by:
      shell in interface Agent
      Parameters:
      cmd - the command to execute
      Returns:
      the result
      Throws:
      Exception
    • setSupervisor

      public void setSupervisor(Supervisor remote)
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • abort

      public void abort() throws Exception
      Description copied from interface: Agent
      Abort the remote agent. The agent should send an event back and die. This is an async method.
      Specified by:
      abort in interface Agent
      Throws:
      Exception
    • frameworkEvent

      public void frameworkEvent(org.osgi.framework.FrameworkEvent event)
      Specified by:
      frameworkEvent in interface org.osgi.framework.FrameworkListener
    • setRemote

      public void setRemote(Supervisor supervisor)
    • isEnvoy

      public boolean isEnvoy()
      Description copied from interface: Agent
      An Envoy is an agent that can install a framework (well, -runpath) and launch it with an Agent. An envoy can only handle this method and Agent.createFramework(String, Collection, Map) so other methods should not be called. This rather awkward model is necessary so that we do not have to reconnect to the actual agent.
      Specified by:
      isEnvoy in interface Agent
      Returns:
      true if this is a limited envoy, otherwise true for a true Agent.
    • getSystemProperties

      public Map<String,String> getSystemProperties() throws Exception
      Description copied from interface: Agent
      Get the remote's system's System properties
      Specified by:
      getSystemProperties in interface Agent
      Returns:
      the remote systems properties
      Throws:
      Exception
    • createFramework

      public boolean createFramework(String name, Collection<String> runpath, Map<String,Object> properties) throws Exception
      Description copied from interface: Agent
      This method is only implemented in the Envoy (the pre-Agent). It is meant to install a -runpath before the framework runs. An Envoy can actally created multiple independent frameworks. If this framework already existed, and the given parameters are identical, that framework will be used for the aget that will take over. Otherwise the current framework is stopped and a new framework is started.
      Specified by:
      createFramework in interface Agent
      Parameters:
      name - the name of the framework
      runpath - the runpath the install
      properties - the framework properties
      Returns:
      if this created a new framework
      Throws:
      Exception
    • getSupervisor

      public Supervisor getSupervisor()
    • setLink

      public void setLink(Link<Agent,Supervisor> link)
    • ping

      public boolean ping()
      Description copied from interface: Agent
      Ping the remote agent to see if it is still alive.
      Specified by:
      ping in interface Agent
    • getContext

      public org.osgi.framework.BundleContext getContext()
    • refresh

      public void refresh(boolean async) throws InterruptedException
      Throws:
      InterruptedException
    • getBundles

      public List<BundleDTO> getBundles(long... bundleId) throws Exception
      Description copied from interface: Agent
      Get the Bundles for the given ids. If no ids are given, all bundles are returned.
      Specified by:
      getBundles in interface Agent
      Throws:
      Exception
    • getBundleRevisons

      public List<org.osgi.framework.wiring.dto.BundleRevisionDTO> getBundleRevisons(long... bundleId) throws Exception
      Return the bundle revisions
      Specified by:
      getBundleRevisons in interface Agent
      Throws:
      Exception