Commit 26645bfb authored by Thibaut Guinoiseau's avatar Thibaut Guinoiseau
Browse files

MOM cmds use sync agent for delete user/dest

parent 79acbfb2
......@@ -31,6 +31,8 @@ import org.objectweb.joram.mom.notifications.FwdAdminRequestNot;
import org.objectweb.joram.shared.admin.AdminReply;
import org.objectweb.joram.shared.admin.CreateDestinationRequest;
import org.objectweb.joram.shared.admin.CreateUserRequest;
import org.objectweb.joram.shared.admin.DeleteDestination;
import org.objectweb.joram.shared.admin.DeleteUser;
import org.objectweb.joram.shared.messages.Message;
import org.objectweb.joram.shared.security.Identity;
import org.objectweb.joram.shared.security.SimpleIdentity;
......@@ -50,6 +52,7 @@ public class SynchronousAgent extends Agent {
//TODO: Doesn't work. Might be useless because this agent is to be merged to AdminTopic
// static private Object monitor = new Object();
//TODO: Should be accessed as a service => Will be done when merged
static public synchronized SynchronousAgent getSynchronousAgent()
throws IOException, InterruptedException {
if(INSTANCE == null) {
......@@ -83,7 +86,7 @@ public class SynchronousAgent extends Agent {
INSTANCE = this;
// notifyInitialized();
}
// private static synchronized void notifyInitialized() {
// monitor.notifyAll();
// }
......@@ -149,6 +152,39 @@ public class SynchronousAgent extends Agent {
AdminReply reply = (AdminReply) msg.getAdminMessage();
return reply.succeeded();
}
public synchronized boolean deleteUser(String userName, String agentId)
throws Exception {
DeleteUser req = new DeleteUser(userName,agentId);
String msgId = nextMsgId();
FwdAdminRequestNot not = new FwdAdminRequestNot(req,
getId(),
msgId,
null);
sendTo(AdminTopic.getDefault(), not);
while(!requests.containsKey(msgId))
wait();
Message msg = requests.remove(msgId);
AdminReply reply = (AdminReply) msg.getAdminMessage();
return reply.succeeded();
}
public synchronized boolean deleteDest(String agentId)
throws Exception {
DeleteDestination req = new DeleteDestination(agentId);
String msgId = nextMsgId();
FwdAdminRequestNot not = new FwdAdminRequestNot(req,
getId(),
msgId,
null);
sendTo(AdminTopic.getDefault(), not);
while(!requests.containsKey(msgId))
wait();
Message msg = requests.remove(msgId);
AdminReply reply = (AdminReply) msg.getAdminMessage();
return reply.succeeded();
}
private synchronized String nextMsgId() {
return "ID:"+getAgentId()+"m"+nextMsgId++;
......
......@@ -22,8 +22,6 @@
*/
package org.ow2.joram.shell.jndi.commands;
import java.util.regex.Pattern;
import javax.naming.NamingException;
import org.osgi.framework.BundleContext;
......@@ -45,7 +43,6 @@ public class JNDICommandsImpl implements JNDICommands {
private BundleContext bundleContext;
private ServiceTracker tracker;
@SuppressWarnings("unchecked")
public JNDICommandsImpl(BundleContext bundleContext) {
this.bundleContext = bundleContext;
this.tracker = new ServiceTracker(this.bundleContext,
......
......@@ -512,7 +512,30 @@ public class MOMCommandsImpl implements MOMCommands {
for(int i = 0; i < objs.length; i++) {
a = (AgentMBean) objs[i];
if(a.getName().equals(args[1])) {
a.delete();
if(category.equalsIgnoreCase("user"))
try {
if(SynchronousAgent.getSynchronousAgent().deleteUser(a.getName(), a.getAgentId()))
System.out.println("User successfully deleted.");
else
System.err.println("User suppression failed.");
} catch (InterruptedException e) {
System.err.println("Error: Interrupted");
} catch (Exception e) {
System.err.println("Error: Exception raised");
e.printStackTrace();
}
else
try {
if(SynchronousAgent.getSynchronousAgent().deleteDest(a.getAgentId()))
System.out.println("Destination successfully deleted.");
else
System.err.println("Destination suppression failed.");
} catch (InterruptedException e) {
System.err.println("Error: Interrupted");
} catch (Exception e) {
System.err.println("Error: Exception raised");
e.printStackTrace();
}
return;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment