You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by ma...@apache.org on 2013/08/22 15:41:10 UTC
svn commit: r1516450 - in
/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent:
impl/AgentUpdateHandlerImpl.java updater/Activator.java
Author: marrs
Date: Thu Aug 22 13:41:09 2013
New Revision: 1516450
URL: http://svn.apache.org/r1516450
Log:
ACE-342 Cleanup, removed some print statements, some simplifications and added some logging.
Modified:
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentUpdateHandlerImpl.java
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/updater/Activator.java
Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentUpdateHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentUpdateHandlerImpl.java?rev=1516450&r1=1516449&r2=1516450&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentUpdateHandlerImpl.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentUpdateHandlerImpl.java Thu Aug 22 13:41:09 2013
@@ -72,6 +72,7 @@ public class AgentUpdateHandlerImpl exte
b.uninstall();
}
catch (BundleException e) {
+ logError("Failed to uninstall updater bundle. Will try to stop it instead.", e);
b.stop();
throw e;
}
@@ -86,7 +87,7 @@ public class AgentUpdateHandlerImpl exte
@Override
public SortedSet<Version> getAvailableVersions() throws RetryAfterException, IOException {
- return getAvailableVersions(getEndpoint(getServerURL(), getIdentification()));
+ return getAvailableVersions(getEndpoint(getServerURL(), getIdentification(), null));
}
@Override
@@ -115,7 +116,6 @@ public class AgentUpdateHandlerImpl exte
Object service = st.waitForService(TIMEOUT);
if (service != null) {
Method method = service.getClass().getMethod("update", Bundle.class, InputStream.class, InputStream.class);
- System.out.println("Method: " + method);
try {
method.invoke(service, m_bundleContext.getBundle(), currentBundleVersion, stream);
}
@@ -180,10 +180,6 @@ public class AgentUpdateHandlerImpl exte
return bais;
}
- private URL getEndpoint(URL serverURL, String identification) {
- return getEndpoint(serverURL, identification, null);
- }
-
private URL getEndpoint(URL serverURL, String identification, Version version) {
try {
return new URL(serverURL, "agent/" + identification + "/" + m_bundleContext.getBundle().getSymbolicName() + "/versions/" + (version == null ? "" : version.toString()));
Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/updater/Activator.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/updater/Activator.java?rev=1516450&r1=1516449&r2=1516450&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/updater/Activator.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/updater/Activator.java Thu Aug 22 13:41:09 2013
@@ -39,8 +39,6 @@ import org.osgi.framework.BundleExceptio
*/
public class Activator implements BundleActivator, Runnable {
private static final int BUFFER_SIZE = 4096;
- private Object LOCK = new Object();
- private BundleContext m_context;
private Thread m_updaterThread;
private InputStream m_oldStream;
private InputStream m_newStream;
@@ -50,10 +48,9 @@ public class Activator implements Bundle
@Override
public void start(BundleContext context) throws Exception {
- m_context = context;
- m_context.registerService(Activator.class.getName(), this, null);
- m_oldFile = m_context.getDataFile("old.jar");
- m_newFile = m_context.getDataFile("new.jar");
+ context.registerService(Activator.class.getName(), this, null);
+ m_oldFile = context.getDataFile("old.jar");
+ m_newFile = context.getDataFile("new.jar");
}
@Override
@@ -61,14 +58,12 @@ public class Activator implements Bundle
}
public void update(Bundle agent, InputStream oldStream, InputStream newStream) throws IOException {
- synchronized (LOCK) {
- m_updaterThread = new Thread(this, "Apache ACE Management Agent Updater");
- m_agent = agent;
- copy(oldStream, new FileOutputStream(m_oldFile));
- copy(newStream, new FileOutputStream(m_newFile));
- m_oldStream = new FileInputStream(m_oldFile);
- m_newStream = new FileInputStream(m_newFile);
- }
+ m_updaterThread = new Thread(this, "Apache ACE Management Agent Updater");
+ m_agent = agent;
+ copy(oldStream, new FileOutputStream(m_oldFile));
+ copy(newStream, new FileOutputStream(m_newFile));
+ m_oldStream = new FileInputStream(m_oldFile);
+ m_newStream = new FileInputStream(m_newFile);
m_updaterThread.start();
}
@@ -95,18 +90,27 @@ public class Activator implements Bundle
@Override
public void run() {
try {
- System.out.println("Updating to " + m_newStream);
m_agent.update(m_newStream);
}
catch (BundleException e) {
try {
- System.out.println("Reverting to " + m_oldStream);
m_agent.update(m_oldStream);
m_agent.start();
}
catch (BundleException e1) {
// at this point we simply give up
- e1.printStackTrace();
+ // and log the exceptions we got
+ System.err.println("Error updating agent:");
+ e.printStackTrace(System.err);
+ e1.printStackTrace(System.err);
+ // the best we can do is try to start the agent (again)
+ try {
+ m_agent.start();
+ System.err.println("We did manage to start the agent again.");
+ }
+ catch (BundleException e2) {
+ e2.printStackTrace(System.err);
+ }
}
}
}