mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-30 09:26:44 +00:00
fixed bug 579, clearing the ActiveMQ broker's persistent store directory in the activator;
it would be unclear what to do with stale old messages after a server restart anyhow
This commit is contained in:
+31
-1
@@ -1,6 +1,8 @@
|
||||
package com.sap.sailing.server.replication.impl;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.osgi.framework.BundleActivator;
|
||||
import org.osgi.framework.BundleContext;
|
||||
@@ -8,6 +10,8 @@ import org.osgi.framework.BundleContext;
|
||||
import com.sap.sailing.server.replication.ReplicationService;
|
||||
|
||||
public class Activator implements BundleActivator {
|
||||
private static final Logger logger = Logger.getLogger(Activator.class.getName());
|
||||
|
||||
private static final String REPLICATION_PERSISTENCE_DIR_PROPERTY = "replication.persistenceDir";
|
||||
|
||||
private static final String BROKER_URL_PROPERTY = "replication.brokerURL";
|
||||
@@ -30,8 +34,10 @@ public class Activator implements BundleActivator {
|
||||
if (brokerURL == null) {
|
||||
brokerURL = "tcp://localhost:61616";
|
||||
}
|
||||
final File brokerPersistenceDir = new File(replicationPersistenceDirectory, "kahadb");
|
||||
removeTemporaryTestBrokerPersistenceDirectory(brokerPersistenceDir);
|
||||
MessageBrokerConfiguration brokerConfig = new MessageBrokerConfiguration("SailingServerReplicationBroker",
|
||||
brokerURL, new File(replicationPersistenceDirectory, "kahadb").getAbsolutePath());
|
||||
brokerURL, brokerPersistenceDir.getAbsolutePath());
|
||||
messageBrokerManager = new MessageBrokerManager(brokerConfig);
|
||||
String useJMX = bundleContext.getProperty(REPLICATION_USE_JMX_PROPERTY);
|
||||
if (useJMX == null || useJMX.length() == 0) {
|
||||
@@ -44,6 +50,30 @@ public class Activator implements BundleActivator {
|
||||
bundleContext.registerService(ReplicationService.class, serverReplicationMasterService, null);
|
||||
}
|
||||
|
||||
public static void removeTemporaryTestBrokerPersistenceDirectory(File brokerPersistenceDir) throws FileNotFoundException {
|
||||
if (brokerPersistenceDir.exists() && brokerPersistenceDir.isDirectory()) {
|
||||
logger.info("Deleting message broker persistence director "+brokerPersistenceDir);
|
||||
deleteRecursive(brokerPersistenceDir);
|
||||
}
|
||||
File failoverStore = new File("activemq-data");
|
||||
if (failoverStore.exists() && failoverStore.isDirectory()) {
|
||||
logger.info("Deleting message broker failover store "+failoverStore);
|
||||
deleteRecursive(failoverStore);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean deleteRecursive(File path) throws FileNotFoundException{
|
||||
if (!path.exists()) throw new FileNotFoundException(path.getAbsolutePath());
|
||||
boolean ret = true;
|
||||
if (path.isDirectory()){
|
||||
for (File f : path.listFiles()){
|
||||
ret = ret && deleteRecursive(f);
|
||||
}
|
||||
}
|
||||
return ret && path.delete();
|
||||
}
|
||||
|
||||
|
||||
public void stop(BundleContext bundleContext) throws Exception {
|
||||
messageBrokerManager.closeSessions();
|
||||
messageBrokerManager.closeConnections();
|
||||
|
||||
Reference in New Issue
Block a user