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());
}
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();
}
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;
}
}
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);
}
Aggregations