Commit d9bc4e09 authored by Thibaut Guinoiseau's avatar Thibaut Guinoiseau

First commit of the JORAM Shell - TG

parent b5e8542c
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>shell-a3</artifactId>
<packaging>bundle</packaging>
<!-- version : major.minor.build -->
<name>JORAM :: shell :: a3</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.ow2.joram</groupId>
<artifactId>shell</artifactId>
<version>5.8.0-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Implementation-Version>${project.version}</Implementation-Version>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Activator>org.ow2.joram.shell.a3.Activator</Bundle-Activator>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<!-- to prevent [WARNING] Using platform encoding -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<felix.version>4.0.2</felix.version>
<joram.version>5.8.0-SNAPSHOT</joram.version>
</properties>
<dependencies>
<!-- <dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
</dependency> -->
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.main</artifactId>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.shell</artifactId>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.gogo.runtime</artifactId>
<version>0.6.0</version>
</dependency>
<dependency>
<groupId>org.ow2.joram</groupId>
<artifactId>a3-rt</artifactId>
</dependency>
</dependencies>
</project>
/*
* 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;
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;
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);
}
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 A3RTCommands {
public void stopServer();
public void startServer();
public void restartServer();
public void engineLoad(String[] args);
public void garbageRatio(String[] args);
}
/*
* 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 A3RTCommandsImpl implements A3RTCommands {
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";
// 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 A3RTCommandsImpl(BundleContext context) {
this.bundleContext = context;
this.engineTracker = new ServiceTracker
(bundleContext, EngineMBean.class, null);
this.ngtTracker = new ServiceTracker
(bundleContext, NGTransactionMBean.class, null);
engineTracker.open();
ngtTracker.open();
}
public void engineLoad(String[] args) {
EngineMBean engine;
try {
engine = (EngineMBean) engineTracker.waitForService(TIMEOUT);
} catch (InterruptedException e) {
System.err.println("Error: Interrupted.");
engine = null;
}
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();
}
}
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);
if(val!=null)
return Short.parseShort(val);
else
return defaultVal;
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>shell-jndi</artifactId>
<packaging>bundle</packaging>
<!-- version : major.minor.build -->
<name>JORAM :: shell :: jndi</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.ow2.joram</groupId>
<artifactId>shell</artifactId>
<version>5.8.0-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Implementation-Version>${project.version}</Implementation-Version>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Activator>org.ow2.joram.shell.jndi.Activator</Bundle-Activator>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<!-- to prevent [WARNING] Using platform encoding -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<felix.version>4.0.2</felix.version>
<joram.version>5.8.0-SNAPSHOT</joram.version>
</properties>
<dependencies>
<!-- <dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
</dependency> -->
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.main</artifactId>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.shell</artifactId>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.gogo.runtime</artifactId>
<version>0.6.0</version>
</dependency>
<dependency>
<groupId>org.ow2.joram</groupId>
<artifactId>jndi-server</artifactId>
</dependency>
</dependencies>
</project>
/*
* 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.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;
import org.ow2.joram.shell.jndi.commands.JNDICommandsImpl;
public class Activator implements BundleActivator {
private BundleContext bundleContext;
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"});
this.bundleContext = context;
bundleContext.registerService(JNDICommands.class,
new JNDICommandsImpl(bundleContext), prop);
}
public void stop(BundleContext arg0) throws Exception {
// TODO Auto-generated method stub
}
}
/*
* 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.jndi.commands;
public interface JNDICommands {
public void getNamingContext();
public void getStrOwnerId();
public void setStrOwnerId(String strOwnerId);
public void createSubcontext(String ctxName);
public void destroySubcontext();
public void lookup(String name);
public void unbind(String name);
}
/*
* 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.jndi.commands;
import java.util.regex.Pattern;
import javax.naming.NamingException;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import fr.dyade.aaa.jndi2.impl.NamingContextMBean;
public class JNDICommandsImpl implements JNDICommands {
private static final int TIMEOUT = 1000;
private BundleContext bundleContext;
private ServiceTracker tracker;
@SuppressWarnings("unchecked")
public JNDICommandsImpl(BundleContext bundleContext) {
this.bundleContext = bundleContext;
this.tracker = new ServiceTracker(this.bundleContext,
NamingContextMBean.class,
null);
this.tracker.open();
}
public void getNamingContext() {
try {
NamingContextMBean nc = (NamingContextMBean) tracker.waitForService(TIMEOUT);
if(nc!=null) {
String[] names = nc.getNamingContext();
if(names != null && names.length > 0) {
System.out.println("Naming context:");
for(String n : names) {
// String detail;
// try {
// String s = nc.lookup(n);
// Pattern p = Pattern.compile("Reference Class Name: (\p{Alnum}{2}");
// detail = (String) o;
// } catch (Exception e) {
// detail="<error>";
// }
// System.out.println("\t"+n+" : "+detail);
System.out.println("\t"+n);
}
} else {
System.out.println("No name in the naming context.");
}
} else {
System.err.println("Error: No NamingContextMBean service found.");
}
} catch (InterruptedException e) {
System.err.println("Error: Interrupted.");
}
}
public void getStrOwnerId() {
try {
NamingContextMBean nc = (NamingContextMBean) tracker.waitForService(TIMEOUT);
if(nc!=null) {
System.out.println(nc.getStrOwnerId());
} else {
System.err.println("Error: No NamingContextMBean service found.");
}
} catch (InterruptedException e) {
System.err.println("Error: Interrupted.");
}
}
public void setStrOwnerId(String strOwnerId) {
try {
NamingContextMBean nc = (NamingContextMBean) tracker.waitForService(TIMEOUT);
if(nc!=null) {
nc.setStrOwnerId(strOwnerId);
} else {
System.err.println("Error: No NamingContextMBean service found.");
}
} catch (InterruptedException e) {
System.err.println("Error: Interrupted.");
}
}
public void createSubcontext(String ctxName) {
try {
NamingContextMBean nc = (NamingContextMBean) tracker.waitForService(TIMEOUT);
if(nc!=null) {
nc.createSubcontext(ctxName);
} else {
System.err.println("Error: No NamingContextMBean service found.");
}
} catch (InterruptedException e) {
System.err.println("Error: Interrupted.");
} catch (NamingException e) {
System.err.println("Error: Invalid subcontext name.");
}
}
public void destroySubcontext() {
try {
NamingContextMBean nc = (NamingContextMBean) tracker.waitForService(TIMEOUT);
if(nc!=null) {
nc.destroySubcontext();
} else {
System.err.println("Error: No NamingContextMBean service found.");
}
} catch (InterruptedException e) {
System.err.println("Error: Interrupted.");
} catch (NamingException e) {
System.err.println("Error: Invalid subcontext name.");
}
}
public void lookup(String name) {
try {
NamingContextMBean nc = (NamingContextMBean) tracker.waitForService(TIMEOUT);
if(nc!=null) {
System.out.println(nc.lookup(name));
} else {
System.err.println("Error: No NamingContextMBean service found.");
}
} catch (InterruptedException e) {
System.err.println("Error: Interrupted.");
} catch (NamingException e) {
System.err.println("Error: Invalid record name.");
}
}
public void unbind(String name) {
try {
NamingContextMBean nc = (NamingContextMBean) tracker.waitForService(TIMEOUT);
if(nc!=null) {
nc.unbind(name);
} else {
System.err.println("Error: No NamingContextMBean service found.");
}
} catch (InterruptedException e) {
System.err.println("Error: Interrupted.");
} catch (NamingException e) {
System.err.println("Error: Invalid record name.");
}
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>shell-mom</artifactId>
<packaging>bundle</packaging>
<!-- version : major.minor.build -->
<name>JORAM :: shell :: mom</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.ow2.joram</groupId>
<artifactId>shell</artifactId>
<version>5.8.0-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Implementation-Version>${project.version}</Implementation-Version>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Activator>org.ow2.joram.shell.mom.Activator</Bundle-Activator>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<!-- to prevent [WARNING] Using platform encoding -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<felix.version>4.0.2</felix.version>