Skip to content

Commit

Permalink
Merge branch 'release/12.5.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
iitsoftware committed Feb 16, 2023
2 parents 50eafb3 + f1dc4e2 commit 809ea47
Show file tree
Hide file tree
Showing 11 changed files with 1,696 additions and 999 deletions.
4 changes: 2 additions & 2 deletions 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.5.2</version>
<version>12.5.3</version>

<name>SwiftMQ Client</name>
<description>Client for SwiftMQ Messaging System with JMS, AMQP 1.0 and file transfer over JMS.</description>
Expand Down Expand Up @@ -48,7 +48,7 @@
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.19</version>
<version>1.4.20</version>
</dependency>
<dependency>
<groupId>javax.jms</groupId>
Expand Down
112 changes: 81 additions & 31 deletions src/main/java/com/swiftmq/mgmt/CommandRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
* A CommandRegistry object will be attached to Entities/EntityLists. It contains
Expand All @@ -40,11 +41,12 @@
public class CommandRegistry implements Dumpable {
String contextName = null;
Entity myEntity = null;
ReentrantReadWriteLock lock = new ReentrantReadWriteLock();

/**
* @SBGen Collection of com.swiftmq.mgmt.Command
*/
ArrayList commands = new ArrayList();
List commands = new ArrayList();

transient CommandExecutor defaultCommand = null;

Expand Down Expand Up @@ -126,31 +128,43 @@ private String readDump(DataInput in) throws IOException {
return null;
}

public synchronized void writeContent(DataOutput out)
public void writeContent(DataOutput out)
throws IOException {
writeDump(out, contextName);
if (myEntity != null) {
out.writeByte(1);
Dumpalizer.dump(out, myEntity);
} else
out.writeByte(0);
out.writeInt(commands.size());
for (int i = 0; i < commands.size(); i++) {
Dumpalizer.dump(out, (Command) commands.get(i));
lock.readLock().lock();
try {
writeDump(out, contextName);
if (myEntity != null) {
out.writeByte(1);
Dumpalizer.dump(out, myEntity);
} else
out.writeByte(0);
out.writeInt(commands.size());
for (int i = 0; i < commands.size(); i++) {
Dumpalizer.dump(out, (Command) commands.get(i));
}
} finally {
lock.readLock().unlock();
}

}

public void readContent(DataInput in)
throws IOException {
DumpableFactory factory = new MgmtFactory();
contextName = readDump(in);
if (in.readByte() == 1)
myEntity = (Entity) Dumpalizer.construct(in, factory);
commands = new ArrayList();
int size = in.readInt();
for (int i = 0; i < size; i++) {
commands.add(Dumpalizer.construct(in, factory));
lock.writeLock().lock();
try {
DumpableFactory factory = new MgmtFactory();
contextName = readDump(in);
if (in.readByte() == 1)
myEntity = (Entity) Dumpalizer.construct(in, factory);
commands = new ArrayList();
int size = in.readInt();
for (int i = 0; i < size; i++) {
commands.add(Dumpalizer.construct(in, factory));
}
} finally {
lock.writeLock().unlock();
}

}

/**
Expand All @@ -159,7 +173,13 @@ public void readContent(DataInput in)
* @param name name.
*/
public void setName(String name) {
this.contextName = name;
lock.writeLock().lock();
try {
this.contextName = name;
} finally {
lock.writeLock().unlock();
}

}

/**
Expand All @@ -169,16 +189,28 @@ public void setName(String name) {
* @param defaultCommand default command executor.
*/
public void setDefaultCommand(CommandExecutor defaultCommand) {
this.defaultCommand = defaultCommand;
lock.writeLock().lock();
try {
this.defaultCommand = defaultCommand;
} finally {
lock.writeLock().unlock();
}

}

/**
* Returns a list of all registered commands.
*
* @return command list.
*/
public ArrayList getCommands() {
return commands;
public List getCommands() {
lock.readLock().lock();
try {
return commands;
} finally {
lock.readLock().unlock();
}

}

/**
Expand All @@ -187,8 +219,14 @@ public ArrayList getCommands() {
* @param command command.
*/
public void addCommand(Command command) {
if (!commands.contains(command))
commands.add(command);
lock.writeLock().lock();
try {
if (!commands.contains(command))
commands.add(command);
} finally {
lock.writeLock().unlock();
}

}

/**
Expand All @@ -197,7 +235,13 @@ public void addCommand(Command command) {
* @param command command.
*/
public void removeCommand(Command command) {
commands.remove(command);
lock.writeLock().lock();
try {
commands.remove(command);
} finally {
lock.writeLock().unlock();
}

}

/**
Expand All @@ -207,12 +251,18 @@ public void removeCommand(Command command) {
* @return command or null.
*/
public Command findCommand(String[] cmd) {
for (int i = 0; i < commands.size(); i++) {
Command c = (Command) commands.get(i);
if (c.equals(cmd))
return c;
lock.readLock().lock();
try {
for (Object command : commands) {
Command c = (Command) command;
if (c.equals(cmd))
return c;
}
return null;
} finally {
lock.readLock().unlock();
}
return null;

}

private boolean isCommonCommand(String cmd) {
Expand Down
Loading

0 comments on commit 809ea47

Please sign in to comment.