Search in sources :

Example 1 with Agent

use of aQute.remote.api.Agent in project bnd by bndtools.

the class RemoteTest method testSimple.

public void testSimple() throws Exception {
    LauncherSupervisor supervisor = new LauncherSupervisor();
    supervisor.connect("localhost", Agent.DEFAULT_PORT);
    assertNotNull(supervisor);
    Agent agent = supervisor.getAgent();
    assertNotNull(agent.getFramework());
    // Create stdin/stderr buffers
    // and redirect output
    StringBuffer stderr = new StringBuffer();
    StringBuffer stdout = new StringBuffer();
    supervisor.setStderr(stderr);
    supervisor.setStdout(stdout);
    supervisor.redirect(1);
    //
    // Install the bundle systemio
    //
    File f = IO.getFile("generated/biz.aQute.remote.test.systemio.jar");
    String sha = supervisor.addFile(f);
    BundleDTO bundle = agent.install(f.getAbsolutePath(), sha);
    //
    // Start the bundle and capture the output
    //
    String result = agent.start(bundle.id);
    assertNull(result, result);
    Thread.sleep(1000);
    assertEquals("Hello World", stdout.toString().trim());
    stdout.setLength(0);
    // Send input (will be consumed by the Activator.stop
    ByteArrayInputStream bin = new ByteArrayInputStream(new String("Input\n").getBytes());
    supervisor.setStdin(bin);
    // stop the bundle (will return input as uppercase)
    result = agent.stop(bundle.id);
    assertNull(result, result);
    Thread.sleep(1000);
    assertEquals("INPUT", stdout.toString().trim());
}
Also used : Agent(aQute.remote.api.Agent) ByteArrayInputStream(java.io.ByteArrayInputStream) LauncherSupervisor(aQute.remote.plugin.LauncherSupervisor) BundleDTO(org.osgi.framework.dto.BundleDTO) File(java.io.File)

Example 2 with Agent

use of aQute.remote.api.Agent in project bnd by bndtools.

the class AgentDispatcher method toAgent.

/**
	 * Create a new agent on an existing framework.
	 */
public static void toAgent(final Descriptor descriptor, DataInputStream in, DataOutputStream out) {
    // Check if the framework is active
    if (descriptor.framework.getState() != Bundle.ACTIVE) {
        throw new IllegalStateException("Framework " + descriptor.name + " is not active. (Stopped?)");
    }
    //
    // Get the bundle context
    //
    BundleContext context = descriptor.framework.getBundleContext();
    AgentServer as = new AgentServer(descriptor.name, context, descriptor.shaCache) {

        //
        // Override the close se we can remote it from the list
        //
        public void close() throws IOException {
            descriptor.servers.remove(this);
            super.close();
        }
    };
    //
    // Link up
    //
    Link<Agent, Supervisor> link = new Link<Agent, Supervisor>(Supervisor.class, as, in, out);
    as.setLink(link);
    link.open();
}
Also used : Supervisor(aQute.remote.api.Supervisor) Agent(aQute.remote.api.Agent) Link(aQute.remote.util.Link) BundleContext(org.osgi.framework.BundleContext)

Example 3 with Agent

use of aQute.remote.api.Agent in project bnd by bndtools.

the class RunSessionImpl method launch.

@Override
public int launch() throws Exception {
    try {
        supervisor = new LauncherSupervisor();
        supervisor.connect(dto.host, dto.agent);
        Agent agent = supervisor.getAgent();
        if (agent.isEnvoy())
            installFramework(agent, dto, properties);
        if (stdout != null)
            supervisor.setStdout(stdout);
        if (stderr != null)
            supervisor.setStderr(stderr);
        started.countDown();
        update(dto);
        int exitCode = supervisor.join();
        return exitCode;
    } catch (Exception e) {
        started.countDown();
        throw e;
    }
}
Also used : Agent(aQute.remote.api.Agent) IOException(java.io.IOException)

Example 4 with Agent

use of aQute.remote.api.Agent in project bnd by bndtools.

the class RemoteTest method testBRD.

/*
	 * Test if we can get the BundleRevisionDTOs
	 */
public void testBRD() throws Exception {
    LauncherSupervisor supervisor = new LauncherSupervisor();
    supervisor.connect("localhost", Agent.DEFAULT_PORT);
    assertNotNull(supervisor);
    Agent agent = supervisor.getAgent();
    assertNotNull(agent);
    List<BundleRevisionDTO> bundleRevisons = agent.getBundleRevisons();
    assertNotNull(bundleRevisons);
}
Also used : Agent(aQute.remote.api.Agent) BundleRevisionDTO(org.osgi.framework.wiring.dto.BundleRevisionDTO) LauncherSupervisor(aQute.remote.plugin.LauncherSupervisor)

Aggregations

Agent (aQute.remote.api.Agent)4 LauncherSupervisor (aQute.remote.plugin.LauncherSupervisor)2 Supervisor (aQute.remote.api.Supervisor)1 Link (aQute.remote.util.Link)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 BundleContext (org.osgi.framework.BundleContext)1 BundleDTO (org.osgi.framework.dto.BundleDTO)1 BundleRevisionDTO (org.osgi.framework.wiring.dto.BundleRevisionDTO)1