1 package com.scalagent.joram.osgi.server; 2 3 import java.io.*; 4 import java.util.*; 5 6 import org.osgi.framework.*; 7 8 import com.scalagent.joram.osgi.server.service.JoramAdmin; 9 10 import org.objectweb.joram.client.jms.ConnectionFactory; 11 import org.objectweb.joram.client.jms.local.LocalConnectionFactory; 12 import org.objectweb.joram.client.jms.admin.AdminModule; 13 import org.objectweb.joram.client.jms.admin.User; 14 import org.objectweb.joram.client.jms.Queue; 15 import org.objectweb.joram.client.jms.Topic; 16 17 import fr.dyade.aaa.agent.AgentServer; 18 import fr.dyade.aaa.agent.*; 19 import fr.dyade.aaa.agent.conf.*; 20 21 public class Activator implements BundleActivator { 22 23 private static BundleContext bcontext; 24 25 public static BundleContext getBundleContext() { 26 return bcontext; 27 } 28 29 35 public void start(BundleContext context) throws Exception { 36 bcontext = context; 37 38 startAgentServer(); 39 40 Properties props = new Properties(); 41 context.registerService(JoramAdmin.class.getName(), 42 new JoramAdminImpl(), 43 props); 44 } 45 46 private void startAgentServer() throws Exception { 47 ClassLoader classLoader = getClass().getClassLoader(); 49 InputStream is = classLoader.getResourceAsStream("a3server.prop"); 50 Properties a3prop = new Properties(); 51 a3prop.load(is); 52 53 String serverId = a3prop.getProperty("sid"); 54 String path = a3prop.getProperty("path"); 55 String relativePath = a3prop.getProperty("relativePath"); 56 String storageDirName = a3prop.getProperty("storageDirName"); 57 String logicalServerName = a3prop.getProperty("logicalServerName"); 58 59 File storageDir = new File(new File(path), storageDirName); 60 File lockFile = new File(storageDir, "lock"); 61 lockFile.delete(); 62 63 if (logicalServerName != null) try { 65 String debugDir = System.getProperty( 66 Debug.DEBUG_DIR_PROPERTY, Debug.DEFAULT_DEBUG_DIR); 67 File debugFile = new File(debugDir, logicalServerName); 68 if ((debugFile != null) && 69 debugFile.exists() && 70 debugFile.isDirectory()) { 71 debugDir = debugFile.getPath(); 72 String debugFileName = System.getProperty( 73 Debug.DEBUG_FILE_PROPERTY, Debug.DEFAULT_DEBUG_FILE); 74 debugFile = new File(debugFile, debugFileName); 75 if ((debugFile != null) && 76 debugFile.exists() && 77 debugFile.isFile() && 78 (debugFile.length() != 0)) { 79 Debug.setDebugDir(debugDir); 80 Debug.setDebugFileName(debugFileName); 81 } 82 } 83 } catch (Exception exc) { 84 } 85 86 AgentServer.init(new String [] { 87 serverId, 88 storageDir.getAbsolutePath()}); 89 AgentServer.start(); 90 91 } 92 93 98 public void stop(BundleContext context) { 99 stopAgentServer(); 100 } 101 102 private void stopAgentServer() { 103 AgentServer.stop(); 104 AgentServer.reset(); 105 } 106 107 public static class JoramAdminImpl implements JoramAdmin { 108 109 private String rootUserName= "root"; 110 111 public void setRootUserName(String root) { 112 this.rootUserName = root; 113 } 114 115 private String rootPassword = "root"; 116 117 public void setRootPassword(String password) { 118 this.rootPassword = password; 119 } 120 121 124 public ConnectionFactory getLocalConnectionFactory() throws Exception { 125 return (ConnectionFactory) LocalConnectionFactory.create(); 126 } 127 128 131 public boolean executeAdminXML(Reader reader) throws Exception { 132 return AdminModule.executeAdmin(reader); 133 } 134 135 140 public void createUser(String name, String password) throws Exception { 141 try { 142 AdminModule.collocatedConnect(rootUserName, rootPassword); 143 User.create(name, password); 144 } finally { 145 AdminModule.disconnect(); 146 } 147 } 148 149 157 public Queue createQueue(String name) throws Exception { 158 Queue queue = null; 159 try { 160 AdminModule.collocatedConnect(rootUserName, rootPassword); 161 queue = Queue.create(name); 162 queue.setFreelyWriteable(true); 163 queue.setFreelyReadable(true); 164 } finally { 165 AdminModule.disconnect(); 166 } 167 return queue; 168 } 169 170 176 public Topic createTopic(String name) throws Exception { 177 Topic topic = null; 178 try { 179 AdminModule.collocatedConnect(rootUserName, rootPassword); 180 topic = Topic.create(name); 181 topic.setFreelyWriteable(true); 182 topic.setFreelyReadable(true); 183 } finally { 184 AdminModule.disconnect(); 185 } 186 return topic; 187 } 188 189 192 public List getDestinations() throws Exception { 193 List destinations = null;; 194 try { 195 AdminModule.collocatedConnect(rootUserName, rootPassword); 196 destinations = AdminModule.getDestinations(); 197 } finally { 198 AdminModule.disconnect(); 199 } 200 return destinations; 201 } 202 203 206 public List getUsers() throws Exception { 207 List users = null;; 208 try { 209 AdminModule.collocatedConnect(rootUserName, rootPassword); 210 users = AdminModule.getUsers(); 211 } finally { 212 AdminModule.disconnect(); 213 } 214 return users; 215 } 216 } 217 } 218 | Popular Tags |