final ConnectionHandler getConnectionHandler() { return m_handler.getConnectionHandler(); }
DownloadHandleImpl(DownloadHandlerImpl handler, URL url) { m_handler = handler; m_url = url; m_file = new File(m_handler.getDataLocation(), getDownloadFileName()); m_handler.logDebug("Created download handle for %s in %s.", m_file.getName(), m_file.getPath()); }
private ExecutorService getExecutor() { return m_handler.getExecutorService(); } }
@BeforeClass public void setUpOnceAgain() throws Exception { File dataLocation = new File("generated"); m_200file = File.createTempFile("download", ".bin", dataLocation); m_200file.deleteOnExit(); int port = 8883; m_200url = new URL("http://localhost:" + port + "/" + m_200file.getName()); m_404url = new URL("http://localhost:" + port + "/error?status=404"); m_503url = new URL("http://localhost:" + port + "/error?status=503&retry=500"); DigestOutputStream dos = new DigestOutputStream(new FileOutputStream(m_200file), MessageDigest.getInstance("MD5")); for (int i = 0; i < 10000; i++) { dos.write(String.valueOf(System.currentTimeMillis()).getBytes()); dos.write(" Lorum Ipsum Lorum Ipsum Lorum Ipsum Lorum Ipsum Lorum Ipsum\n".getBytes()); } dos.close(); m_200digest = new String(dos.getMessageDigest().digest()); m_webServer = new TestWebServer(port, "/", dataLocation.getName()); m_webServer.addServlet(new TestErrorServlet(), "/error"); m_webServer.start(); m_agentContextImpl = mockAgentContext(); m_agentContext = m_agentContextImpl; BundleContext bc = mockBundleContext(); m_agentContextImpl.setHandler(EventsHandler.class, new EventsHandlerImpl(bc)); m_agentContextImpl.setHandler(ConnectionHandler.class, new ConnectionHandlerImpl()); m_agentContextImpl.setHandler(LoggingHandler.class, new LoggingHandlerImpl(bc, Levels.DEBUG)); m_agentContextImpl.setHandler(DownloadHandler.class, new DownloadHandlerImpl(dataLocation)); m_agentContextImpl.start(); replayTestMocks(); }
final void logWarning(String message, Throwable cause, Object... args) { m_handler.logWarning(message, cause, args); }
final void logDebug(String message, Object... args) { m_handler.logDebug(message, args); }
@BeforeClass public void setUp() throws Exception { m_agentContext = mockAgentContext(); m_agentContext.setHandler(DownloadHandler.class, new DownloadHandlerImpl(m_agentContext.getWorkDir())); m_agentContext.setHandler(ConnectionHandler.class, new ConnectionHandlerImpl()); replayTestMocks(); m_agentContext.start(); }
@Override public Future<DownloadResult> start(DownloadProgressListener listener) { if (m_future != null && !m_future.isDone()) { throw new IllegalStateException("Can not call start on a handle that is already started!"); } m_future = null; ExecutorService executor = getExecutor(); if (executor.isShutdown()) { m_handler.logWarning("Cannot start download, executor is shut down!"); } else { m_future = executor.submit(new DownloadCallableImpl(this, listener, m_file)); } return m_future; }
/** * Called by our {@link DependencyTrackerImpl} when all dependencies are satisfied. */ public void componentStarted(BundleContext context) throws Exception { final File bundleDataArea = context.getDataFile(""); m_agentContext = new AgentContextImpl(bundleDataArea); m_agentContext.setHandler(LoggingHandler.class, new LoggingHandlerImpl(context)); m_agentContext.setHandler(ConfigurationHandler.class, new ConfigurationHandlerImpl(context)); m_agentContext.setHandler(EventsHandler.class, new EventsHandlerImpl(context)); m_agentContext.setHandler(ScheduledExecutorService.class, m_executorService); m_agentContext.setHandler(DownloadHandler.class, new DownloadHandlerImpl(bundleDataArea)); m_agentContext.setHandler(DeploymentHandler.class, new DeploymentHandlerImpl(context, m_packageAdmin)); m_agentContext.setHandler(AgentUpdateHandler.class, new AgentUpdateHandlerImpl(context)); m_agentContext.setHandler(FeedbackHandler.class, new FeedbackHandlerImpl()); IdentificationHandler identificationHandler = (m_identificationHandler != null) ? m_identificationHandler : new IdentificationHandlerImpl(); m_agentContext.setHandler(IdentificationHandler.class, identificationHandler); DiscoveryHandler discoveryHandler = (m_discoveryHandler != null) ? m_discoveryHandler : new DiscoveryHandlerImpl(); m_agentContext.setHandler(DiscoveryHandler.class, discoveryHandler); ConnectionHandler connectionHandler = (m_connectionHandler != null) ? m_connectionHandler : new ConnectionHandlerImpl(); m_agentContext.setHandler(ConnectionHandler.class, connectionHandler); m_agentContext.addComponent(new EventLoggerImpl(context)); // Lastly, inject the (custom) controller for this agent... m_agentContext.setController(m_controller); m_agentContext.start(); m_agentControlRegistration = context.registerService(AgentControl.class.getName(), new AgentControlImpl(m_agentContext), null); }