Commit 7ef6e0da authored by Yohann CINTRE's avatar Yohann CINTRE
Browse files

Adding org.ow2.joram.admin package

parent d1c4b65a
package org.ow2.joram.admin;
import org.objectweb.joram.mom.dest.QueueImplMBean;
import org.objectweb.joram.mom.dest.TopicImplMBean;
import org.objectweb.joram.mom.proxies.ClientSubscriptionMBean;
import org.objectweb.joram.mom.proxies.ProxyImplMBean;
public interface DestinationListener {
public void onQueueAdded(String queueName, QueueImplMBean queue);
public void onQueueRemoved(String queueName, QueueImplMBean queue);
public void onTopicAdded(String topicName, TopicImplMBean topic);
public void onTopicRemoved(String topicName, TopicImplMBean topic);
public void onSubscriptionAdded(String userName, ClientSubscriptionMBean subscription);
public void onSubscriptionRemoved(String userName, ClientSubscriptionMBean subscription);
public void onUserAdded(String userName, ProxyImplMBean user);
public void onUserRemoved(String userName, ProxyImplMBean user);
}
package org.ow2.joram.admin;
public class JORAMInterface {
SysoListener listener;
public JORAMInterface(String login, String password) throws Exception {
listener = new SysoListener();
boolean connected = false;
JoramAdmin admin = new JoramAdminImpl();
connected = admin.connect(login, password);
if(!connected) throw new Exception("Erreur de login/password");
admin.start(listener);
}
public SysoListener getListener() {
return listener;
}
}
package org.ow2.joram.admin;
public interface JoramAdmin {
public boolean connect(String login, String password);
public void start(DestinationListener listener);
public void stop();
public void disconnect();
}
\ No newline at end of file
package org.ow2.joram.admin;
import javax.management.MBeanServerNotification;
import javax.management.Notification;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import javax.management.ObjectName;
import org.objectweb.joram.mom.dest.QueueImpl;
import org.objectweb.joram.mom.dest.TopicImpl;
import org.objectweb.joram.mom.proxies.ClientSubscriptionMBean;
import org.objectweb.joram.mom.proxies.ProxyImplMBean;
import fr.dyade.aaa.agent.AgentServer;
import fr.dyade.aaa.util.management.MXWrapper;
public class JoramAdminImpl implements JoramAdmin {
static final String REGISTERED = "JMX.mbean.registered";
static final String UNREGISTERED = "JMX.mbean.unregistered";
ObjectName ConnectionON, UserON, DestinationON;
DestinationListener adminListener;
public boolean connect(String login, String password) {
return login.equals(password);
}
public void disconnect() {
}
public void start(DestinationListener adminListener) {
this.adminListener = adminListener;
NotificationListener jmxListener = new MyNotificationListener();
NotificationFilter filter = new MyNotificationFilter();
try {
ConnectionON = new ObjectName("Joram#0:type=Connection,*");
UserON = new ObjectName("Joram#0:type=User,*");
DestinationON = new ObjectName("Joram#0:type=Destination,*");
MXWrapper.init();
try {
MXWrapper.addNotificationListener(new ObjectName("JMImplementation:type=MBeanServerDelegate"),
jmxListener, filter, null);
} catch (NullPointerException exc) {
System.err.println("JMX must be enabled, use -Dcom.sun.management.jmxremote "
+ "-DMXServer=com.scalagent.jmx.JMXServer options in command line.");
System.exit(-1);
}
AgentServer.init((short) 0, "./s0", null);
AgentServer.start();
Thread.sleep(1000L);
} catch (Exception exc) {
System.out.println("FATAL: Error launching JORAM server.");
exc.printStackTrace();
}
}
public void stop() {
AgentServer.stop();
}
class MyNotificationListener implements NotificationListener {
public void handleNotification(Notification n, Object handback) {
try {
MBeanServerNotification not = (MBeanServerNotification) n;
ObjectName mbeanName = not.getMBeanName();
Object mbean = MXWrapper.getMBeanInstance(mbeanName);
if (UserON.apply(mbeanName)) {
if (mbean instanceof ProxyImplMBean) {
ProxyImplMBean user = (ProxyImplMBean) mbean;
if (not.getType().equals(REGISTERED)) {
adminListener.onUserAdded(user.getName(), user);
} else if (not.getType().equals(UNREGISTERED)) {
adminListener.onUserRemoved(user.getName(), user);
}
} else if (mbean instanceof ClientSubscriptionMBean) {
ClientSubscriptionMBean subscription = (ClientSubscriptionMBean) mbean;
if (not.getType().equals(REGISTERED)) {
adminListener.onSubscriptionAdded(subscription.getName(), subscription);
} else if (not.getType().equals(UNREGISTERED)) {
adminListener.onSubscriptionRemoved(subscription.getName(), subscription);
}
} else {
System.out.println("Unknown User: " + mbean.getClass().getName());
}
} else if (DestinationON.apply(mbeanName)) {
if (mbean instanceof QueueImpl) {
QueueImpl queue = (QueueImpl) mbean;
if (not.getType().equals(REGISTERED)) {
adminListener.onQueueAdded(queue.getName(), queue);
} else if (not.getType().equals(UNREGISTERED)) {
adminListener.onQueueRemoved(queue.getName(), queue);
}
} else if (mbean instanceof TopicImpl) {
TopicImpl topic = (TopicImpl) mbean;
if (not.getType().equals(REGISTERED)) {
adminListener.onTopicAdded(topic.getName(), topic);
} else if (not.getType().equals(UNREGISTERED)) {
adminListener.onTopicRemoved(topic.getName(), topic);
}
} else {
System.out.println("Unknown Destination: " + mbean.getClass().getName());
}
}
} catch (Throwable exc) {
exc.printStackTrace();
}
}
}
static class MyNotificationFilter implements NotificationFilter {
private static final long serialVersionUID = 1L;
public boolean isNotificationEnabled(Notification notification) {
return true;
}
}
}
package org.ow2.joram.admin;
public class Main {
public static void main(String[] args) {
JoramAdmin admin = new JoramAdminImpl();
admin.connect("root", "root");
admin.start(new SysoListener());
}
}
package org.ow2.joram.admin;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.objectweb.joram.mom.dest.DestinationImplMBean;
import org.objectweb.joram.mom.dest.QueueImplMBean;
import org.objectweb.joram.mom.dest.TopicImplMBean;
import org.objectweb.joram.mom.messages.MessageView;
import org.objectweb.joram.mom.proxies.ClientSubscriptionMBean;
import org.objectweb.joram.mom.proxies.ProxyImplMBean;
public class SysoListener implements DestinationListener {
private boolean printTrace = false;
private Map<String, DestinationImplMBean> destinations = new HashMap<String, DestinationImplMBean>();
private Map<String, ProxyImplMBean> users = new HashMap<String, ProxyImplMBean>();
private List<ClientSubscriptionMBean> subscriptions = new ArrayList<ClientSubscriptionMBean>();
public void onQueueAdded(String queueName, QueueImplMBean queue) {
if(printTrace) System.out.println();
if(printTrace) System.out.println(" +++ Queue creation : " + queueName);
destinations.put(queueName, queue);
if(printTrace) printStats();
}
public void onQueueRemoved(String queueName, QueueImplMBean queue) {
if(printTrace) System.out.println();
if(printTrace) System.out.println(" --- Queue deletion : " + queueName);
destinations.remove(queueName);
}
public void onTopicAdded(String topicName, TopicImplMBean topic) {
if(printTrace) System.out.println();
if(printTrace) System.out.println(" +++ Topic creation : " + topicName);
destinations.put(topicName, topic);
if(printTrace) printStats();
if(printTrace) System.out.println();
}
public void onTopicRemoved(String topicName, TopicImplMBean topic) {
if(printTrace) System.out.println();
if(printTrace) System.out.println(" --- Topic deletion : " + topicName);
destinations.remove(topicName);
}
private void printStats() {
Iterator<Entry<String, DestinationImplMBean>> iterator = destinations.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, DestinationImplMBean> entry = iterator.next();
System.out.println(" -> " + entry.getKey() + " -> "
+ entry.getValue().getNbMsgsDeliverSinceCreation() + " messages delivered.");
if (entry.getValue() instanceof QueueImplMBean) {
List msgs = ((QueueImplMBean) entry.getValue()).getMessagesView();
Iterator<?> iter = msgs.iterator();
while (iter.hasNext()) {
MessageView msg = (MessageView) iter.next();
System.out.println(" " + msg);
}
}
}
}
public void onSubscriptionAdded(String userName, ClientSubscriptionMBean subscription) {
if(printTrace) System.out.println(" **** Subscription creation for " + userName + " : " + subscription.getName());
subscriptions.add(subscription);
}
public void onSubscriptionRemoved(String userName, ClientSubscriptionMBean subscription) {
if(printTrace) System.out.println(" **** Subscription deletion for " + userName + " : " + subscription.getName());
subscriptions.remove(subscription);
}
public void onUserAdded(String userName, ProxyImplMBean user) {
if(printTrace) System.out.println();
if(printTrace) System.out.println(" ** User creation : " + userName);
users.put(userName, user);
}
public void onUserRemoved(String userName, ProxyImplMBean user) {
if(printTrace) System.out.println(" ** User deletion : " + userName);
if(printTrace) System.out.println();
users.remove(userName);
}
public Map<String, DestinationImplMBean> getDestinations() {
return destinations;
}
public Map<String, ProxyImplMBean> getUsers() {
return users;
}
public List<ClientSubscriptionMBean> getSubscription() {
return subscriptions;
}
}
<?xml version="1.0" encoding="WINDOWS-1252" standalone="no"?>
<jardesc>
<jar path="Joram/ship/bundle/joram-admin-bundle.jar"/>
<options buildIfNeeded="true" compress="true" descriptionLocation="/Joram/src/org/ow2/joram/admin/jardesc.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
<selectedProjects/>
<manifest generateManifest="false" manifestLocation="/Joram/src/org/ow2/joram/admin/manifest.mf" manifestVersion="1.0" reuseManifest="false" saveManifest="true" usesManifest="true">
<sealing sealJar="false">
<packagesToSeal/>
<packagesToUnSeal/>
</sealing>
</manifest>
<selectedElements exportClassFiles="true" exportJavaFiles="true" exportOutputFolder="false">
<javaElement handleIdentifier="=Joram/src&lt;org.ow2.joram.admin{AdminActivator.java"/>
<javaElement handleIdentifier="=Joram/src&lt;org.ow2.joram.admin{Main.java"/>
<javaElement handleIdentifier="=Joram/src&lt;org.ow2.joram.admin{SysoListener.java"/>
<javaElement handleIdentifier="=Joram/src&lt;org.ow2.joram.admin{JoramAdminSimulator.java"/>
<javaElement handleIdentifier="=Joram/src&lt;org.ow2.joram.admin{JoramAdmin.java"/>
<javaElement handleIdentifier="=Joram/src&lt;org.ow2.joram.admin{DestinationListener.java"/>
<javaElement handleIdentifier="=Joram/src&lt;org.ow2.joram.admin{JoramAdminOSGi.java"/>
</selectedElements>
</jardesc>
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: JORAM :: Admin MBean Tracker
Bundle-SymbolicName: org.ow2.joram.admin
Export-Package: org.ow2.joram.admin;uses:="org.objectweb.joram.mom.dest,org.osgi.util.tracker,org.osgi.framework"
Import-Package: org.osgi.framework,
org.osgi.util.tracker,
org.objectweb.joram.mom.dest
Bundle-Description: Joram Admin MBean Tracker
Bundle-Vendor: Scalagent D.T.
Bundle-Activator: org.ow2.joram.admin.AdminActivator
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