ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1513102 [3/3] - in /ace/sandbox/bramk: cnf/ext/ cnf/localrepo/ cnf/localrepo/javax.servlet/ cnf/localrepo/org.eclipse.jetty.continuation/ cnf/localrepo/org.eclipse.jetty.http/ cnf/localrepo/org.eclipse.jetty.io/ cnf/localrepo/org.eclipse.j...
Date Mon, 12 Aug 2013 10:58:52 GMT
Added: ace/sandbox/bramk/cnf/localrepo/javax.servlet/javax.servlet-2.5.0.jar
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/cnf/localrepo/javax.servlet/javax.servlet-2.5.0.jar?rev=1513102&view=auto
==============================================================================
Binary file - no diff available.

Propchange: ace/sandbox/bramk/cnf/localrepo/javax.servlet/javax.servlet-2.5.0.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.continuation/org.eclipse.jetty.continuation-7.6.9.jar
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.continuation/org.eclipse.jetty.continuation-7.6.9.jar?rev=1513102&view=auto
==============================================================================
Binary file - no diff available.

Propchange: ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.continuation/org.eclipse.jetty.continuation-7.6.9.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.http/org.eclipse.jetty.http-7.6.9.jar
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.http/org.eclipse.jetty.http-7.6.9.jar?rev=1513102&view=auto
==============================================================================
Binary file - no diff available.

Propchange: ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.http/org.eclipse.jetty.http-7.6.9.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.io/org.eclipse.jetty.io-7.6.9.jar
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.io/org.eclipse.jetty.io-7.6.9.jar?rev=1513102&view=auto
==============================================================================
Binary file - no diff available.

Propchange: ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.io/org.eclipse.jetty.io-7.6.9.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.jmx/org.eclipse.jetty.jmx-7.6.9.jar
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.jmx/org.eclipse.jetty.jmx-7.6.9.jar?rev=1513102&view=auto
==============================================================================
Binary file - no diff available.

Propchange: ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.jmx/org.eclipse.jetty.jmx-7.6.9.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.security/org.eclipse.jetty.security-7.6.9.jar
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.security/org.eclipse.jetty.security-7.6.9.jar?rev=1513102&view=auto
==============================================================================
Binary file - no diff available.

Propchange: ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.security/org.eclipse.jetty.security-7.6.9.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.server/org.eclipse.jetty.server-7.6.9.jar
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.server/org.eclipse.jetty.server-7.6.9.jar?rev=1513102&view=auto
==============================================================================
Binary file - no diff available.

Propchange: ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.server/org.eclipse.jetty.server-7.6.9.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.servlet/org.eclipse.jetty.servlet-7.6.9.jar
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.servlet/org.eclipse.jetty.servlet-7.6.9.jar?rev=1513102&view=auto
==============================================================================
Binary file - no diff available.

Propchange: ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.servlet/org.eclipse.jetty.servlet-7.6.9.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.util/org.eclipse.jetty.util-7.6.9.jar
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.util/org.eclipse.jetty.util-7.6.9.jar?rev=1513102&view=auto
==============================================================================
Binary file - no diff available.

Propchange: ace/sandbox/bramk/cnf/localrepo/org.eclipse.jetty.util/org.eclipse.jetty.util-7.6.9.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: ace/sandbox/bramk/org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/BasicAgentTest.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/BasicAgentTest.java?rev=1513102&r1=1513101&r2=1513102&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/BasicAgentTest.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/BasicAgentTest.java Mon Aug 12 10:58:50 2013
@@ -18,17 +18,7 @@
  */
 package org.apache.ace.agent.itest;
 
-import java.util.Hashtable;
-import java.util.Map;
-
-import junit.framework.Assert;
-
-import org.apache.ace.agent.Agent;
-import org.apache.ace.agent.AgentFactory;
-import org.apache.ace.agent.Constants;
 import org.apache.ace.it.IntegrationTestBase;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
 
 /**
  * Integration test for Management Agent Configuration
@@ -36,37 +26,7 @@ import org.osgi.framework.ServiceReferen
  */
 public class BasicAgentTest extends IntegrationTestBase {
 
-	public void testOneAgentConfiguration() throws Exception {
-
-		// agent factory should be up
-		AgentFactory agentFactory = getService(AgentFactory.class);
-		Assert.assertNotNull(agentFactory);
-
-		assertAgentDown("007");
-
-		// configure an agent
-		Map<String, String> config = new Hashtable<String, String>();
-		config.put("verbose", "true");
-		config.put(Constants.CONFIG_IDENTIFICATION_KEY, "007");
-		config.put(Constants.CONFIG_SERVERURL_KEY, "http://localhost:8080");
-		config.put("logstores", "auditlog");
-		config.put("authType", "NONE");
-		agentFactory.updated(config);
-
-        assertAgentUp("007");
-	}
-
-	private void assertAgentUp(String agentId) throws InvalidSyntaxException {
-		String agentFilter = "(agent=" + agentId + ")";
-		ServiceReference[] references = m_bundleContext
-				.getAllServiceReferences(Agent.class.getName(), agentFilter);
-		assertNotNull(references);
-	}
-
-	private void assertAgentDown(String agentId) throws InvalidSyntaxException {
-		String agentFilter = "(agent=" + agentId + ")";
-		ServiceReference[] references = m_bundleContext
-				.getAllServiceReferences(Agent.class.getName(), agentFilter);
-		assertNull(references);
-	}
+    public void testOneAgentConfiguration() throws Exception {
+        assertNull(null);
+    }
 }

