Skip to content
Snippets Groups Projects
Commit 0a075bd8 authored by felmer's avatar felmer
Browse files

SSDM-1324: list commands of all command queues.

SVN: 33022
parent cdfe85f4
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
package ch.systemsx.cisd.openbis.dss.generic.server; package ch.systemsx.cisd.openbis.dss.generic.server;
import java.io.File; import java.io.File;
import java.io.FilenameFilter;
import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -46,6 +49,8 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.DatasetDescription; ...@@ -46,6 +49,8 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.DatasetDescription;
*/ */
class DataSetCommandExecutor implements IDataSetCommandExecutor class DataSetCommandExecutor implements IDataSetCommandExecutor
{ {
private static final String COMMAND_QUEUE_FILE_PREFIX = "commandQueue";
private final static Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION, private final static Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION,
DataSetCommandExecutor.class); DataSetCommandExecutor.class);
...@@ -82,7 +87,7 @@ class DataSetCommandExecutor implements IDataSetCommandExecutor ...@@ -82,7 +87,7 @@ class DataSetCommandExecutor implements IDataSetCommandExecutor
private static File getCommandQueueFile(File store, String nameOrNull) private static File getCommandQueueFile(File store, String nameOrNull)
{ {
String fileName = "commandQueue"; String fileName = COMMAND_QUEUE_FILE_PREFIX;
if (StringUtils.isNotBlank(nameOrNull)) if (StringUtils.isNotBlank(nameOrNull))
{ {
fileName += "-" + nameOrNull; fileName += "-" + nameOrNull;
...@@ -212,28 +217,54 @@ class DataSetCommandExecutor implements IDataSetCommandExecutor ...@@ -212,28 +217,54 @@ class DataSetCommandExecutor implements IDataSetCommandExecutor
*/ */
public static void listQueuedCommands(File store) public static void listQueuedCommands(File store)
{ {
final File queueFile = getCommandQueueFile(store); List<File> commandQueueFiles = listCommandQueueFiles(store);
final IExtendedBlockingQueue<IDataSetCommand> commandQueue = for (File queueFile : commandQueueFiles)
PersistentExtendedBlockingQueueFactory.<IDataSetCommand> createSmartPersist(queueFile);
if (commandQueue.isEmpty())
{
System.out.println("Command queue is empty.");
} else
{ {
System.out.println("Found " + commandQueue.size() + " items in command queue:"); if (commandQueueFiles.size() != 1)
for (final IDataSetCommand cmd : commandQueue)
{ {
try String fileName = queueFile.getName();
String queueName = "Default command queue";
if (fileName.length() > COMMAND_QUEUE_FILE_PREFIX.length())
{ {
System.out.println(cmd.getDescription()); queueName = "Command queue '" + fileName.substring(COMMAND_QUEUE_FILE_PREFIX.length() + 1) + "'";
} catch (RuntimeException ex) }
System.out.println("======= " + queueName + " (" + queueFile + ")");
}
final IExtendedBlockingQueue<IDataSetCommand> commandQueue =
PersistentExtendedBlockingQueueFactory.<IDataSetCommand> createSmartPersist(queueFile);
if (commandQueue.isEmpty())
{
System.out.println("Command queue is empty.");
} else
{
System.out.println("Found " + commandQueue.size() + " items in command queue:");
for (final IDataSetCommand cmd : commandQueue)
{ {
System.err.printf("Error showing description of command '%s':\n", cmd try
.getClass().getSimpleName()); {
ex.printStackTrace(); System.out.println(cmd.getDescription());
} catch (RuntimeException ex)
{
System.err.printf("Error showing description of command '%s':\n", cmd
.getClass().getSimpleName());
ex.printStackTrace();
}
} }
} }
} }
} }
private static List<File> listCommandQueueFiles(File store)
{
File[] commandQueueFiles = store.listFiles(new FilenameFilter()
{
@Override
public boolean accept(File file, String name)
{
return name.startsWith(COMMAND_QUEUE_FILE_PREFIX);
}
});
return commandQueueFiles == null ? Collections.<File>emptyList() : Arrays.asList(commandQueueFiles);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment