Commit 7bdfadc3 authored by Andre Freyssinet's avatar Andre Freyssinet

JORAM-344: Allows to remove services from configuration updates.

parent 5cc881cb
......@@ -36,6 +36,7 @@ import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
import java.util.Random;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;
......@@ -162,6 +163,22 @@ public final class AgentServer {
EncodableFactoryRepository.putFactory(MESSAGE_CLASS_ID, new Message.Factory());
}
/**
* Name of the transaction object indicating that the configuration object has been
* updated in the transaction base. This makes it possible to initialize the server
* in a slightly different way, for example reading anew the services list.
*
* Currently we simply consider the fact that the configuration has been modified, in
* the future this object could contain indications on the changes to be made.
*/
public static final String UPDATE_CONF_TX_NAME = "updatecfg";
/**
* Object indicating that the configuration object has been updated in the transaction
* base (see UpdateConfTxName).
*/
public static ServerUpdate updatecfg = null;
/**
* Default configuration used if no other configuration is found, by default empty.
*/
......@@ -223,7 +240,6 @@ public final class AgentServer {
*/
public final static int CFG_JMS_PORT_DFLT = 16010;
/**
* Name of property allowing to configure the minimum value for listening port of the JMS
* server when using the default server configuration with random port choice (if listening
......@@ -1279,8 +1295,19 @@ public final class AgentServer {
logmon.log(BasicLevel.INFO,
getName() + ", config not found", exc);
}
// Verify if the configuration has been updated since last boot.
updatecfg = (ServerUpdate) transaction.load(UPDATE_CONF_TX_NAME);
if (updatecfg != null) {
logmon.log(BasicLevel.WARN,
getName() + ", configuration update detected: " + updatecfg.getUpdateDate());
// Removes the object before the next boot
transaction.delete(UPDATE_CONF_TX_NAME);
}
} else {
// First boot, forces the update
updatecfg = new ServerUpdate();
}
if (a3config == null) {
// Try to load an initial configuration (serialized or XML), or
// generates a default one in case of failure.
......@@ -1437,19 +1464,36 @@ public final class AgentServer {
Channel.newInstance();
try {
// Initialize services.
// Initialize services, loads the configuration from transaction.
ServiceManager.init();
logmon.log(BasicLevel.INFO,
getName() + ", ServiceManager initialized");
/* Actually get Services from A3CML configuration file. */
// Actually get Services from A3CML configuration file.
// Be careful to not erase the ServiceManager list in order to avoid
// a new initialization of existing services.
ServiceDesc services[] = AgentServer.getServices();
if (services != null) {
for (int i = 0; i < services.length; i ++) {
ServiceManager.register(services[i].getClassName(),
services[i].getArguments());
if (updatecfg != null) {
logmon.log(BasicLevel.INFO,
getName() + ", Updates ServiceManager");
Set<String> list = ServiceManager.listServices();
for (int i = 0; i < services.length; i ++) {
list.remove(services[i].getClassName());
// Adds new services or validates existing ones.
ServiceManager.register(services[i].getClassName(),
services[i].getArguments());
}
for (String scname : list) {
// Removes services no longer declared in configuration
ServiceManager.unregister(scname);
}
}
} else {
logmon.log(BasicLevel.WARN,
getName() + ", no services from configuration");
}
ServiceManager.save();
} catch (Exception exc) {
......
/*
* Copyright (C) 2019 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.
*/
package fr.dyade.aaa.agent;
import java.io.IOException;
import java.io.Serializable;
import java.util.Date;
/**
* Object indicating that the configuration object has been updated in the transaction
* base. This makes it possible to initialize the server in a slightly different way, for
* example reading anew the services list.
*
* Currently we simply consider the fact that the configuration has been modified, in
* the future this object could contain indications on the changes to be made.
*/
public class ServerUpdate implements Serializable {
/** Define serialVersionUID for interoperability. */
private static final long serialVersionUID = 1L;
/**
* Date of the update.
*/
private String update = null;
/**
* Creates a new empty ServerUpdate
*/
public ServerUpdate() {
update = new Date().toString();
}
private void writeObject(java.io.ObjectOutputStream out) throws IOException {
out.writeUTF(update);
}
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
update = in.readUTF();
}
public String getUpdateDate() {
return update;
}
}
/*
* Copyright (C) 2001 - 2007 ScalAgent Distributed Technologies
* Copyright (C) 2001 - 2019 ScalAgent Distributed Technologies
* Copyright (C) 1996 - 2000 BULL
* Copyright (C) 1996 - 2000 INRIA
*
......
......@@ -24,8 +24,10 @@ import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.NoSuchElementException;
import java.util.Set;
import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.util.monolog.api.Logger;
......@@ -78,6 +80,8 @@ public class ServiceManager implements Serializable {
save();
}
public static String txname = "serviceManager";
/**
* Builds object from persistent image.
*
......@@ -89,14 +93,14 @@ public class ServiceManager implements Serializable {
* if the corresponding image class may not be found
*/
static ServiceManager load() throws IOException, ClassNotFoundException {
return (ServiceManager) AgentServer.getTransaction().load("serviceManager");
return (ServiceManager) AgentServer.getTransaction().load(txname);
}
/**
* Saves object in persistent storage.
*/
static void save() throws IOException {
AgentServer.getTransaction().save(manager, "serviceManager");
AgentServer.getTransaction().save(manager, txname);
// with OSGi the service start asynchronously,
// and perhaps without running transaction.
AgentServer.getTransaction().begin();
......@@ -311,18 +315,13 @@ public class ServiceManager implements Serializable {
for (Enumeration<ServiceDesc> e = manager.registry.elements(); e.hasMoreElements();) {
services[i++] = e.nextElement();
}
// 1.2 Collection values = manager.registry.values();
// 1.2 ServiceDesc[] services = new ServiceDesc[values.size()];
// 1.2 try {
// 1.2 services = (ServiceDesc[]) values.toArray(services);
// 1.2 } catch (ArrayStoreException exc) {
// 1.2 xlogmon.log(BasicLevel.ERROR,
// 1.2 "AgentServer#" + AgentServer.getServerId() +
// 1.2 ".ServiceManager, can't get services.", exc);
// 1.2 }
return services;
}
static Set<String> listServices() {
return new HashSet<String>(manager.registry.keySet());
}
/**
* Provides a string image for this object.
*
......
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