Modified: ace/sandbox/bramk/org.apache.ace.agent/.classpath
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/.classpath?rev=1513102&r1=1513101&r2=1513102&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/.classpath (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/.classpath Mon Aug 12 10:58:50 2013
@@ -1,7 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
 	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="test"/>
 	<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.testng.TESTNG_CONTAINER"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>

Modified: ace/sandbox/bramk/org.apache.ace.agent/bnd.bnd
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/bnd.bnd?rev=1513102&r1=1513101&r2=1513102&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/bnd.bnd (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/bnd.bnd Mon Aug 12 10:58:50 2013
@@ -1,78 +1,30 @@
-Bundle-Activator: org.apache.ace.agent.impl.Activator
+Bundle-Name: Apache ACE Agent
+Bundle-Description: Implementation of the Apache ACE Agent
 Bundle-Version: 1.0.0
 
 -buildpath: osgi.core,\
-	osgi.cmpn,\
-	org.apache.felix.dependencymanager,\
-	org.apache.felix.deploymentadmin,\
-	org.apache.ace.log.target;version=latest,\
-	org.apache.ace.log.target.store.impl;version=latest,\
-	org.apache.ace.range.api;version=latest,\
-	org.apache.ace.log.api;version=latest,\
-	org.apache.commons.codec
+	javax.servlet;version=2.5.0,\
+	org.eclipse.jetty.http;version=7.6.9,\
+	org.eclipse.jetty.io;version=7.6.9,\
+	org.eclipse.jetty.jmx;version=7.6.9,\
+	org.eclipse.jetty.security;version=7.6.9,\
+	org.eclipse.jetty.server;version=7.6.9,\
+	org.eclipse.jetty.servlet;version=7.6.9,\
+	org.eclipse.jetty.util;version=7.6.9,\
+	org.eclipse.jetty.continuation;version=7.6.9.v20130131,\
+	org.apache.felix.deploymentadmin;version=0.9.4
 
 -sources false
 
 #
-# Embedding all required api and implementation packages to ensure that the
-# Management Agent can run in any plain vanilla framework.
 #	
-Private-Package: org.apache.ace.agent.eventlogging,\
-	org.apache.ace.agent,\
-	org.apache.ace.agent.versions,\
-	org.apache.ace.log.util,\
-	org.apache.ace.log,\
-	org.apache.ace.log.target.store,\
-	org.apache.ace.agent.spi,\
+Private-Package: org.apache.ace.agent.deployment.impl,\
 	org.apache.ace.agent.impl,\
-	org.apache.ace.agent.connection,\
-	org.apache.ace.agent.download,\
-	org.apache.ace.agent.update,\
-	org.apache.ace.agent.logging,\
-	org.apache.ace.agent.deployment,\
-	org.apache.ace.agent.discovery,\
-	org.apache.ace.range,\
-	org.apache.ace.agent.identification,\
-	org.apache.felix.dm,\
-	org.apache.felix.dm.impl,\
-	org.apache.felix.dm.impl.dependencies,\
-	org.apache.felix.dm.impl.index,\
-	org.apache.felix.dm.impl.metatype,\
-	org.apache.felix.dm.tracker,\
-	org.apache.felix.deploymentadmin;-split-package:=first,\
-	org.apache.felix.deploymentadmin.spi;-split-package:=first,\
-	org.osgi.util.tracker;-split-package:=first,\
-	org.apache.commons.codec;-split-package:=first,\
-	org.apache.commons.codec.binary;-split-package:=first
-	
-# 
-# Exporting deploymentadmin and (some) compendium services so resource processors 
-# can wire up to the management agent. As bnd will generate the appropriate imports
-# this should not lead to any conflicts with deployment packages.
-#
-# We could consider exposing all compendium packages by default in this way?
-#
-Export-Package: org.osgi.service.deploymentadmin;version=1.0;-split-package:=first,\
-	org.osgi.service.deploymentadmin.spi;version=1.0;-split-package:=first,\
-	org.osgi.service.cm;version=1.3;-split-package:=first,\
-	org.osgi.service.event;version=1.2;-split-package:=first,\
-	org.osgi.service.log;version=1.3;-split-package:=first,\
-	org.osgi.service.metatype;-split-package:=first,\
-	org.apache.ace.agent,\
-	org.apache.ace.agent.spi,\
-	org.apache.felix.dm
-    
+	org.apache.ace.agent.download
+
 # 
-# Make sure the apropriate imports are generated for the exported packages.
 #
-Import-Package: !org.apache.felix.shell,\
-	!org.eclipse.osgi.framework.console,\
-	*
-		
-Bundle-Name: Apache ACE Agent
-Bundle-Description: Implementation of the Apache ACE Agent
--runfw: org.apache.felix.framework;version='[4.0.3,4.0.3]'
--runee: JavaSE-1.6
--runbundles: org.apache.felix.gogo.command,\
-	org.apache.felix.gogo.runtime,\
-	org.apache.felix.gogo.shell
\ No newline at end of file
+Import-Package: *
+Export-Package: org.apache.ace.agent,\
+	org.apache.ace.agent.download,\
+	org.apache.ace.agent.deployment
\ No newline at end of file

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/AgentConfiguration.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/AgentConfiguration.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/AgentConfiguration.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/AgentConfiguration.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,101 @@
+package org.apache.ace.agent;
+
+import java.util.Map;
+import java.util.logging.Level;
+
+/**
+ * The agent's persisted configuration. External launchers can override the default values through system properties
+ * when the agent starts. However, once a configuration value has been stored in the persisted configuration is will no
+ * longer be overwritten by system properties. This ensures a simple system restart will not override configuration set
+ * by runtime controllers.
+ */
+// TODO should we support recovery by allow config overrides through system properties or should a luancher just wip
+// the bundle cache when it requires a clean boostrap?
+public interface AgentConfiguration {
+
+    // NOTE Configuration of the default subsystems for identification, discovery and connection handling is not part of
+    // this definition. Even though they are default implementations the are still extensions.
+
+    /**
+     * Sync interval; When sync is active it will automatically install updates and send feedback to the server. The
+     * time unit is seconds. A value of 0 or less disables the sync.
+     */
+    String CONFIG_KEY_SYNC_INTERVAL = AgentConfiguration.class.getPackage().getName() + ".syncinterval";
+    long CONFIG_DEFAULT_SYNC_INTERVAL = 300l;
+
+    void setSyncInterval(long seconds);
+
+    long getSyncInterval();
+
+    /**
+     * SyncRetries value; When an install fails during a sync the agent can try to recover by ignoring optimization
+     * flags and potentially restarting a Deployment Package download. A value of 1 or less disables the retry behavior.
+     */
+    String CONFIG_KEY_SYNC_RETRIES = AgentConfiguration.class.getPackage().getName() + ".syncretries";
+    int CONFIG_DEFAULT_SYNC_RETRIES = 3;
+
+    void setSyncRetries(int value);
+
+    int getSyncRetries();
+
+    /**
+     * UpdateStreaming flag; When set Deployment Packages are installed directly from the download stream reducing
+     * overhead and disk usage, but disabling resume capabilities. This strategy is of interest to highly resource
+     * constraint devices and/or system with highly reliable connectivity and no need for resume semantics.
+     */
+    String CONFIG_KEY_STREAMING_UPDATES = AgentConfiguration.class.getPackage().getName() + ".updatestreaming";
+    boolean CONFIG_DEFAULT_UPDATE_STREAMING = false;
+
+    void setUpdateStreaming(boolean flag);
+
+    boolean getUpdateStreaming();
+
+    /**
+     * StopUnaffected flag; When set all target bundles of a Deployment Package will be restarted as part of the
+     * deployment session. Otherwise the agent tries to minimize the impact by only restarting bundles that are actually
+     * affected. Not stopping unaffected bundles reduces overhead, but may fail in complex wiring scenarios.
+     */
+    String CONFIG_KEY_STOP_UNAFFECTED = AgentConfiguration.class.getPackage().getName() + ".stopunaffected";
+    boolean CONFIG_DEFAULT_STOP_UNAFFECTED = true; // spec behavior
+
+    void setStopUnaffected(boolean flag);
+
+    boolean getStopUnaffected();
+
+    /**
+     * FixPackages flag; When set the Agent will request the server for fix packages instead of full deployment
+     * packages. This behavior significantly reduces bandwidth consumption.
+     */
+    String CONFIG_KEY_FIX_PACKAGES = AgentConfiguration.class.getPackage().getName() + ".fixpackages";
+    boolean CONFIG_DEFAULT_FIX_PACKAGES = true;
+
+    void setFixPackage(boolean flag);
+
+    boolean getFixPackages();
+
+    /**
+     * Log level; Logging uses standard Java logging to guarantee optimal compatibility in any standard Java
+     * environment.
+     */
+    String CONFIG_KEY_LOG_LEVEL = AgentConfiguration.class.getPackage().getName() + ".loglevel";
+    Level CONFIG_DEFAULT_LOG_LEVEL = Level.INFO;
+
+    void setLogLevel(Level level);
+
+    Level getLogLevel();
+
+    /**
+     * Custom configuration keys; This is provided to allow a launcher to specify system properties that should be
+     * included in the persistent configuration map. The initial values of these properties are only read once when the
+     * agent starts and only stored if no value is set in the configuration map.
+     */
+    String CONFIG_KEY_EXTENSION_PROPERTIES = AgentConfiguration.class.getPackage().getName() + ".extensionkeys";
+
+    /**
+     * Direct access to the configuration map; This is provided to allow extensions to access custom configuration
+     * properties.
+     */
+    void setMap(Map<String, String> configuration);
+
+    Map<String, String> getMap();
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/AgentControl.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/AgentControl.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/AgentControl.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/AgentControl.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,35 @@
+package org.apache.ace.agent;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.ace.agent.deployment.DeploymentHandler;
+import org.apache.ace.agent.deployment.RetryAfterException;
+import org.apache.ace.agent.download.DownloadHandler;
+import org.osgi.framework.Version;
+
+/**
+ * The agent's control (service) interface. Provides control functions and access to configuration for consumers that
+ * wish to control the agent's behavior.
+ */
+public interface AgentControl {
+
+    /** access to the configuration */
+    AgentConfiguration getConfiguration();
+
+    /** access to the feedback channels */
+    List<FeedbackChannel> getFeedbackChannels();
+
+    /** access to the a named feedback channel */
+    FeedbackChannel getFeedbackChannel(String name);
+
+    /** current deployment version */
+    Version getCurrentVersion();
+
+    /** available deployment versions */
+    Version[] getAvailableVersions() throws RetryAfterException, IOException;
+
+    DownloadHandler getDownloadHandler();
+
+    DeploymentHandler getDeploymentHandler();
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/FeedbackChannel.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/FeedbackChannel.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/FeedbackChannel.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/FeedbackChannel.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,33 @@
+package org.apache.ace.agent;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.ace.agent.deployment.RetryAfterException;
+
+public interface FeedbackChannel {
+
+    /**
+     * Returns the name of the channel.
+     */
+    String getName();
+
+    /**
+     * Returns <code>true</code> when new feedback has become available since the last synchronization.
+     */
+    boolean feedbackAvailable();
+
+    /**
+     * Synchronizes the feedback with the current server. Ensures the server has at least as much feedback data as we
+     * do.
+     */
+    void sendFeedback() throws RetryAfterException, IOException;
+
+    /**
+     * Logs a new message to the channel.
+     * 
+     * @param type
+     * @param properties
+     */
+    void write(int type, Map<String, String> properties);
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DeploymentHandle.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DeploymentHandle.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DeploymentHandle.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DeploymentHandle.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,35 @@
+package org.apache.ace.agent.deployment;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+
+/**
+ * Represents a deployment handle that can be installed.
+ *
+ */
+public interface DeploymentHandle {
+
+    /**
+     * Return the size of the update in number of bytes. Depending on implementation this may be een estimate and should
+     * not be assumed to be the exact content length.
+     * 
+     * @return The size in number of bytes, or <code>-1</code> if it can not be determined.
+     */
+    long getSizeEstimate() throws IOException, RetryAfterException;
+
+    /**
+     * Return the InputStream for this handle.
+     * 
+     * @return The InputStream
+     * @throws IOException
+     */
+    InputStream getInput() throws IOException, RetryAfterException;
+
+    /**
+     * Install the handle.
+     * 
+     * @throws IOException
+     */
+    void install() throws IOException, RetryAfterException;
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DeploymentHandler.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DeploymentHandler.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DeploymentHandler.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DeploymentHandler.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,28 @@
+package org.apache.ace.agent.deployment;
+
+import org.osgi.framework.Version;
+
+/**
+ * Agent control delegate interface that provides the deployment handles.
+ * 
+ */
+public interface DeploymentHandler {
+
+    /**
+     * Get a deployment handle that support streaming install.
+     * 
+     * @param version The deployment version
+     * @param fixPackage Whether to use a fix-package
+     * @return The handle
+     */
+    StreamDeploymentHandle getStreamHandle(Version version, boolean fixPackage);
+
+    /**
+     * Get a deployment handle that support download install.
+     * 
+     * @param version The deployment version
+     * @param fixPackage Whether to use a fix-package
+     * @return The handle
+     */
+    DownloadDeploymentHandle getDownloadHandle(Version version, boolean fixPackage);
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DownloadDeploymentHandle.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DownloadDeploymentHandle.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DownloadDeploymentHandle.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DownloadDeploymentHandle.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,17 @@
+package org.apache.ace.agent.deployment;
+
+import org.apache.ace.agent.download.DownloadHandle;
+
+/**
+ * Deployment handle that downloads deployment packages before installing them.
+ * 
+ */
+public interface DownloadDeploymentHandle extends DeploymentHandle {
+
+    /**
+     * Returns the underlying download handle to allow conttrol over the download.
+     * 
+     * @return The download handle
+     */
+    DownloadHandle getDownloadHandle();
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/RetryAfterException.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/RetryAfterException.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/RetryAfterException.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/RetryAfterException.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,10 @@
+package org.apache.ace.agent.deployment;
+
+public class RetryAfterException extends Exception {
+
+    private static final long serialVersionUID = 1L;
+
+    public RetryAfterException(int time) {
+        super("Server too busy. Retry after " + time + " seconds");
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/StreamDeploymentHandle.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/StreamDeploymentHandle.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/StreamDeploymentHandle.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/StreamDeploymentHandle.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,9 @@
+package org.apache.ace.agent.deployment;
+
+/**
+ * Deployment handle that streams packages directly when deploying.
+ * 
+ */
+public interface StreamDeploymentHandle extends DeploymentHandle {
+
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/impl/AbstractDeploymentHandle.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/impl/AbstractDeploymentHandle.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/impl/AbstractDeploymentHandle.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/impl/AbstractDeploymentHandle.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,30 @@
+package org.apache.ace.agent.deployment.impl;
+
+import java.net.URL;
+
+import org.apache.ace.agent.deployment.DeploymentHandle;
+
+public abstract class AbstractDeploymentHandle implements DeploymentHandle {
+
+    private final DeploymentHandlerImpl m_handler;
+    private final URL m_url;
+
+    public AbstractDeploymentHandle(DeploymentHandlerImpl handler, URL url) {
+        m_handler = handler;
+        m_url = url;
+    }
+
+    @Override
+    public long getSizeEstimate() {
+        // TODO Connect to the deployment API and het the estimate (cached)
+        return 0;
+    }
+
+    protected DeploymentHandlerImpl getHandler() {
+        return m_handler;
+    }
+
+    protected URL getURL() {
+        return m_url;
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/impl/DeploymentHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/impl/DeploymentHandlerImpl.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/impl/DeploymentHandlerImpl.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/impl/DeploymentHandlerImpl.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,51 @@
+package org.apache.ace.agent.deployment.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.ace.agent.deployment.DeploymentHandler;
+import org.apache.ace.agent.deployment.DownloadDeploymentHandle;
+import org.apache.ace.agent.deployment.StreamDeploymentHandle;
+import org.apache.ace.agent.download.DownloadHandle;
+import org.apache.ace.agent.download.DownloadHandler;
+import org.osgi.framework.Version;
+import org.osgi.service.deploymentadmin.DeploymentAdmin;
+import org.osgi.service.deploymentadmin.DeploymentException;
+
+public class DeploymentHandlerImpl implements DeploymentHandler {
+
+    private DeploymentAdmin m_deploymentAdmin;
+    private DownloadHandler m_downloadHandler;
+
+    public DeploymentHandlerImpl(DeploymentAdmin deploymentAdmin, DownloadHandler downloadHandler) {
+        m_deploymentAdmin = deploymentAdmin;
+        m_downloadHandler = downloadHandler;
+    }
+
+    @Override
+    public StreamDeploymentHandle getStreamHandle(Version version, boolean fixPackage) {
+        return new StreamDeploymentHandleImpl(this, getDeploymentUrl(version, fixPackage));
+    }
+
+    @Override
+    public DownloadDeploymentHandle getDownloadHandle(Version version, boolean fixPackage) {
+        URL url = getDeploymentUrl(version, fixPackage);
+        DownloadHandle handle = m_downloadHandler.getHandle(url);
+        return new DownloadDeploymentHandleImpl(this, url, handle);
+    }
+
+    void install(InputStream inputStream) throws IOException {
+        // FIXME exception
+        try {
+            m_deploymentAdmin.installDeploymentPackage(inputStream);
+        }
+        catch (DeploymentException e) {
+            throw new IOException(e);
+        }
+    }
+
+    protected URL getDeploymentUrl(Version version, boolean fixPackage) {
+        return null;
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/impl/DownloadDeploymentHandleImpl.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/impl/DownloadDeploymentHandleImpl.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/impl/DownloadDeploymentHandleImpl.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/impl/DownloadDeploymentHandleImpl.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,36 @@
+package org.apache.ace.agent.deployment.impl;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.ace.agent.deployment.DownloadDeploymentHandle;
+import org.apache.ace.agent.download.DownloadHandle;
+import org.apache.ace.agent.download.DownloadResult;
+
+public class DownloadDeploymentHandleImpl extends AbstractDeploymentHandle implements DownloadDeploymentHandle {
+
+    private final DownloadHandle m_handle;
+
+    public DownloadDeploymentHandleImpl(DeploymentHandlerImpl handler, URL url, DownloadHandle handle) {
+        super(handler, url);
+        m_handle = handle;
+    }
+
+    @Override
+    public InputStream getInput() throws IOException {
+        DownloadResult result = m_handle.result();
+        return new FileInputStream(result.getFile());
+    }
+
+    @Override
+    public void install() throws IOException {
+        getHandler().install(getInput());
+    }
+
+    @Override
+    public DownloadHandle getDownloadHandle() {
+        return m_handle;
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/impl/StreamDeploymentHandleImpl.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/impl/StreamDeploymentHandleImpl.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/impl/StreamDeploymentHandleImpl.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/impl/StreamDeploymentHandleImpl.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,29 @@
+package org.apache.ace.agent.deployment.impl;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.ace.agent.deployment.StreamDeploymentHandle;
+
+public class StreamDeploymentHandleImpl extends AbstractDeploymentHandle implements StreamDeploymentHandle {
+
+
+    public StreamDeploymentHandleImpl(DeploymentHandlerImpl handler, URL url) {
+        super(handler, url);
+    }
+    
+    @Override
+    public long getSizeEstimate() {
+        // TODO 
+        return 0;
+    }
+
+    @Override
+    public InputStream getInput() {
+        return null;
+    }
+
+    @Override
+    public void install() {
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/packageinfo
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/packageinfo?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/packageinfo (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/packageinfo Mon Aug 12 10:58:50 2013
@@ -0,0 +1 @@
+version 1.0
\ No newline at end of file

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DownloadHandle.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DownloadHandle.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DownloadHandle.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DownloadHandle.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,90 @@
+package org.apache.ace.agent.download;
+
+/**
+ * A {@link DownloadHandle} provides control over an asynchronous download and access to the resulting file when the it
+ * is completed. <br/>
+ * <br/>
+ * Consumers must consider the following rules;
+ * <ul>
+ * <li>Control methods must be called in logical order.
+ * <li>Implementations are not expected to be thread-safe.
+ * <li>Resulting files must be assumed to be transient.
+ * <ul>
+ */
+public interface DownloadHandle {
+
+    /**
+     * Size of the buffer used while downloading the content stream.
+     */
+    int DEFAULT_READBUFFER_SIZE = 1024;
+
+    /**
+     * Callback interface; when registered the progress method will be invoked while downloading the content stream for
+     * every {@link READBUFFER_SIZE} bytes.
+     */
+    interface ProgressListener {
+        /**
+         * Called while downloading the content stream.
+         * 
+         * @param contentLength The total length of the content or -1 if unknown.
+         * @param progress The number of bytes that has been received so far.
+         */
+        void progress(long contentLength, long progress);
+    }
+
+    /**
+     * Callback interface; when registered the completed method will be invoked when the download terminates for any
+     * reason.
+     * 
+     */
+    interface CompletedListener {
+        /**
+         * Called when a download terminates.
+         * 
+         * @param result The result of the download.
+         */
+        void completed(DownloadResult result);
+    }
+
+    /**
+     * Registers the progress listener.
+     * 
+     * @param listener The progress listener.
+     * @return this
+     */
+    DownloadHandle setProgressListener(ProgressListener listener);
+
+    /**
+     * Registers the completion listener.
+     * 
+     * @param listener The completion listener.
+     * @return this
+     */
+    DownloadHandle setCompletionListener(CompletedListener listener);
+
+    /**
+     * Starts the download.
+     * 
+     * @return this
+     */
+    DownloadHandle start();
+
+    /**
+     * Pauses the download.
+     * 
+     * @return this
+     */
+    DownloadHandle stop();
+
+    /**
+     * Retrieves the download result. Will wait for completion before returning.
+     * 
+     * @return The result of the download
+     */
+    DownloadResult result();
+
+    /**
+     * Releases any resources that may be held by the handle.
+     */
+    void discard();
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DownloadHandler.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DownloadHandler.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DownloadHandler.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DownloadHandler.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,19 @@
+package org.apache.ace.agent.download;
+
+import java.net.URL;
+
+/**
+ * Service interface for a DownloadHandler component.
+ */
+public interface DownloadHandler {
+
+    /**
+     * Returns a {@link DownloadHandle} for a URL.
+     * 
+     * @param url The url
+     * @return The {@link DownloadHandle}
+     */
+    DownloadHandle getHandle(URL url);
+    
+    DownloadHandle getHandle(URL url, int readBufferSize);
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DownloadResult.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DownloadResult.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DownloadResult.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DownloadResult.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,36 @@
+package org.apache.ace.agent.download;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Represents the result of a download task.
+ * 
+ */
+public interface DownloadResult {
+
+    /**
+     * Returns the state of the result.
+     * 
+     * @return The state
+     */
+    DownloadState getState();
+
+    /**
+     * Returns the download file.
+     * 
+     * @return The file, <code>null</code> if the download was unsuccessful
+     */
+    File getFile();
+
+    int getCode();
+    
+    Map<String, List<String>> getHeaders();
+    /**
+     * Return the cause of an unsuccessful download.
+     * 
+     * @return The cause, <code>null</code> if the download was successful
+     */
+    Throwable getCause();
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DownloadState.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DownloadState.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DownloadState.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DownloadState.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,19 @@
+package org.apache.ace.agent.download;
+
+/**
+ * The state of a download handle that completed.
+ */
+public enum DownloadState {
+    /**
+     * The handle completed successfully.
+     */
+    SUCCESSFUL,
+    /**
+     * The handle completed because it was stopped.
+     */
+    STOPPED,
+    /**
+     * The handle completed due to an unrecoverable error. It can not be resumed.
+     */
+    FAILED,
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/impl/DownloadCallableImpl.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/impl/DownloadCallableImpl.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/impl/DownloadCallableImpl.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/impl/DownloadCallableImpl.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,176 @@
+package org.apache.ace.agent.download.impl;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+
+class DownloadCallableImpl implements Callable<Void> {
+
+    // test support
+    static final int FAIL_OPENCONNECTION = 1;
+    static final int FAIL_OPENINPUTSTREAM = 2;
+    static final int FAIL_OPENOUTPUTSTREAM = 3;
+    static final int FAIL_AFTERFIRSTWRITE = 4;
+
+    private final DownloadHandleImpl m_handle;
+    private final URL m_source;
+    private final File m_target;
+    private final int m_readBufferSize;
+    private final int m_failAtPosition;
+
+    private volatile boolean m_abort = false;
+
+    DownloadCallableImpl(DownloadHandleImpl handle, URL source, File target, int readBufferSize, int failAtPosition) {
+        m_handle = handle;
+        m_source = source;
+        m_target = target;
+        m_readBufferSize = readBufferSize;
+        m_failAtPosition = failAtPosition;
+    }
+
+    @Override
+    public Void call() throws Exception {
+        return download();
+    }
+
+    /**
+     * Abort the download. Used instead of a cancel on the future so normal completion can take place.
+     */
+    void abort() {
+        m_abort = true;
+    }
+
+    @SuppressWarnings("resource")
+    private Void download() {
+
+        int statusCode = 0;
+        Map<String, List<String>> headerFields = null;
+
+        BufferedInputStream inputStream = null;
+        BufferedOutputStream outputStream = null;
+        HttpURLConnection httpUrlConnection = null;
+        try {
+
+            boolean partialContent = false;
+            boolean appendTarget = false;
+
+            if (m_failAtPosition == FAIL_OPENCONNECTION)
+                throw new IOException("Failed on openConnection on request");
+            httpUrlConnection = (HttpURLConnection) m_source.openConnection();
+
+            long targetSize = m_target.length();
+            if (targetSize > 0) {
+                String rangeHeader = "bytes=" + targetSize + "-";
+                m_handle.logDebug("Requesting Range %s", targetSize, rangeHeader);
+                httpUrlConnection.setRequestProperty("Range", rangeHeader);
+            }
+
+            statusCode = httpUrlConnection.getResponseCode();
+            headerFields = httpUrlConnection.getHeaderFields();
+            if (statusCode == 200) {
+                partialContent = false;
+            }
+            else if (statusCode == 206) {
+                partialContent = true;
+            }
+            else {
+                throw new IOException("Unable to handle server response code " + statusCode);
+            }
+
+            if (m_failAtPosition == FAIL_OPENINPUTSTREAM)
+                throw new IOException("Failed on openConnection on request");
+            inputStream = new BufferedInputStream(httpUrlConnection.getInputStream());
+
+            long contentLength = httpUrlConnection.getContentLength();
+            if (partialContent) {
+                String contentRange = httpUrlConnection.getHeaderField("Content-Range");
+                if (contentRange == null) {
+                    throw new IOException("Server returned no Content-Range for partial content");
+                }
+                if (!contentRange.startsWith("bytes ")) {
+                    throw new IOException("Server returned non byes Content-Range " + contentRange);
+                }
+                String tmp = contentRange;
+                tmp = tmp.replace("byes ", "");
+                String[] parts = tmp.split("/");
+                String start = parts[0].split("-")[0];
+                String end = parts[0].split("-")[1];
+                System.out.println("size:" + parts[1]);
+                System.out.println("from:" + start);
+                System.out.println("too:" + end);
+
+                if (parts[1].equals("*"))
+                    contentLength = -1;
+                else
+                    contentLength = Long.parseLong(parts[1]);
+            }
+
+            long progress = 0l;
+            if (partialContent) {
+                progress = targetSize;
+                appendTarget = true;
+            }
+
+            if (m_failAtPosition == FAIL_OPENOUTPUTSTREAM)
+                throw new IOException("Failed on outputStream");
+            outputStream = new BufferedOutputStream(new FileOutputStream(m_target, appendTarget));
+
+            byte buffer[] = new byte[m_readBufferSize];
+            int read = -1;
+            while (!m_abort && (read = inputStream.read(buffer)) >= 0) {
+
+                outputStream.write(buffer, 0, read);
+                progress += read;
+                m_handle.progressCallback(statusCode, headerFields, contentLength, progress);
+
+                if (m_failAtPosition == FAIL_AFTERFIRSTWRITE)
+                    throw new IOException("Failed after first write");
+
+                if (Thread.currentThread().isInterrupted())
+                    m_abort = true;
+            }
+
+            if (m_abort) {
+                m_handle.logDebug("Download stopped");
+                m_handle.stoppedCallback(statusCode, headerFields, null);
+            }
+            else {
+                m_handle.logDebug("Download completed");
+                m_handle.successfulCallback(statusCode, headerFields);
+            }
+        }
+        catch (Exception e) {
+            m_handle.failedCallback(statusCode, headerFields, e);
+        }
+        cleanupQuietly(httpUrlConnection, inputStream, outputStream);
+        return null;
+    }
+
+    private static void cleanupQuietly(HttpURLConnection httpUrlConnection, InputStream inputStream, OutputStream outputStream) {
+        if (httpUrlConnection != null)
+            httpUrlConnection.disconnect();
+        if (inputStream != null)
+            try {
+                inputStream.close();
+            }
+            catch (IOException e) {
+                // ignore
+            }
+        if (outputStream != null)
+            try {
+                outputStream.close();
+            }
+            catch (IOException e) {
+                // ignore
+            }
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/impl/DownloadHandleImpl.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/impl/DownloadHandleImpl.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/impl/DownloadHandleImpl.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/impl/DownloadHandleImpl.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,177 @@
+package org.apache.ace.agent.download.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Future;
+
+import org.apache.ace.agent.download.DownloadHandle;
+import org.apache.ace.agent.download.DownloadResult;
+import org.apache.ace.agent.download.DownloadState;
+
+/**
+ * A {@link DownloadHandle} implementation that supports pause/resume semantics based on HTTP Range headers assuming the
+ * server supports this feature.
+ * 
+ */
+class DownloadHandleImpl implements DownloadHandle {
+
+    private final DownloadHandlerImpl m_handler;
+    private final URL m_url;
+    private final int m_readBufferSize;
+
+    private volatile boolean m_started = false;
+    private volatile boolean m_completed = false;
+
+    private volatile Future<Void> m_future;
+    private volatile DownloadCallableImpl m_callable;
+    private volatile File m_file;
+
+    private volatile ProgressListener m_progressListener;
+    private volatile CompletedListener m_completionListener;
+
+    private volatile DownloadResult m_downloadResult;
+
+    DownloadHandleImpl(DownloadHandlerImpl handler, URL url) {
+        this(handler, url, DEFAULT_READBUFFER_SIZE);
+    }
+
+    DownloadHandleImpl(DownloadHandlerImpl handler, URL url, int readBufferSize) {
+        m_handler = handler;
+        m_url = url;
+        m_readBufferSize = readBufferSize;
+    }
+
+    @Override
+    public DownloadHandle setProgressListener(ProgressListener listener) {
+        m_progressListener = listener;
+        return this;
+    }
+
+    @Override
+    public DownloadHandle setCompletionListener(CompletedListener listener) {
+        m_completionListener = listener;
+        return this;
+    }
+
+    @Override
+    public DownloadHandle start() {
+        return start(-1);
+    }
+
+    DownloadHandle start(int failAtPosition) {
+        if (m_started)
+            throw new IllegalStateException("Can not call start on a handle that is allready started");
+        if (m_file == null) {
+            try {
+                m_file = File.createTempFile("download", ".bin");
+            }
+            catch (IOException e) {
+                failedCallback(0, null, e);
+            }
+        }
+        startDownload(failAtPosition);
+        return this;
+    }
+
+    @Override
+    public DownloadHandle stop() {
+        if (!m_started && !m_completed)
+            throw new IllegalStateException("Can not call stop on a handle that is not yet started");
+        m_started = false;
+        stopDownload();
+        return this;
+    }
+
+    @Override
+    public DownloadResult result() {
+        if (m_completed)
+            return m_downloadResult;
+        if (!m_started)
+            throw new IllegalStateException("Can not call result on a handle that is not yet started");
+        try {
+            m_future.get();
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+        }
+        return m_downloadResult;
+    }
+
+    @Override
+    public void discard() {
+        if (m_started)
+            stop();
+        m_file.delete();
+    }
+
+    void progressCallback(int statusCode, Map<String, List<String>> headers, long contentLength, long progress) {
+        callProgressListener(m_progressListener, contentLength, progress);
+    }
+
+    void successfulCallback(int statusCode, Map<String, List<String>> headers) {
+        m_started = false;
+        m_completed = true;
+        m_downloadResult = new DownloadResultImpl(DownloadState.SUCCESSFUL, m_file, statusCode, headers, null);
+        callCompletionListener(m_completionListener, m_downloadResult);
+    }
+
+    void stoppedCallback(int statusCode, Map<String, List<String>> headers, Throwable cause) {
+        m_started = false;
+        m_completed = false;
+        m_downloadResult = new DownloadResultImpl(DownloadState.STOPPED, null, statusCode, headers, cause);
+        callCompletionListener(m_completionListener, m_downloadResult);
+    }
+
+    void failedCallback(int statusCode, Map<String, List<String>> headers, Throwable cause) {
+        m_started = false;
+        m_completed = false;
+        m_downloadResult = new DownloadResultImpl(DownloadState.FAILED, null, statusCode, headers, cause);
+        callCompletionListener(m_completionListener, m_downloadResult);
+    }
+
+    void logDebug(String message, Object... args) {
+        m_handler.logDebug(message, args);
+    }
+
+    void logInfo(String message, Object... args) {
+        m_handler.logInfo(message, args);
+    }
+
+    void logWarning(String message, Object... args) {
+        m_handler.logWarning(message, args);
+    }
+
+    private void startDownload(int failAtPosition) {
+        m_started = true;
+        m_callable = new DownloadCallableImpl(this, m_url, m_file, m_readBufferSize, failAtPosition);
+        m_future = m_handler.getExecutor().submit(m_callable);
+    }
+
+    private void stopDownload() {
+        m_started = false;
+        m_callable.abort();
+    }
+
+    private static void callProgressListener(ProgressListener listener, long contentLength, long progress) {
+        if (listener != null)
+            try {
+                listener.progress(contentLength, progress);
+            }
+            catch (Exception e) {
+                // ignore
+            }
+    }
+
+    private static void callCompletionListener(CompletedListener listener, DownloadResult result) {
+        if (listener != null && result != null)
+            try {
+                listener.completed(result);
+            }
+            catch (Exception e) {
+                // ignore
+            }
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/impl/DownloadHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/impl/DownloadHandlerImpl.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/impl/DownloadHandlerImpl.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/impl/DownloadHandlerImpl.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,61 @@
+package org.apache.ace.agent.download.impl;
+
+import java.net.URL;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+
+import org.apache.ace.agent.download.DownloadHandle;
+import org.apache.ace.agent.download.DownloadHandler;
+
+public class DownloadHandlerImpl implements DownloadHandler {
+
+    private ExecutorService m_exe;
+
+    @Override
+    public DownloadHandle getHandle(URL url) {
+        return new DownloadHandleImpl(this, url);
+    }
+
+    @Override
+    public DownloadHandle getHandle(URL url, int readBufferSize) {
+        return new DownloadHandleImpl(this, url, readBufferSize);
+    }
+
+    public void start() throws Exception {
+        m_exe = Executors.newCachedThreadPool(new ThreadFactory() {
+            private volatile int m_count;
+
+            @Override
+            public Thread newThread(Runnable r) {
+                Thread t = new Thread(r, "DownloadHandler Thread (" + m_count++ + ")");
+                t.setDaemon(true);
+                return t;
+            }
+        });
+
+    }
+
+    public void stop() throws Exception {
+        m_exe.shutdownNow();
+    }
+
+    /*
+     * handle support methods
+     */
+    ExecutorService getExecutor() {
+        return m_exe;
+    }
+
+    void logDebug(String message, Object... args) {
+        System.err.println(String.format(message, args));
+    }
+
+    void logInfo(String message, Object... args) {
+        System.err.println(String.format(message, args));
+    }
+
+    void logWarning(String message, Object... args) {
+        System.err.println(String.format(message, args));
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/impl/DownloadResultImpl.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/impl/DownloadResultImpl.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/impl/DownloadResultImpl.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/impl/DownloadResultImpl.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,50 @@
+package org.apache.ace.agent.download.impl;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ace.agent.download.DownloadResult;
+import org.apache.ace.agent.download.DownloadState;
+
+public class DownloadResultImpl implements DownloadResult {
+
+    final DownloadState m_state;
+    final File m_file;
+    final int m_code;
+    final Map<String, List<String>> m_headers;
+    final Throwable m_cause;
+
+    DownloadResultImpl(DownloadState state, File file, int code, Map<String, List<String>> headers, Throwable cause) {
+        m_state = state;
+        m_file = file;
+        m_code = code;
+        m_headers = headers;
+        m_cause = cause;
+    }
+
+    @Override
+    public DownloadState getState() {
+        return m_state;
+    }
+
+    @Override
+    public File getFile() {
+        return m_file;
+    }
+
+    @Override
+    public int getCode() {
+        return m_code;
+    }
+
+    @Override
+    public Map<String, List<String>> getHeaders() {
+        return m_headers;
+    }
+
+    @Override
+    public Throwable getCause() {
+        return m_cause;
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/packageinfo
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/packageinfo?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/packageinfo (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/packageinfo Mon Aug 12 10:58:50 2013
@@ -0,0 +1 @@
+version 1.0
\ No newline at end of file

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java?rev=1513102&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java Mon Aug 12 10:58:50 2013
@@ -0,0 +1,32 @@
+package org.apache.ace.agent.impl;
+
+import java.io.IOException;
+
+import org.apache.ace.agent.AgentControl;
+import org.apache.ace.agent.FeedbackChannel;
+import org.apache.ace.agent.deployment.RetryAfterException;
+
+public class DefaultController {
+
+    private AgentControl m_control;
+
+    private void sync() {
+
+        m_control.getCurrentVersion();
+
+        for (FeedbackChannel channel : m_control.getFeedbackChannels()) {
+            if (channel.feedbackAvailable())
+                try {
+                    channel.sendFeedback();
+                }
+                catch (RetryAfterException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+                catch (IOException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+        }
+    }
+}



Mime
View raw message