Commit 3e266a23 authored by Thibaut Guinoiseau's avatar Thibaut Guinoiseau

Removed Felix dependencies from shell bundles

parent 84c62304
#############################################
### JORAM Shell ####
#############################################
By: Scalagent D.T.
I\ Installation
1) Required bundles
* Apache Felix Gogo bundles:
- Gogo Runtime
- Gogo Shell : simple TUI
- Gogo Commands: provides useful commands
* JORAM Shell bundles:
- Shell A3 : A3 commands
- Shell MOM : MOM commands
- Shell JNDI : JNDI commands
II\ U
......@@ -32,15 +32,9 @@
</build>
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.main</artifactId>
<version>${felix.main.version}</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.gogo.runtime</artifactId>
<version>${felix.gogo.runtime.version}</version>
<groupId>org.osgi</groupId>
<artifactId>org.osgi</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.joram</groupId>
......
......@@ -24,23 +24,23 @@ package org.ow2.joram.shell.a3;
import java.util.Hashtable;
import org.apache.felix.service.command.CommandProcessor;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.ow2.joram.shell.a3.commands.A3RTCommands;
import org.ow2.joram.shell.a3.commands.A3RTCommandsImpl;
import org.ow2.joram.shell.a3.commands.A3Commands;
import org.ow2.joram.shell.a3.commands.A3CommandsImpl;
public class Activator implements BundleActivator {
public void start(BundleContext bundleContext) throws Exception {
Hashtable<String, Object> prop = new Hashtable<String, Object>();
prop.put(CommandProcessor.COMMAND_SCOPE, A3RTCommandsImpl.NAMESPACE);
prop.put(CommandProcessor.COMMAND_FUNCTION,
new String[] {"engineLoad", "garbageRatio",
"restartServer", "startServer",
"stopServer", "close"});
bundleContext.registerService(A3RTCommands.class,
new A3RTCommandsImpl(bundleContext), prop);
//CommandProcessor.COMMAND_SCOPE="osgi.command.scope"
prop.put("osgi.command.scope",
A3CommandsImpl.NAMESPACE);
//CommandProcessor.COMMAND_FUNCTION="osgi.command.function"
prop.put("osgi.command.function",
A3CommandsImpl.COMMANDS);
bundleContext.registerService(A3Commands.class.getCanonicalName(),
new A3CommandsImpl(bundleContext), prop);
}
public void stop(BundleContext context) throws Exception {
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2012 - ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s):
*/
package org.ow2.joram.shell.a3.commands;
public interface A3Commands {
public void stopServer();
public void startServer();
public void restartServer();
public void engineLoad(String[] args);
public void garbageRatio(String[] args);
public void close();
public void info();
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2012 - ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s):
*/
package org.ow2.joram.shell.a3.commands;
import org.objectweb.util.monolog.api.LoggerFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.util.tracker.ServiceTracker;
import fr.dyade.aaa.agent.AgentServer;
import fr.dyade.aaa.agent.EngineMBean;
import fr.dyade.aaa.ext.NGTransactionMBean;
public class A3CommandsImpl implements A3Commands {
public static final String NAMESPACE = "joram:a3";
private static final int TIMEOUT = 1000;
// A3 Server default properties
public static final String AGENT_SERVER_ID_PROPERTY = "fr.dyade.aaa.agent.AgentServer.id";
public static final String AGENT_SERVER_CLUSTERID_PROPERTY = "fr.dyade.aaa.agent.AgentServer.clusterid";
public static final String AGENT_SERVER_STORAGE_PROPERTY = "fr.dyade.aaa.agent.AgentServer.storage";
public static final String[] COMMANDS = new String[] {
"engineLoad", "garbageRatio",
"restartServer", "startServer",
"stopServer", "close",
"info"};
// private static void help(String command) {
// StringBuffer buf = new StringBuffer();
// String fullCommand = "["+NAMESPACE+":]"+command;
// buf.append("Usage: ").append(fullCommand).append(" ");
// if(command.equals("")) {
// buf.append("");
// } else if(command.equals("")) {
// } else if(command.equals("")) {
// } else {
// System.err.println("Unknown command: "+command);
// return;
// }
// System.out.println(buf.toString());
// }
private BundleContext bundleContext;
private ServiceTracker engineTracker;
private ServiceTracker ngtTracker;
public A3CommandsImpl(BundleContext context) {
this.bundleContext = context;
this.engineTracker = new ServiceTracker
(bundleContext, EngineMBean.class.getCanonicalName(), null);
this.ngtTracker = new ServiceTracker
(bundleContext, NGTransactionMBean.class.getCanonicalName(), null);
engineTracker.open();
ngtTracker.open();
}
public void engineLoad(String[] args) {
EngineMBean engine = getEngine();
if(engine == null) {
System.err.println("Error: No engine found.");
return;
}
float load = engine.getAverageLoad1();
System.out.println("Engine load (for the last min.): "+load);
}
/* Charge du moteur de persistance transactionnel
* - 2 paramètres charge moyenne et max
* - par défaut pas de paramètres => charge moyenne = 5, charge max = 30
* - AgentServer:cons=Transaction,server=AgentServer#0:GarbageRatio
*/
public void garbageRatio(String[] args) {
NGTransactionMBean ngt;
try {
ngt = (NGTransactionMBean) ngtTracker.waitForService(TIMEOUT);
} catch (InterruptedException e) {
System.err.println("Error: Interrupted.");
ngt = null;
}
if(ngt == null) {
System.err.println("Error: No NG transaction found.");
return;
}
float load = ngt.getGarbageRatio();
System.out.println("Garbage operations ratio: "+load);
}
public void stopServer() {
System.out.print("Server stopping... "); System.out.flush();
AgentServer.stop();
AgentServer.reset();
System.out.println("Done.");
}
public void startServer() {
short sid = getShortProperty(AGENT_SERVER_ID_PROPERTY, (short) 0);
String path = getProperty(AGENT_SERVER_STORAGE_PROPERTY, "s"+sid);
short clusterId = getShortProperty(AGENT_SERVER_CLUSTERID_PROPERTY, AgentServer.NULL_ID);
System.out.print("Server starting... "); System.out.flush();
try {
LoggerFactory f = null;
AgentServer.init(sid,path,f,clusterId);
AgentServer.start();
} catch (Exception e) {
System.err.println("Error: "+e.getMessage());
}
System.out.println("Started.");
}
public void restartServer() {
stopServer();
startServer();
}
public void close() {
stopServer();
Bundle bundle0 = bundleContext.getBundle(0);
try {
bundle0.stop();
} catch (BundleException e) {
System.err.println("Error: Failed to stop the System Bundle.");
e.printStackTrace();
}
}
public void info() {
/*
* nbWaitingMessages : Valeur absolue, instantannée
* engineLoad1/5/15 : Moyenne de nbWaitingMessages sur 1/5/15 minutes => Plus pertinent
* garbageRation : (transaction), pas prioritaire.
*/
EngineMBean engine = getEngine();
NGTransactionMBean ngt = getNGTransaction();
if(engine!=null) {
System.out.println("Avg. engine load for the last min. : "+engine.getAverageLoad1());
System.out.println("Avg. engine load for the last 5 min. : "+engine.getAverageLoad5());
System.out.println("Avg. engine load for the last 15 min.: "+engine.getAverageLoad15());
System.out.println("Number of waiting messages : "+engine.getNbWaitingMessages());
} else {
System.err.println("Error: Can't find A3 engine.");
// System.out.println("Avg. engine load for the last min. : N/A");
// System.out.println("Avg. engine load for the last 5 min. : N/A");
// System.out.println("Avg. engine load for the last 15 min.: N/A");
// System.out.println("Number of waiting messages : N/A");
}
if(ngt!=null) {
System.out.println("Garbage ratio : "+ngt.getGarbageRatio());
}
}
private EngineMBean getEngine() {
try {
return (EngineMBean) engineTracker.waitForService(TIMEOUT);
} catch (InterruptedException e) {
return null;
}
}
private NGTransactionMBean getNGTransaction() {
try {
return (NGTransactionMBean) ngtTracker.waitForService(TIMEOUT);
} catch (InterruptedException e) {
return null;
}
}
private String getProperty(String prop, String defaultVal) {
String val = bundleContext.getProperty(prop);
if(val!=null)
return val;
else
return defaultVal;
}
private Short getShortProperty(String prop, Short defaultVal) {
String val = bundleContext.getProperty(prop);
try {
if(val!=null)
return Short.parseShort(val);
else
return defaultVal;
} catch(NumberFormatException e) {
return defaultVal;
}
}
}
......@@ -31,14 +31,8 @@
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.main</artifactId>
<version>${felix.main.version}</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.gogo.runtime</artifactId>
<version>${felix.gogo.runtime.version}</version>
<groupId>org.osgi</groupId>
<artifactId>org.osgi</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.joram</groupId>
......
......@@ -24,7 +24,6 @@ package org.ow2.joram.shell.jndi;
import java.util.Hashtable;
import org.apache.felix.service.command.CommandProcessor;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.ow2.joram.shell.jndi.commands.JNDICommands;
......@@ -37,17 +36,14 @@ public class Activator implements BundleActivator {
public void start(BundleContext context) throws Exception {
Hashtable<String, Object> prop = new Hashtable<String, Object>();
prop.put(CommandProcessor.COMMAND_SCOPE, "joram:jndi");
prop.put(CommandProcessor.COMMAND_FUNCTION,
new String[] {"getNamingContext",
"getStrOwnerId",
"setStrOwnerId",
"createSubcontext",
"destroySubcontext",
"lookup",
"unbind"});
//CommandProcessor.COMMAND_SCOPE="osgi.command.scope"
prop.put("osgi.command.scope",
JNDICommandsImpl.NAMESPACE);
//CommandProcessor.COMMAND_FUNCTION="osgi.command.function"
prop.put("osgi.command.function",
JNDICommandsImpl.COMMANDS);
this.bundleContext = context;
bundleContext.registerService(JNDICommands.class,
bundleContext.registerService(JNDICommands.class.getCanonicalName(),
new JNDICommandsImpl(bundleContext), prop);
}
......
......@@ -34,6 +34,13 @@ import fr.dyade.aaa.jndi2.impl.NamingContextMBean;
public class JNDICommandsImpl implements JNDICommands {
private static final int TIMEOUT = 1000;
public static final String NAMESPACE = "joram:jndi";
public static final String[] COMMANDS = new String[] {
"getNamingContext", "getStrOwnerId",
"setStrOwnerId", "createSubcontext",
"destroySubcontext", "lookup",
"unbind"};
private BundleContext bundleContext;
private ServiceTracker tracker;
......@@ -42,8 +49,8 @@ public class JNDICommandsImpl implements JNDICommands {
public JNDICommandsImpl(BundleContext bundleContext) {
this.bundleContext = bundleContext;
this.tracker = new ServiceTracker(this.bundleContext,
NamingContextMBean.class,
null);
NamingContextMBean.class.getCanonicalName(),
null);
this.tracker.open();
}
......
......@@ -31,14 +31,8 @@
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.main</artifactId>
<version>${felix.main.version}</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.gogo.runtime</artifactId>
<version>${felix.gogo.runtime.version}</version>
<groupId>org.osgi</groupId>
<artifactId>org.osgi</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.joram</groupId>
......
......@@ -24,7 +24,6 @@ package org.ow2.joram.shell.mom;
import java.util.Hashtable;
import org.apache.felix.service.command.CommandProcessor;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.ow2.joram.shell.mom.commands.MOMCommands;
......@@ -36,14 +35,14 @@ public class Activator implements BundleActivator {
public void start(BundleContext context) throws Exception {
Hashtable<String, Object> prop = new Hashtable<String, Object>();
prop.put(CommandProcessor.COMMAND_SCOPE, MOMCommandsImpl.NAMESPACE);
prop.put(CommandProcessor.COMMAND_FUNCTION,
new String[] {"list", "create",
"delete", "addUser",
"queueLoad", "subscriptionLoad",
"info", "lsMsg"});
//CommandProcessor.COMMAND_SCOPE="osgi.command.scope"
prop.put("osgi.command.scope",
MOMCommandsImpl.NAMESPACE);
//CommandProcessor.COMMAND_FUNCTION="osgi.command.function"
prop.put("osgi.command.function",
MOMCommandsImpl.COMMANDS);
this.bundleContext = context;
bundleContext.registerService(MOMCommands.class,
bundleContext.registerService(MOMCommands.class.getCanonicalName(),
new MOMCommandsImpl(bundleContext), prop);
}
......
......@@ -42,12 +42,6 @@ public interface MOMCommands {
*/
public void delete(String[] args);
/**
* Add a new user to the servers
* @param args parameters of the command
*/
public void addUser(String[] args);
/**
* Check the pending count of a queue
* @param args parameters of the command
......@@ -61,7 +55,7 @@ public interface MOMCommands {
public void subscriptionLoad(String[] args);
/**
* Display info about the JORAM server
* Display info about a destination (topic & subscription, queue)
* @param args ???
*/
public void info(String[] args);
......@@ -71,5 +65,28 @@ public interface MOMCommands {
* @param args {queue name, message range}
*/
public void lsMsg(String[] args);
/**
* Ping
*/
public void ping();
/**
* Delete (a) message(s) in a destination
* @param args
*/
public void deleteMsg(String[] args);
/**
* Send a new message in a destination
* @param args
*/
public void sendMsg(String[] args);
/**
* Receive (a) message(s) from a destination
* @param args
*/
public void receiveMsg(String[] args);
}
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