Commit c3c32ad3 authored by afreyssin's avatar afreyssin

Allows asynchronous execution of static method from the administration API.

This allows to fix JORAM-288.
parent 401a475d
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2004 - 2015 ScalAgent Distributed Technologies
* Copyright (C) 2004 - 2018 ScalAgent Distributed Technologies
* Copyright (C) 2004 Bull SA
*
* This library is free software; you can redistribute it and/or
......@@ -1568,6 +1568,30 @@ public final class AdminModule {
return invokeStaticServerMethod(getLocalServerId(), className, methodName, parameterTypes, args);
}
/**
* Invokes the specified static method with the specified parameters on the
* local server. The parameters types of the invoked method must be java
* primitive types, the java objects wrapping them or String type.
* The method can be invoked either asynchronously or not by the server depending
* of the parameter async.
*
* @param className the name of the class holding the static method
* @param methodName the name of the invoked method
* @param parameterTypes the list of parameters
* @param args the arguments used for the method call
* @param async if true the method is invoked asynchronously by the server and the result is lost.
* @return the result of the invoked method after applying the toString method.
* @throws ConnectException If the connection fails.
* @throws AdminException If the invocation can't be done or fails
*/
public static String invokeStaticServerMethod(String className,
String methodName,
Class<?>[] parameterTypes,
Object[] args,
boolean async) throws ConnectException, AdminException {
return invokeStaticServerMethod(getLocalServerId(), className, methodName, parameterTypes, args, async);
}
/**
* Invokes the specified static method with the specified parameters on the
* chosen server. The parameters types of the invoked method must be java
......@@ -1590,7 +1614,36 @@ public final class AdminModule {
if (wrapper == null)
throw new ConnectException("Administration connection is closed.");
return wrapper.invokeStaticServerMethod(serverId, className, methodName, parameterTypes, args);
return wrapper.invokeStaticServerMethod(serverId, className, methodName, parameterTypes, args);
}
/**
* Invokes the specified static method with the specified parameters on the
* chosen server. The parameters types of the invoked method must be java
* primitive types, the java objects wrapping them or String type.
* The method can be invoked either asynchronously or not by the server depending
* of the parameter async.
*
* @param serverId the identifier of the server.
* @param className the name of the class holding the static method
* @param methodName the name of the invoked method
* @param parameterTypes the list of parameters
* @param args the arguments used for the method call
* @param async if true the method is invoked asynchronously by the server and the result is lost.
* @return the result of the invoked method after applying the toString method
* @throws ConnectException If the connection fails.
* @throws AdminException If the invocation can't be done or fails
*/
public static String invokeStaticServerMethod(int serverId,
String className,
String methodName,
Class<?>[] parameterTypes,
Object[] args,
boolean async) throws ConnectException, AdminException {
if (wrapper == null)
throw new ConnectException("Administration connection is closed.");
return wrapper.invokeStaticServerMethod(serverId, className, methodName, parameterTypes, args, async);
}
/**
......@@ -1660,4 +1713,20 @@ public final class AdminModule {
throw new ConnectException("Administration connection is closed.");
return wrapper.deleteJMSPBridgeConnection(serverId, names);
}
/**
* Removes the live connection to the specified AMQP server.
*
* @param serverId the serverId
* @param names the name identifying the server or list of name separate by space
* @param async invoke asynchronously
* @return the result of the method
* @throws ConnectException If the connection fails.
* @throws AdminException If the invocation can't be done or fails
*/
public static String deleteJMSPBridgeConnection(int serverId, String names, boolean async) throws ConnectException, AdminException {
if (wrapper == null)
throw new ConnectException("Administration connection is closed.");
return wrapper.deleteJMSPBridgeConnection(serverId, names, async);
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2009 - 2015 ScalAgent Distributed Technologies
* Copyright (C) 2009 - 2018 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
......@@ -1160,6 +1160,7 @@ public class AdminWrapper implements AdminItf {
* Invokes the specified static method with the specified parameters on the
* chosen server. The parameters types of the invoked method must be java
* primitive types, the java objects wrapping them or String type.
* The method is invoked synchronously by the server and the result is returned.
*
* @param serverId the identifier of the server.
* @param className the name of the class holding the static method
......@@ -1172,6 +1173,29 @@ public class AdminWrapper implements AdminItf {
*/
public String invokeStaticServerMethod(int serverId, String className, String methodName,
Class<?>[] parameterTypes, Object[] args) throws ConnectException, AdminException {
return invokeStaticServerMethod(serverId, className, methodName, parameterTypes, args, false);
}
/**
* Invokes the specified static method with the specified parameters on the
* chosen server. The parameters types of the invoked method must be java
* primitive types, the java objects wrapping them or String type.
* The method can be invoked either asynchronously or not by the server depending
* of the parameter async.
*
* @param serverId the identifier of the server.
* @param className the name of the class holding the static method
* @param methodName the name of the invoked method
* @param parameterTypes the list of parameters
* @param args the arguments used for the method call
* @param async if true the method is invoked asynchronously by the server and the result is lost.
* @return the result of the invoked method after applying the toString method
* @throws ConnectException If the connection fails.
* @throws AdminException If the invocation can't be done or fails
*/
public String invokeStaticServerMethod(int serverId, String className, String methodName,
Class<?>[] parameterTypes, Object[] args, boolean async) throws ConnectException, AdminException {
if (parameterTypes == null && (args != null && args.length > 0)) {
throw new AdminException("Parameter types array is null while args array is not null or empty.");
......@@ -1185,6 +1209,7 @@ public class AdminWrapper implements AdminItf {
Properties props = new Properties();
props.setProperty(AdminCommandConstant.INVOKE_CLASS_NAME, className);
props.setProperty(AdminCommandConstant.INVOKE_METHOD_NAME, methodName);
props.setProperty(AdminCommandConstant.INVOKE_ASYNC, "" + async);
if (parameterTypes != null) {
for (int i = 0; i < parameterTypes.length; i++) {
props.setProperty(AdminCommandConstant.INVOKE_METHOD_ARG + i, parameterTypes[i].getName());
......@@ -1281,4 +1306,23 @@ public class AdminWrapper implements AdminItf {
new Class[] { String.class },
new Object[] { names });
}
/**
* Removes the live connection to the specified JMS server.
*
* @param serverId the serverId
* @param names the name identifying the server or list of name separate by space
* @param async invoke asynchronously
* @return the result of the method
* @throws ConnectException If the connection fails.
* @throws AdminException If the invocation can't be done or fails
*/
public String deleteJMSPBridgeConnection(int serverId, String names, boolean async) throws ConnectException, AdminException {
return invokeStaticServerMethod(
serverId,
"org.objectweb.joram.mom.dest.jms.JMSConnectionService",
"deleteServer",
new Class[] { String.class },
new Object[] { names }, async);
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2005 - 2015 ScalAgent Distributed Technologies
* Copyright (C) 2005 - 2018 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
......@@ -976,6 +976,12 @@ public class JoramAdmin implements AdminItf, JoramAdminMBean {
return wrapper.invokeStaticServerMethod(serverId, className, methodName, parameterTypes, args);
}
public String invokeStaticServerMethod(int serverId, String className,
String methodName, Class<?>[] parameterTypes, Object[] args, boolean async)
throws ConnectException, AdminException {
return wrapper.invokeStaticServerMethod(serverId, className, methodName, parameterTypes, args, async);
}
public String addAMQPBridgeConnection(int serverId, String urls)
throws ConnectException, AdminException {
return wrapper.addAMQPBridgeConnection(serverId, urls);
......@@ -995,4 +1001,9 @@ public class JoramAdmin implements AdminItf, JoramAdminMBean {
throws ConnectException, AdminException {
return wrapper.deleteJMSPBridgeConnection(serverId, names);
}
public String deleteJMSPBridgeConnection(int serverId, String names, boolean async)
throws ConnectException, AdminException {
return wrapper.deleteJMSPBridgeConnection(serverId, names, async);
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2001 - 2016 ScalAgent Distributed Technologies
* Copyright (C) 2001 - 2018 ScalAgent Distributed Technologies
* Copyright (C) 1996 - 2000 Dyade
*
* This library is free software; you can redistribute it and/or
......@@ -27,6 +27,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
......@@ -1658,6 +1659,7 @@ public final class AdminTopic extends Topic implements AdminTopicMBean {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "AdminTopic.invokeStaticMethod(" + prop + ")");
boolean async = Boolean.parseBoolean(prop.getProperty(AdminCommandConstant.INVOKE_ASYNC));
String className = prop.getProperty(AdminCommandConstant.INVOKE_CLASS_NAME);
if (className == null) {
throw new IllegalArgumentException("Class name property must be specified to invoke method.");
......@@ -1670,7 +1672,7 @@ public final class AdminTopic extends Topic implements AdminTopicMBean {
int i = 0;
String paramType;
List paramClasses = new ArrayList();
List paramValues = new ArrayList();
final List paramValues = new ArrayList();
while ((paramType = prop.getProperty(AdminCommandConstant.INVOKE_METHOD_ARG + i)) != null) {
String paramValue = prop.getProperty(AdminCommandConstant.INVOKE_METHOD_ARG_VALUE + i);
if (paramType.equals(Integer.TYPE.getName())) {
......@@ -1761,12 +1763,26 @@ public final class AdminTopic extends Topic implements AdminTopicMBean {
}
Class<?> clazz = Class.forName(className);
Method method = clazz.getMethod(methodName,
final Method method = clazz.getMethod(methodName,
(Class[]) paramClasses.toArray(new Class[paramClasses.size()]));
if (! Modifier.isStatic(method.getModifiers()))
throw new IllegalArgumentException("Specified method must be static: " + method);
return method.invoke(null, paramValues.toArray());
if (async) {
Thread thread = new Thread() {
public void run() {
try {
method.invoke(null, paramValues.toArray());
} catch (Exception exc) {
logger.log(BasicLevel.WARN, "AdminTopic.invokeStaticMethod: async invocation", exc);
}
}
};
thread.start();
return null;
} else {
return method.invoke(null, paramValues.toArray());
}
}
/**
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2010 - 2016 ScalAgent Distributed Technologies
* Copyright (C) 2010 - 2018 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
......@@ -73,6 +73,9 @@ public class AdminCommandConstant {
/** Used by AdminTopic to invoke a static method */
public static final String INVOKE_METHOD_NAME = "jms_joram_invoke_method";
/** Used by AdminTopic to invoke a static method */
public static final String INVOKE_ASYNC = "jms_joram_invoke_async";
/** Used by AdminTopic to invoke a static method */
public static final String INVOKE_METHOD_ARG = "jms_joram_invoke_arg";
......
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