Commit 5c2daf92 authored by Guillaume Surrel's avatar Guillaume Surrel
Browse files

Updating properties is now done in setProperties method with a boolean 'firstTime' set to false.

parent c44460bd
......@@ -112,25 +112,25 @@ public class AcquisitionModule implements ReliableTransmitter {
private int priority;
/** <code>true</code> if the priority property has been set. */
private boolean isPrioritySet = false;
private boolean isPrioritySet;
/** Tells if the messages produced are persistent. */
private boolean isPersistent;
/** <code>true</code> if the persistence property has been set. */
private boolean isPersistencySet = false;
private boolean isPersistencySet;
/** The duration of produced messages. */
private long expiration;
/** <code>true</code> if the expiration property has been set. */
private boolean isExpirationSet = false;
private boolean isExpirationSet;
/** The acquisition queue or topic using this module. */
private final Destination destination;
/** The period before subsequent acquisition if positive. */
private long period = 0;
private long period;
/** The task used to launch a new acquisition. */
private AcquisitionTask acquisitionTask;
......@@ -226,12 +226,23 @@ public class AcquisitionModule implements ReliableTransmitter {
/**
* Resets the acquisition properties.
*/
private void setProperties(Properties properties) {
public void setProperties(Properties properties) {
if (isDaemon && running) {
((AcquisitionDaemon) acquisitionHandler).stop();
running = false;
}
if (acquisitionTask != null) {
acquisitionTask.cancel();
}
// Reset to defaults
period = 0;
isExpirationSet = false;
isPersistencySet = false;
isPrioritySet = false;
// Clone properties as it is modified before setting handler properties
// and we want to keep all properties in destinations to persist them
Properties props = (Properties) properties.clone();
......@@ -240,10 +251,6 @@ public class AcquisitionModule implements ReliableTransmitter {
logger.log(BasicLevel.DEBUG, "AcquisitionModule.setProperties = " + props + " daemon = " + isDaemon);
}
if (acquisitionTask != null) {
acquisitionTask.cancel();
}
if (props.containsKey(PERIOD)) {
try {
period = ConversionHelper.toLong(props.get(PERIOD));
......@@ -339,24 +346,6 @@ public class AcquisitionModule implements ReliableTransmitter {
AgentServer.getTimer().schedule(new AcquisitionTask(), 0);
}
}
/**
* Update the properties.
* If daemon stop before resets the acquisition properties.
*
* @param properties new properties
* @throws Exception
*/
public void updateProperties(Properties properties) throws Exception {
if (logger.isLoggable(BasicLevel.DEBUG)) {
logger.log(BasicLevel.DEBUG, "AcquisitionModule.updateProperties(" + properties + ')');
}
// If non-empty, sets the new properties
if (properties != null) {
setProperties(properties);
}
}
/**
* Start the daemon.
......
......@@ -74,25 +74,32 @@ public class AcquisitionQueue extends Queue implements AcquisitionQueueMBean {
* @param properties
* The initial set of properties.
*/
public void setProperties(Properties properties) throws RequestException {
super.setProperties(properties);
public void setProperties(Properties properties, boolean firstTime) throws Exception {
super.setProperties(properties, firstTime);
if (logger.isLoggable(BasicLevel.DEBUG)) {
logger.log(BasicLevel.DEBUG, "AcquisitionQueue.<init> prop = " + properties);
}
if (properties == null) {
throw new RequestException("No property found: At least " + AcquisitionModule.CLASS_NAME
+ " property must be defined on queue creation.");
logger.log(BasicLevel.DEBUG, "AcquisitionQueue.setProperties prop = " + properties);
}
this.properties = properties;
acquisitionClassName = properties.getProperty(AcquisitionModule.CLASS_NAME);
properties.remove(AcquisitionModule.CLASS_NAME);
try {
AcquisitionModule.checkAcquisitionClass(acquisitionClassName);
} catch (Exception exc) {
logger.log(BasicLevel.ERROR, "AcquisitionQueue: error with acquisition class.", exc);
throw new RequestException(exc.getMessage());
// Acquisition class name can only be set the first time.
if (firstTime) {
if (properties != null) {
acquisitionClassName = properties.getProperty(AcquisitionModule.CLASS_NAME);
properties.remove(AcquisitionModule.CLASS_NAME);
}
if (acquisitionClassName == null) {
throw new RequestException("Acquisition class name not found: " + AcquisitionModule.CLASS_NAME
+ " property must be set on queue creation.");
}
try {
AcquisitionModule.checkAcquisitionClass(acquisitionClassName);
} catch (Exception exc) {
logger.log(BasicLevel.ERROR, "AcquisitionQueue: error with acquisition class.", exc);
throw new RequestException(exc.getMessage());
}
} else {
acquisitionModule.setProperties(properties);
}
}
......@@ -132,22 +139,6 @@ public class AcquisitionQueue extends Queue implements AcquisitionQueueMBean {
return null;
}
/**
* Update properties configuration, they are processed by the distribution module
*
* @param prop the new properties.
* @throws Exception
*/
public void updateProperties(Properties prop) throws Exception {
if (logger.isLoggable(BasicLevel.DEBUG)) {
logger.log(BasicLevel.DEBUG, "AcquisitionQueue.updateProperties(" + prop + ')');
}
super.setProperties(prop);
this.properties = prop;
// update the module
acquisitionModule.updateProperties(properties);
}
/**
* Start the handler.
*
......
......@@ -74,25 +74,34 @@ public class AcquisitionTopic extends Topic implements AcquisitionTopicMBean {
* @param properties
* The initial set of properties.
*/
public void setProperties(Properties properties) throws RequestException {
super.setProperties(properties);
public void setProperties(Properties properties, boolean firstTime) throws Exception {
super.setProperties(properties, firstTime);
if (logger.isLoggable(BasicLevel.DEBUG)) {
logger.log(BasicLevel.DEBUG, "AcquisitionTopic.<init> prop = " + properties);
}
if (properties == null) {
throw new RequestException("No property found: At least " + AcquisitionModule.CLASS_NAME
+ " property must be defined on topic creation.");
logger.log(BasicLevel.DEBUG, "AcquisitionTopic.setProperties prop = " + properties);
}
this.properties = properties;
acquisitionClassName = properties.getProperty(AcquisitionModule.CLASS_NAME);
properties.remove(AcquisitionModule.CLASS_NAME);
try {
AcquisitionModule.checkAcquisitionClass(acquisitionClassName);
} catch (Exception exc) {
logger.log(BasicLevel.ERROR, "AcquisitionTopic: error with acquisition class.", exc);
throw new RequestException(exc.getMessage());
// Acquisition class name can only be set the first time.
if (firstTime) {
if (properties != null) {
acquisitionClassName = properties.getProperty(AcquisitionModule.CLASS_NAME);
properties.remove(AcquisitionModule.CLASS_NAME);
}
if (acquisitionClassName == null) {
throw new RequestException("Acquisition class name not found: " + AcquisitionModule.CLASS_NAME
+ " property must be set on topic creation.");
}
try {
AcquisitionModule.checkAcquisitionClass(acquisitionClassName);
} catch (Exception exc) {
logger.log(BasicLevel.ERROR, "AcquisitionTopic: error with acquisition class.", exc);
throw new RequestException(exc.getMessage());
}
}
if (!firstTime) {
acquisitionModule.setProperties(properties);
}
}
......@@ -132,22 +141,6 @@ public class AcquisitionTopic extends Topic implements AcquisitionTopicMBean {
return null;
}
/**
* Update properties configuration, they are processed by the distribution module
* @param prop the new properties.
* @throws Exception
*/
public void updateProperties(Properties prop) throws Exception {
if (logger.isLoggable(BasicLevel.DEBUG)) {
logger.log(BasicLevel.DEBUG, "AcquisitionTopic.updateProperties(" + prop + ')');
}
super.setProperties(prop);
this.properties = prop;
// update the module
acquisitionModule.updateProperties(properties);
}
/**
* Start the handler.
*
......
......@@ -30,6 +30,7 @@ import java.io.Serializable;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
......@@ -736,7 +737,7 @@ public final class AdminTopic extends Topic implements AdminTopicMBean {
dest = (Destination) Class.forName(className).newInstance();
dest.setName(destName);
dest.setAdminId(adminId);
dest.setProperties(properties);
dest.setProperties(properties, true);
} catch (Exception exc) {
logger.log(BasicLevel.ERROR,
"Could not instantiate Destination class [" + className + "]: ", exc);
......@@ -1574,7 +1575,12 @@ public final class AdminTopic extends Topic implements AdminTopicMBean {
Object result = invokeStaticMethod(request.getProp());
if (result != null) {
replyProp = new Properties();
replyProp.setProperty(AdminCommandConstant.INVOKE_METHOD_RESULT, result.toString());
if (result instanceof Object[]) {
replyProp.setProperty(AdminCommandConstant.INVOKE_METHOD_RESULT,
Arrays.toString((Object[]) result));
} else {
replyProp.setProperty(AdminCommandConstant.INVOKE_METHOD_RESULT, result.toString());
}
}
break;
......
......@@ -52,7 +52,6 @@ import org.objectweb.joram.shared.admin.ClusterLeave;
import org.objectweb.joram.shared.admin.ClusterList;
import org.objectweb.joram.shared.admin.ClusterListReply;
import org.objectweb.joram.shared.excepts.AccessException;
import org.objectweb.joram.shared.excepts.RequestException;
import org.objectweb.util.monolog.api.BasicLevel;
import fr.dyade.aaa.agent.AgentId;
......@@ -104,38 +103,41 @@ public class ClusterQueue extends Queue implements ClusterQueueMBean {
*
* @param prop The initial set of properties.
*/
public void setProperties(Properties prop) throws RequestException {
super.setProperties(prop);
public void setProperties(Properties prop, boolean firstTime) throws Exception {
super.setProperties(prop, firstTime);
/** producer threshold */
int producThreshold = -1;
int producThreshold = 10000;
/** consumer threshold */
int consumThreshold = -1;
int consumThreshold = 10000;
/** automatic eval threshold */
boolean autoEvalThreshold = false;
long waitAfterClusterReq = -1;
long waitAfterClusterReq = 60000;
timeThreshold = getPeriod();
if (prop != null) {
try {
waitAfterClusterReq = Long.valueOf(prop.getProperty("waitAfterClusterReq")).longValue();
} catch (NumberFormatException exc) {
waitAfterClusterReq = 60000;
logger.log(BasicLevel.ERROR, "Incorrect waitAfterClusterReq value" + exc);
}
try {
producThreshold = Integer.valueOf(prop.getProperty("producThreshold")).intValue();
} catch (NumberFormatException exc) {
producThreshold = 10000;
logger.log(BasicLevel.ERROR, "Incorrect producThreshold value" + exc);
}
try {
consumThreshold = Integer.valueOf(prop.getProperty("consumThreshold")).intValue();
} catch (NumberFormatException exc) {
consumThreshold = 10000;
logger.log(BasicLevel.ERROR, "Incorrect consumThreshold value" + exc);
}
autoEvalThreshold = Boolean.valueOf(prop.getProperty("autoEvalThreshold")).booleanValue();
try {
timeThreshold = Long.valueOf(prop.getProperty("timeThreshold")).longValue();
} catch (NumberFormatException exc) {
timeThreshold = getPeriod();
logger.log(BasicLevel.ERROR, "Incorrect timeThreshold value" + exc);
}
}
......
......@@ -62,7 +62,6 @@ import org.objectweb.joram.shared.admin.SetWriter;
import org.objectweb.joram.shared.admin.UnsetReader;
import org.objectweb.joram.shared.admin.UnsetWriter;
import org.objectweb.joram.shared.excepts.AccessException;
import org.objectweb.joram.shared.excepts.MessageValueException;
import org.objectweb.joram.shared.excepts.MomException;
import org.objectweb.joram.shared.excepts.RequestException;
import org.objectweb.joram.shared.messages.ConversionHelper;
......@@ -157,8 +156,8 @@ public abstract class Destination extends Agent implements DestinationMBean {
// interceptors
if (interceptorsStr != null) {
interceptors = new ArrayList();
InterceptorsHelper.addInterceptors(interceptorsStr, interceptors);
interceptors = new ArrayList();
InterceptorsHelper.addInterceptors(interceptorsStr, interceptors);
}
initialize(firstTime);
......@@ -309,29 +308,48 @@ public abstract class Destination extends Agent implements DestinationMBean {
}
/**
* Configures a <code>Destination</code>.
* Sets the configuration of a <code>Destination</code>. Be careful, this is
* done a first time before {@link #deploy()}, so the agent is serialized and
* initialized afterwards.<br>
* After deployment, firstTime argument is set to false.
*
* @param prop The initial set of properties.
*/
public void setProperties(Properties prop) throws RequestException {
try {
if (prop != null)
period = ConversionHelper.toLong(prop.get(WAKEUP_PERIOD));
} catch (MessageValueException e) {
period = -1L;
} catch (NumberFormatException e) {
period = -1L;
public void setProperties(Properties prop, boolean firstTime) throws Exception {
if (logger.isLoggable(BasicLevel.DEBUG)) {
logger.log(BasicLevel.DEBUG, this + ", setProperties.");
}
long newPeriod = -1;
if (prop != null && prop.containsKey(WAKEUP_PERIOD)) {
try {
newPeriod = ConversionHelper.toLong(prop.get(WAKEUP_PERIOD));
} catch (Exception e) {
logger.log(BasicLevel.ERROR, this + ": error setting destination period", e);
}
}
if (firstTime) {
period = newPeriod;
} else {
setPeriod(newPeriod);
}
// interceptors set in destination creation
if (prop != null && interceptorsStr == null && prop.containsKey(AdminCommandConstant.INTERCEPTORS)) {
if (logger.isLoggable(BasicLevel.DEBUG))
interceptorsStr = null;
interceptors = null;
if (prop != null && prop.containsKey(AdminCommandConstant.INTERCEPTORS)) {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + ": setProperties interceptors = " + prop.get(AdminCommandConstant.INTERCEPTORS));
interceptorsStr = (String) prop.get(AdminCommandConstant.INTERCEPTORS);
interceptorsStr = (String) prop.get(AdminCommandConstant.INTERCEPTORS);
}
// Interceptors are set the first time in agent initialization
if (!firstTime) {
if (interceptorsStr != null) {
interceptors = new ArrayList();
InterceptorsHelper.addInterceptors(interceptorsStr, interceptors);
} else {
interceptors = null;
}
}
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + ", init.");
}
/**
......@@ -1043,7 +1061,8 @@ public abstract class Destination extends Agent implements DestinationMBean {
setSave();
break;
case AdminCommandConstant.CMD_SET_PROPERTIES:
updateProperties(request.getProp());
setProperties(request.getProp(), false);
setSave();
break;
case AdminCommandConstant.CMD_START_HANDLER:
replyProp = processStartHandler(request.getProp());
......@@ -1064,15 +1083,6 @@ public abstract class Destination extends Agent implements DestinationMBean {
}
}
/**
* Update properties configuration.
* (overload in specific destination)
*
* @param prop properties to update.
* @throws Exception
*/
protected void updateProperties(Properties prop) throws Exception { }
/**
* Start the acquisition queue/topic handler.
*
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2001 - 2010 ScalAgent Distributed Technologies
* Copyright (C) 2001 - 2011 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
......@@ -31,7 +31,6 @@ import org.objectweb.joram.mom.dest.Queue;
import org.objectweb.joram.mom.notifications.ClientMessages;
import org.objectweb.joram.mom.util.DMQManager;
import org.objectweb.joram.shared.MessageErrorConstants;
import org.objectweb.joram.shared.excepts.RequestException;
import org.objectweb.joram.shared.messages.Message;
import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.util.monolog.api.Logger;
......@@ -50,31 +49,20 @@ public class FtpQueue extends Queue {
public static Logger logger = Debug.getLogger(FtpQueue.class.getName());
private String user = "anonymous";
private String pass = "no@no.no";
private String path = null;
private transient TransferItf transfer = null;
private AgentId dmq = null;
private String user;
private String pass;
private String path;
private transient TransferItf transfer;
private AgentId dmq;
private int clientContext;
private int requestId;
public String ftpImplName = "com.scalagent.joram.mom.dest.ftp.TransferImplRef";
public String ftpImplName;
private Hashtable transferTable;
public FtpQueue() {
fixed = true;
transferTable = new Hashtable();
try {
if ((ftpImplName != null) && (ftpImplName.length() > 0))
transfer = (TransferItf) Class.forName(ftpImplName).newInstance();
} catch (Exception exc) {
transfer = null;
logger.log(BasicLevel.ERROR, "FtpQueue: transfer = null", exc);
}
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "--- " + this + " transfer = " + transfer);
}
/**
......@@ -82,16 +70,20 @@ public class FtpQueue extends Queue {
*
* @param prop The initial set of properties.
*/
public void setProperties(Properties prop) throws RequestException {
if (prop == null)
return;
super.setProperties(prop);
user = prop.getProperty("user", user);
pass = prop.getProperty("pass", pass);
path = prop.getProperty("path", path);
ftpImplName = prop.getProperty("ftpImpl", ftpImplName);
public void setProperties(Properties prop, boolean firstTime) throws Exception {
super.setProperties(prop, firstTime);
user = "anonymous";
pass = "no@no.no";
path = null;
ftpImplName = "com.scalagent.joram.mom.dest.ftp.TransferImplRef";
if (prop != null) {
user = prop.getProperty("user", user);
pass = prop.getProperty("pass", pass);
path = prop.getProperty("path", path);
ftpImplName = prop.getProperty("ftpImpl", ftpImplName);
}
}
/**
* Initializes the destination.
*
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2004 - 2010 ScalAgent Distributed Technologies
* Copyright (C) 2004 - 2011 ScalAgent Distributed Technologies
* Copyright (C) 2003 - 2004 Bull SA
*
* This library is free software; you can redistribute it and/or
......@@ -37,7 +37,6 @@ import org.objectweb.joram.mom.notifications.ReceiveRequest;
import org.objectweb.joram.mom.util.DMQManager;
import org.objectweb.joram.shared.MessageErrorConstants;
import org.objectweb.joram.shared.excepts.AccessException;
import org.objectweb.joram.shared.excepts.RequestException;
import org.objectweb.joram.shared.selectors.Selector;
import org.objectweb.util.monolog.api.BasicLevel;
......@@ -81,8 +80,8 @@ public class JMSBridgeQueue extends Queue {
*
* @param prop The initial set of properties.
*/
public void setProperties(Properties prop) throws RequestException {
super.setProperties(prop);
public void setProperties(Properties prop, boolean firstTime) throws Exception {
super.setProperties(prop, firstTime);
// creates the JMS module for communication with external provider
jmsModule = new JMSBridgeModule(prop);
}
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2004 - 2010 ScalAgent Distributed Technologies
* Copyright (C) 2004 - 2011 ScalAgent Distributed Technologies
* Copyright (C) 2003 - 2004 Bull SA
*
* This library is free software; you can redistribute it and/or
......@@ -36,7 +36,6 @@ import org.objectweb.joram.mom.notifications.TopicForwardNot;
import org.objectweb.joram.mom.util.DMQManager;
import org.objectweb.joram.shared.MessageErrorConstants;
import org.objectweb.joram.shared.excepts.AccessException;
import org.objectweb.joram.shared.excepts.RequestException;
import org.objectweb.util.monolog.api.BasicLevel;
import fr.dyade.aaa.agent.AgentId;
......@@ -83,8 +82,8 @@ public class JMSBridgeTopic extends Topic {
*
* @param prop The initial set of properties.
*/
public void setProperties(Properties prop) throws RequestException {
super.setProperties(prop);
public void setProperties(Properties prop, boolean firstTime) throws Exception {
super.setProperties(prop, firstTime);
// creates the table for outgoing messages.
jmsModule = new JMSBridgeModule(prop);
}
......
Markdown is supported
0% or .