1 package org.objectweb.jtests.providers.admin; 2 3 import com.swiftmq.admin.cli.*; 4 import org.objectweb.jtests.jms.admin.Admin; 5 6 import javax.jms.*; 7 import javax.naming.*; 8 import java.util.Properties ; 9 10 public class SwiftMQAdmin implements Admin 11 { 12 InitialContext ctx = null; 13 CLI cli = null; 14 QueueConnection qc = null; 15 16 public SwiftMQAdmin() 17 { 18 try 19 { 20 Properties props = new Properties (); 21 props.setProperty("java.naming.factory.initial", "com.swiftmq.jndi.InitialContextFactoryImpl"); 22 props.setProperty("java.naming.provider.url", "smqp://localhost:4001/timeout=10000"); 23 ctx = new InitialContext(props); 24 QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup("plainsocket@router1"); 25 qc = qcf.createQueueConnection(); 26 cli = new CLI(qc); 27 cli.waitForRouter("router1"); 28 cli.executeCommand("sr router1"); 29 try 30 { 31 cli.executeCommand("cc /sys$jndi/aliases"); 32 cli.executeCommand("delete QueueConnectionFactory"); 33 cli.executeCommand("delete TopicConnectionFactory"); 34 cli.executeCommand("delete testqueue"); 35 } catch (CLIException e) 36 { 37 } 38 } catch (Exception e) 39 { 40 e.printStackTrace(); 41 System.exit(-1); 42 } 43 } 44 45 public String getName() 46 { 47 return "SwiftMQ"; 48 } 49 50 public InitialContext createInitialContext() 51 throws NamingException 52 { 53 return ctx; 54 } 55 56 public void createQueueConnectionFactory(String name) 57 { 58 try 59 { 60 cli.executeCommand("cc /sys$jndi/aliases"); 61 cli.executeCommand("new " + name + " map-to plainsocket@router1"); 62 } catch (CLIException e) 63 { 64 e.printStackTrace(); 65 System.exit(-1); 66 } 67 } 68 69 public void createTopicConnectionFactory(String name) 70 { 71 try 72 { 73 cli.executeCommand("cc /sys$jndi/aliases"); 74 cli.executeCommand("new " + name + " map-to plainsocket@router1"); 75 } catch (CLIException e) 76 { 77 e.printStackTrace(); 78 System.exit(-1); 79 } 80 } 81 82 public void createConnectionFactory(String name) 83 { 84 createQueueConnectionFactory(name); 85 } 86 87 public void createQueue(String name) 88 { 89 try 90 { 91 cli.executeCommand("cc /sys$queuemanager/queues"); 92 cli.executeCommand("new " + name); 93 cli.executeCommand("cc /sys$jndi/aliases"); 94 cli.executeCommand("new " + name + " map-to " + name + "@router1"); 95 } catch (CLIException e) 96 { 97 e.printStackTrace(); 98 System.exit(-1); 99 } 100 } 101 102 public void createTopic(String name) 103 { 104 try 105 { 106 cli.executeCommand("cc /sys$topicmanager/topics"); 107 String [] s = cli.getContextEntities(); 108 boolean found = false; 109 if (s != null) 110 { 111 for (int i = 0; i < s.length; i++) 112 { 113 if (s[i].equals(name)) 114 { 115 found = true; 116 break; 117 } 118 } 119 } 120 if (!found) 121 cli.executeCommand("new " + name); 122 } catch (CLIException e) 123 { 124 e.printStackTrace(); 125 System.exit(-1); 126 } 127 } 128 129 public void deleteQueue(String name) 130 { 131 try 132 { 133 cli.executeCommand("cc /sys$queuemanager/queues"); 134 cli.executeCommand("delete " + name); 135 cli.executeCommand("cc /sys$jndi/aliases"); 136 cli.executeCommand("delete " + name); 137 } catch (CLIException e) 138 { 139 e.printStackTrace(); 140 System.exit(-1); 141 } 142 } 143 144 public void deleteTopic(String name) 145 { 146 } 148 149 public void deleteQueueConnectionFactory(String name) 150 { 151 try 152 { 153 cli.executeCommand("cc /sys$jndi/aliases"); 154 cli.executeCommand("delete " + name); 155 } catch (CLIException e) 156 { 157 e.printStackTrace(); 158 System.exit(-1); 159 } 160 } 161 162 public void deleteTopicConnectionFactory(String name) 163 { 164 try 165 { 166 cli.executeCommand("cc /sys$jndi/aliases"); 167 cli.executeCommand("delete " + name); 168 } catch (CLIException e) 169 { 170 e.printStackTrace(); 171 System.exit(-1); 172 } 173 } 174 175 public void deleteConnectionFactory(String name) 176 { 177 deleteQueueConnectionFactory(name); 178 } 179 } 180 | Popular Tags |