1. import java.io.*;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. public class QueueSync {
  7. public static void main(String[] args) {
  8. String configFilePath = args[0]; // Configuration file path as first argument
  9. if (configFilePath == null || configFilePath.isEmpty()) {
  10. System.err.println("Error: Configuration file path is required.");
  11. System.exit(1);
  12. }
  13. try {
  14. syncQueues(configFilePath);
  15. } catch (IOException e) {
  16. System.err.println("Error reading/processing config file: " + e.getMessage());
  17. System.exit(1);
  18. }
  19. }
  20. public static void syncQueues(String configFilePath) throws IOException {
  21. // Read configuration from file
  22. Map<String, List<String>> queueConfigs = readQueueConfigs(configFilePath);
  23. // Iterate through each queue configuration
  24. for (Map.Entry<String, List<String>> entry : queueConfigs.entrySet()) {
  25. String queueName = entry.getKey();
  26. List<String> resources = entry.getValue();
  27. // Simulate dry-run synchronization
  28. System.out.println("Syncing queue: " + queueName);
  29. for (String resource : resources) {
  30. System.out.println(" - Resource: " + resource);
  31. // In a real scenario, this would involve actual queue synchronization logic.
  32. // For dry-run, we just print the resource.
  33. }
  34. System.out.println("---");
  35. }
  36. }
  37. private static Map<String, List<String>> readQueueConfigs(String configFilePath) throws IOException {
  38. Map<String, List<String>> queueConfigs = new HashMap<>();
  39. try (BufferedReader reader = new BufferedReader(new FileReader(configFilePath))) {
  40. String line;
  41. while ((line = reader.readLine()) != null) {
  42. line = line.trim();
  43. if (!line.isEmpty() && line.startsWith("#")) {
  44. continue; // Skip comments
  45. }
  46. String[] parts = line.split(":", 2);
  47. if (parts.length == 2) {
  48. String queueName = parts[0].trim();
  49. String resourcesStr = parts[1].trim();
  50. List<String> resources = new ArrayList<>();
  51. for (String resource : resourcesStr.split(",")) {
  52. resources.add(resource.trim());
  53. }
  54. queueConfigs.put(queueName, resources);
  55. }
  56. }
  57. }
  58. return queueConfigs;
  59. }
  60. }

Add your comment