Skip to content

Commit

Permalink
Merge branch 'release/12.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
iitsoftware committed Aug 20, 2022
2 parents 0bea73e + 2c3af4b commit 1f71ecd
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 31 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>com.swiftmq</groupId>
<artifactId>swiftmq-client</artifactId>
<version>12.4.1</version>
<version>12.5.0</version>

<name>SwiftMQ Client</name>
<description>Client for SwiftMQ Messaging System with JMS, AMQP 1.0 and file transfer over JMS.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.swiftmq.jms.TextMessageImpl;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.Dom4JDriver;
import com.thoughtworks.xstream.security.AnyTypePermission;

import javax.jms.JMSException;
import javax.jms.Message;
Expand All @@ -44,6 +45,8 @@ private void createResult(TextMessage message) throws JMSException {
String s = message.getText();
if (s != null) {
XStream xStream = new XStream(new Dom4JDriver());
xStream.addPermission(AnyTypePermission.ANY);
xStream.allowTypesByWildcard(new String[]{".*"});
StringReader reader = new StringReader(s);
result = (Map<String, Map<String, Object>>) xStream.fromXML(reader);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/swiftmq/jndi/fs/ContextImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.Dom4JDriver;
import com.thoughtworks.xstream.security.AnyTypePermission;

import javax.naming.*;
import java.io.*;
Expand All @@ -31,6 +32,8 @@ public class ContextImpl implements Context, java.io.Serializable, NameParser {
ContextImpl(File contextDir) {
this.contextDir = contextDir;
xStream = new XStream(new Dom4JDriver());
xStream.addPermission(AnyTypePermission.ANY);
xStream.allowTypesByWildcard(new String[]{".*"});
}

public Name parse(String s) throws NamingException {
Expand Down
34 changes: 11 additions & 23 deletions src/main/java/com/swiftmq/swiftlet/SwiftletDeployer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import com.swiftmq.swiftlet.deploy.DeploySpace;
import com.swiftmq.swiftlet.deploy.DeploySwiftlet;
import com.swiftmq.swiftlet.deploy.event.DeployListener;
import com.swiftmq.swiftlet.event.SwiftletManagerAdapter;
import com.swiftmq.swiftlet.event.SwiftletManagerEvent;
import com.swiftmq.swiftlet.log.LogSwiftlet;
import com.swiftmq.swiftlet.mgmt.CLIExecutor;
import com.swiftmq.swiftlet.mgmt.MgmtSwiftlet;
Expand All @@ -46,27 +44,10 @@ public class SwiftletDeployer implements DeployListener {
SwiftletDeployer() {
traceSwiftlet = (TraceSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$trace");
traceSpace = traceSwiftlet.getTraceSpace(TraceSwiftlet.SPACE_KERNEL);
SwiftletManager.getInstance().addSwiftletManagerListener("sys$log", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent evt) {
logSwiftlet = (LogSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$log");
}
});
SwiftletManager.getInstance().addSwiftletManagerListener("sys$mgmt", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent evt) {
mgmtSwiftlet = (MgmtSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$mgmt");
}
});
SwiftletManager.getInstance().addSwiftletManagerListener("sys$deploy", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent evt) {
deploySwiftlet = (DeploySwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$deploy");
deploySpace = deploySwiftlet.getDeploySpace(SPACE_NAME);
}
});
SwiftletManager.getInstance().addSwiftletManagerListener("sys$scheduler", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent evt) {
start();
}
});
logSwiftlet = (LogSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$log");
mgmtSwiftlet = (MgmtSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$mgmt");
deploySwiftlet = (DeploySwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$deploy");
deploySpace = deploySwiftlet.getDeploySpace(SPACE_NAME);
if (traceSpace.enabled) traceSpace.trace("SwiftletManager", toString() + "/created");
}

Expand Down Expand Up @@ -109,6 +90,13 @@ public void start() {
if (traceSpace.enabled) traceSpace.trace("SwiftletManager", toString() + "/start done");
}

public void stop() {
if (traceSpace.enabled) traceSpace.trace("SwiftletManager", toString() + "/stop ...");
if (deploySpace != null)
deploySpace.setDeployListener(null);
if (traceSpace.enabled) traceSpace.trace("SwiftletManager", toString() + "/stop ...");
}

private int executeCLICommands(Bundle bundle, CLIExecutor cliexec, String phase, boolean old) throws Exception {
if (traceSpace.enabled)
traceSpace.trace("SwiftletManager", toString() + "/executeCLICommands, bundle=" + bundle.getBundleName() + ", phase=" + phase + " ...");
Expand Down
57 changes: 50 additions & 7 deletions src/main/java/com/swiftmq/swiftlet/SwiftletManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
* The SwiftletManager is the single instance of a SwiftMQ router that is
Expand Down Expand Up @@ -103,6 +106,7 @@ public class SwiftletManager {
Set kernelListeners = new HashSet();
Map surviveMap = Collections.synchronizedMap(new HashMap());
RouterMemoryMeter memoryMeter = null;
SwiftletDeployer swiftletDeployer = null;

LogSwiftlet logSwiftlet = null;
TraceSwiftlet traceSwiftlet = null;
Expand All @@ -122,6 +126,8 @@ public class SwiftletManager {
boolean quietMode = false;
boolean strippedMode = false;
boolean doFireKernelStartedEvent = true;
AtomicBoolean configDirty = new AtomicBoolean(false);
Lock saveLock = new ReentrantLock();
PrintStream savedSystemOut = System.out;

Thread shutdownHook = null;
Expand Down Expand Up @@ -153,6 +159,16 @@ protected void trace(String message) {
traceSpace.trace("SwiftletManager", message);
}

protected void startSwiftletDeployer() {
swiftletDeployer = new SwiftletDeployer();
swiftletDeployer.start();
}

protected void stopSwiftletDeployer() {
if (swiftletDeployer != null)
swiftletDeployer.stop();
}

protected Configuration getConfiguration(Swiftlet swiftlet) throws Exception {
trace("Swiftlet " + swiftlet.getName() + "', getConfiguration");
Configuration config = (Configuration) RouterConfiguration.Singleton().getConfigurations().get(swiftlet.getName());
Expand Down Expand Up @@ -239,21 +255,24 @@ protected void startKernelSwiftlets() {
trace("Trace swiftlet '" + actSwiftletName + " has been started");
trace("Starting kernel swiftlets");

// Create Extension Swiftlet Deployer
new SwiftletDeployer();

// Next: start the other kernel swiftlets
for (String kernelSwiftletName : kernelSwiftletNames) {
actSwiftletName = kernelSwiftletName;
startKernelSwiftlet(actSwiftletName, swiftletTable);
if (kernelSwiftletName.equals("sys$log"))
logSwiftlet = (LogSwiftlet) getSwiftlet("sys$log");
}

// Create Extension Swiftlet Deployer
if (!isHA())
startSwiftletDeployer();
saveConfigIfDirty();
} catch (Exception e) {
e.printStackTrace();
trace("Kernel swiftlet: '" + actSwiftletName + "', exception during startup: " + e.getMessage());
System.err.println("Exception during startup kernel swiftlet '" + actSwiftletName + "': " + e.getMessage());
System.exit(-1);
}
logSwiftlet = (LogSwiftlet) getSwiftlet("sys$log");
trace("Kernel swiftlets started");
}

Expand Down Expand Up @@ -286,6 +305,7 @@ protected void startKernelSwiftlet(String actSwiftletName, Map table) throws Exc
protected void stopKernelSwiftlets() {
trace("stopKernelSwiftlets");
logSwiftlet.logInformation("SwiftletManager", "stopKernelSwiftlets");
stopSwiftletDeployer();
List al = new ArrayList();
synchronized (sSemaphore) {
for (int i = kernelSwiftletNames.length - 1; i >= 0; i--) {
Expand Down Expand Up @@ -354,6 +374,22 @@ public void setStrippedMode(boolean strippedMode) {
this.strippedMode = strippedMode;
}

public void setConfigDirty(boolean configDirty) {
this.configDirty.set(configDirty);
}

public void saveConfigIfDirty() {
if (configDirty.get()) {
logSwiftlet.logInformation("SwiftletManager", "Configuration was updated, saving ...");
saveConfiguration();
}
}

public String getLastSwiftlet() {
Object[] arr = swiftletTable.keySet().toArray();
return (String) arr[arr.length - 1];
}

/**
* Loads a new Extension Swiftlet. Will be used from the Deploy Swiftlet only.
*
Expand Down Expand Up @@ -868,6 +904,7 @@ public void shutdown(boolean removeShutdownHook) {
public synchronized void shutdown() {
System.out.println("Shutdown SwiftMQ " + Version.getKernelVersion() + " " + "[" + getRouterName() + "] ...");
trace("shutdown");
saveConfigIfDirty();
if (configfileWatchdog != null)
timerSwiftlet.removeTimerListener(configfileWatchdog);
memoryMeter.close();
Expand Down Expand Up @@ -897,7 +934,13 @@ public String getRouterName() {
* Saves this router's configuration.
*/
public void saveConfiguration() {
saveConfiguration(RouterConfiguration.Singleton());
saveLock.lock();
try {
saveConfiguration(RouterConfiguration.Singleton());
configDirty.set(false);
} finally {
saveLock.unlock();
}
}

protected Element[] getOptionalElements() {
Expand Down Expand Up @@ -938,11 +981,11 @@ protected String[] saveConfiguration(RouterConfigInstance entity) {
Map configs = entity.getEntities();
for (Object o : configs.keySet()) {
Entity c = (Entity) configs.get((String) o);
if (c instanceof Configuration)
if (c instanceof Configuration) {
XMLUtilities.configToXML((Configuration) c, root);
}
}
XMLUtilities.writeDocument(doc, configFilename);
routerConfig = doc;
al.add("Configuration saved to file '" + configFilename + "'.");
} catch (Exception e) {
al.add("Error saving configuration: " + e);
Expand Down

0 comments on commit 1f71ecd

Please sign in to comment.