Package aQute.remote.agent
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.
-
Field Summary
Fields inherited from interface aQute.remote.api.Agent
AGENT_SERVER_PORT_KEY, COMMAND_SESSION, CONSOLE, DEFAULT_PORT, NONE, PORT_P -
Constructor Summary
ConstructorsConstructorDescriptionAgentServer(String name, org.osgi.framework.BundleContext context, File cache) An agent server is based on a context and takes a name and cache directoryAgentServer(String name, org.osgi.framework.BundleContext context, File cache, StartLevelRuntimeHandler startlevels) -
Method Summary
Modifier and TypeMethodDescriptionvoidabort()Abort the remote agent.voidclose()booleancreateFramework(String name, Collection<String> runpath, Map<String, Object> properties) This method is only implemented in the Envoy (the pre-Agent).voidframeworkEvent(org.osgi.framework.FrameworkEvent event) List<org.osgi.framework.wiring.dto.BundleRevisionDTO>getBundleRevisons(long... bundleId) Return the bundle revisionsgetBundles(long... bundleId) Get the Bundles for the given ids.org.osgi.framework.BundleContextGet the framework's DTOGet the remote's system's System propertiesInstall a new bundle at the given bundle location.installFromURL(String location, String url) Install a new bundle at the given location using a url to get the stream.installWithData(String location, byte[] data) Install or update a bundle from the specified byte array instance.booleanisEnvoy()An Envoy is an agent that can install a framework (well, -runpath) and launch it with an Agent.booleanping()Ping the remote agent to see if it is still alive.booleanredirect(int port) Redirect I/O from port.voidrefresh(boolean async) voidsetLink(Link<Agent, Supervisor> link) voidsetRemote(Supervisor supervisor) voidsetSupervisor(Supervisor remote) Execute a remote command on Gogo (if present) and return the result.start(long... ids) Start a number of bundlesbooleanSend a text to the potentially redirected stdin stream so that remotely executing code will read it from an InputStream.stop(long... ids) Stop a number of bundlesuninstall(long... ids) Uninstall a number of bundlesUpdates a single bundle by id in the framework.Update the bundles in the framework.updateFromURL(long id, String url) Updates a single bundle from a url
-
Constructor Details
-
AgentServer
An agent server is based on a context and takes a name and cache directory- Parameters:
name- the name of the agent's frameworkcontext- a bundle context of the frameworkcache- the directory for caching
-
AgentServer
public AgentServer(String name, org.osgi.framework.BundleContext context, File cache, StartLevelRuntimeHandler startlevels)
-
-
Method Details
-
getFramework
Get the framework's DTO- Specified by:
getFrameworkin interfaceAgent- Throws:
Exception
-
installWithData
Description copied from interface:AgentInstall or update a bundle from the specified byte array instance.This method does check if there is any existing bundle with the specified
locationidentifier. 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:
installWithDatain interfaceAgent- Parameters:
location- The bundle location (cannot benull)data- The byte array instance from which this bundle will be read (cannot benull)- Returns:
- A Bundle DTO (cannot be
null) - Throws:
Exception- if the bundle cannot be installed or updated
-
install
Description copied from interface:AgentInstall a new bundle at the given bundle location. The SHA identifies the file and should be retrievable throughSupervisor.getFile(String). -
installFromURL
Description copied from interface:AgentInstall 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:
installFromURLin interfaceAgent- Parameters:
location- the bundle locationurl- url of the bundle that can retrived using url.openStream()- Returns:
- A bundle DTO
- Throws:
Exception
-
start
Description copied from interface:AgentStart a number of bundles -
stop
Description copied from interface:AgentStop a number of bundles -
uninstall
Description copied from interface:AgentUninstall a number of bundles -
update
Description copied from interface:AgentUpdate 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:
updatein interfaceAgent- Parameters:
bundles- the bundles to update- Throws:
InterruptedException
-
update
Description copied from interface:AgentUpdates a single bundle by id in the framework. The SHA identifies the file and should be retrievable throughSupervisor.getFile(String) -
updateFromURL
Description copied from interface:AgentUpdates a single bundle from a urlNOTICE: 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:
updateFromURLin interfaceAgent- Parameters:
id- bundle to updateurl- location of bundle contents- Returns:
- any errors that occurred
- Throws:
Exception
-
redirect
Description copied from interface:AgentRedirect I/O from port. Port can beAgent.CONSOLE,Agent.COMMAND_SESSION,Agent.NONE, or a TCP Telnet port. -
stdin
Description copied from interface:AgentSend a text to the potentially redirected stdin stream so that remotely executing code will read it from an InputStream. -
shell
Description copied from interface:AgentExecute a remote command on Gogo (if present) and return the result. -
setSupervisor
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
abort
Description copied from interface:AgentAbort the remote agent. The agent should send an event back and die. This is an async method. -
frameworkEvent
public void frameworkEvent(org.osgi.framework.FrameworkEvent event) - Specified by:
frameworkEventin interfaceorg.osgi.framework.FrameworkListener
-
setRemote
-
isEnvoy
public boolean isEnvoy()Description copied from interface:AgentAn Envoy is an agent that can install a framework (well, -runpath) and launch it with an Agent. An envoy can only handle this method andAgent.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. -
getSystemProperties
Description copied from interface:AgentGet the remote's system's System properties- Specified by:
getSystemPropertiesin interfaceAgent- Returns:
- the remote systems properties
- Throws:
Exception
-
createFramework
public boolean createFramework(String name, Collection<String> runpath, Map<String, Object> properties) throws ExceptionDescription copied from interface:AgentThis 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:
createFrameworkin interfaceAgent- Parameters:
name- the name of the frameworkrunpath- the runpath the installproperties- the framework properties- Returns:
- if this created a new framework
- Throws:
Exception
-
getSupervisor
-
setLink
-
ping
public boolean ping()Description copied from interface:AgentPing the remote agent to see if it is still alive. -
getContext
public org.osgi.framework.BundleContext getContext() -
refresh
- Throws:
InterruptedException
-
getBundles
Description copied from interface:AgentGet the Bundles for the given ids. If no ids are given, all bundles are returned.- Specified by:
getBundlesin interfaceAgent- Throws:
Exception
-
getBundleRevisons
public List<org.osgi.framework.wiring.dto.BundleRevisionDTO> getBundleRevisons(long... bundleId) throws Exception Return the bundle revisions- Specified by:
getBundleRevisonsin interfaceAgent- Throws:
Exception
-