Fix AR-431, AR-432.

Modified the Repository bootstrap mechanism so it's performed after all other initialisation and the order of bootstrap is explicit.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2414 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2006-02-16 15:11:53 +00:00
parent 6fac677245
commit 6cb16abef4
14 changed files with 388 additions and 189 deletions

View File

@@ -29,6 +29,9 @@ import org.alfresco.filesys.smb.server.SMBServer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
@@ -38,7 +41,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
*
* @author GKSpencer
*/
public class CIFSServer
public class CIFSServer implements ApplicationListener
{
private static final Log logger = LogFactory.getLog("org.alfresco.smb.server");
@@ -78,6 +81,29 @@ public class CIFSServer
return (filesysConfig != null && filesysConfig.isSMBServerEnabled());
}
/*
* (non-Javadoc)
* @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
*/
public void onApplicationEvent(ApplicationEvent event)
{
if (event instanceof ContextRefreshedEvent)
{
try
{
startServer();
}
catch (SocketException e)
{
throw new AlfrescoRuntimeException("Failed to start CIFS server", e);
}
catch (IOException e)
{
throw new AlfrescoRuntimeException("Failed to start CIFS server", e);
}
}
}
/**
* Start the CIFS server components
*
@@ -237,4 +263,6 @@ public class CIFSServer
}
System.exit(1);
}
}

View File

@@ -27,6 +27,9 @@ import org.alfresco.filesys.server.config.ServerConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
@@ -36,7 +39,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
*
* @author GKSpencer
*/
public class FTPServer
public class FTPServer implements ApplicationListener
{
private static final Log logger = LogFactory.getLog("org.alfresco.ftp.server");
@@ -76,6 +79,29 @@ public class FTPServer
return (filesysConfig != null && filesysConfig.isFTPServerEnabled());
}
/*
* (non-Javadoc)
* @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
*/
public void onApplicationEvent(ApplicationEvent event)
{
if (event instanceof ContextRefreshedEvent)
{
try
{
startServer();
}
catch (SocketException e)
{
throw new AlfrescoRuntimeException("Failed to start FTP server", e);
}
catch (IOException e)
{
throw new AlfrescoRuntimeException("Failed to start FTP server", e);
}
}
}
/**
* Start the FTP server components
*

View File

@@ -20,6 +20,7 @@ import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.security.Provider;
import java.security.Security;
@@ -78,6 +79,9 @@ import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.transaction.TransactionService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
/**
* <p>
@@ -85,7 +89,7 @@ import org.apache.commons.logging.LogFactory;
*
* @author Gary K. Spencer
*/
public class ServerConfiguration
public class ServerConfiguration implements ApplicationListener
{
// Debug logging
@@ -407,6 +411,18 @@ public class ServerConfiguration
return initialised;
}
/*
* (non-Javadoc)
* @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
*/
public void onApplicationEvent(ApplicationEvent event)
{
if (event instanceof ContextRefreshedEvent)
{
init();
}
}
/**
* Initialize the configuration using the configuration service
*/

View File

@@ -23,6 +23,9 @@ import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.i18n.I18NUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
/**
* This component is responsible for ensuring that patches are applied
@@ -30,7 +33,7 @@ import org.apache.commons.logging.LogFactory;
*
* @author Derek Hulley
*/
public class PatchExecuter
public class PatchExecuter implements ApplicationListener
{
private static final String MSG_CHECKING = "patch.executer.checking";
private static final String MSG_NO_PATCHES_REQUIRED = "patch.executer.no_patches_required";
@@ -97,4 +100,17 @@ public class PatchExecuter
}
}
}
/*
* (non-Javadoc)
* @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
*/
public void onApplicationEvent(ApplicationEvent event)
{
if (event instanceof ContextRefreshedEvent)
{
applyOutstandingPatches();
}
}
}

View File

@@ -35,8 +35,7 @@ import org.alfresco.service.descriptor.DescriptorService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
@@ -48,7 +47,7 @@ import org.springframework.core.io.Resource;
*
* @author David Caruana
*/
public class DescriptorServiceImpl implements DescriptorService, ApplicationListener
public class DescriptorServiceImpl implements DescriptorService, ApplicationListener, InitializingBean
{
private Properties serverProperties;
@@ -62,9 +61,6 @@ public class DescriptorServiceImpl implements DescriptorService, ApplicationList
private Descriptor repoDescriptor;
// Logger
private static final Log logger = LogFactory.getLog(DescriptorService.class);
/**
* Sets the server descriptor from a resource file
@@ -135,22 +131,6 @@ public class DescriptorServiceImpl implements DescriptorService, ApplicationList
return repoDescriptor;
}
/**
* Initialise Descriptors
*/
public void init()
{
// initialise descriptors
serverDescriptor = createServerDescriptor();
repoDescriptor = TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork<Descriptor>()
{
public Descriptor doWork()
{
return createRepositoryDescriptor();
}
});
}
/**
* @param event
*/
@@ -158,44 +138,27 @@ public class DescriptorServiceImpl implements DescriptorService, ApplicationList
{
if (event instanceof ContextRefreshedEvent)
{
if (serverDescriptor != null)
// initialise the repository descriptor
// note: this requires that the repository schema has already been initialised
repoDescriptor = TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork<Descriptor>()
{
// log output of VM stats
Map properties = System.getProperties();
String version = (properties.get("java.runtime.version") == null) ? "unknown" : (String)properties.get("java.runtime.version");
long maxHeap = Runtime.getRuntime().maxMemory();
float maxHeapMB = maxHeap / 1024l;
maxHeapMB = maxHeapMB / 1024l;
if (logger.isInfoEnabled())
public Descriptor doWork()
{
logger.info(String.format("Alfresco JVM - v%s; maximum heap size %.3fMB", version, maxHeapMB));
return createRepositoryDescriptor();
}
if (logger.isWarnEnabled())
{
if (version.startsWith("1.2") || version.startsWith("1.3") || version.startsWith("1.4"))
{
logger.warn(String.format("Alfresco JVM - WARNING - v1.5 is required; currently using v%s", version));
}
if (maxHeapMB < 500)
{
logger.warn(String.format("Alfresco JVM - WARNING - maximum heap size %.3fMB is less than recommended 512MB", maxHeapMB));
}
}
// log output of version initialised
if (logger.isInfoEnabled())
{
String serverEdition = serverDescriptor.getEdition();
String serverVersion = serverDescriptor.getVersion();
String repoVersion = repoDescriptor.getVersion();
int schemaVersion = repoDescriptor.getSchema();
logger.info(String.format("Alfresco started (%s) - v%s; repository v%s; schema %d",
serverEdition, serverVersion, repoVersion, schemaVersion));
}
}
});
}
}
/**
* Initialise Descriptors
*/
public void afterPropertiesSet() throws Exception
{
// initialise server descriptor
serverDescriptor = createServerDescriptor();
}
/**
* Create server descriptor
*
@@ -257,7 +220,7 @@ public class DescriptorServiceImpl implements DescriptorService, ApplicationList
*/
public String getVersionMajor()
{
return "unknown";
return "Unknown";
}
/* (non-Javadoc)
@@ -265,7 +228,7 @@ public class DescriptorServiceImpl implements DescriptorService, ApplicationList
*/
public String getVersionMinor()
{
return "unknown";
return "Unknown";
}
/* (non-Javadoc)
@@ -273,7 +236,7 @@ public class DescriptorServiceImpl implements DescriptorService, ApplicationList
*/
public String getVersionRevision()
{
return "unknown";
return "Unknown";
}
/* (non-Javadoc)
@@ -281,7 +244,7 @@ public class DescriptorServiceImpl implements DescriptorService, ApplicationList
*/
public String getVersionLabel()
{
return "unknown";
return "Unknown";
}
/* (non-Javadoc)
@@ -289,7 +252,7 @@ public class DescriptorServiceImpl implements DescriptorService, ApplicationList
*/
public String getVersion()
{
return "unknown (pre 1.0.0 RC2)";
return "Unknown (pre 1.0.0 RC2)";
}
/* (non-Javadoc)
@@ -297,7 +260,7 @@ public class DescriptorServiceImpl implements DescriptorService, ApplicationList
*/
public String getEdition()
{
return "unknown";
return "Unknown";
}
/*

View File

@@ -0,0 +1,98 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.repo.descriptor;
import java.util.Map;
import org.alfresco.service.descriptor.Descriptor;
import org.alfresco.service.descriptor.DescriptorService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
/**
* Provide a Repository Startup Log
*
* @author davidc
*/
public class DescriptorStartupLog implements ApplicationListener
{
// Logger
private static final Log logger = LogFactory.getLog(DescriptorService.class);
// Dependencies
private DescriptorService descriptorService;
/**
* @param descriptorService Descriptor Service
*/
public void setDescriptorService(DescriptorService descriptorService)
{
this.descriptorService = descriptorService;
}
/**
* @param event
*/
public void onApplicationEvent(ApplicationEvent event)
{
if (event instanceof ContextRefreshedEvent)
{
//
// log output of VM stats
//
Map properties = System.getProperties();
String version = (properties.get("java.runtime.version") == null) ? "unknown" : (String)properties.get("java.runtime.version");
long maxHeap = Runtime.getRuntime().maxMemory();
float maxHeapMB = maxHeap / 1024l;
maxHeapMB = maxHeapMB / 1024l;
if (logger.isInfoEnabled())
{
logger.info(String.format("Alfresco JVM - v%s; maximum heap size %.3fMB", version, maxHeapMB));
}
if (logger.isWarnEnabled())
{
if (version.startsWith("1.2") || version.startsWith("1.3") || version.startsWith("1.4"))
{
logger.warn(String.format("Alfresco JVM - WARNING - v1.5 is required; currently using v%s", version));
}
if (maxHeapMB < 500)
{
logger.warn(String.format("Alfresco JVM - WARNING - maximum heap size %.3fMB is less than recommended 512MB", maxHeapMB));
}
}
// Log Repository Descriptors
if (logger.isInfoEnabled())
{
Descriptor serverDescriptor = descriptorService.getServerDescriptor();
Descriptor repoDescriptor = descriptorService.getRepositoryDescriptor();
String serverEdition = serverDescriptor.getEdition();
String serverVersion = serverDescriptor.getVersion();
String repoVersion = repoDescriptor.getVersion();
int schemaVersion = repoDescriptor.getSchema();
logger.info(String.format("Alfresco started (%s) - v%s; repository v%s; schema %d",
serverEdition, serverVersion, repoVersion, schemaVersion));
}
}
}
}

View File

@@ -23,6 +23,7 @@ import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
@@ -47,6 +48,9 @@ import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.io.ClassPathResource;
/**
@@ -54,7 +58,7 @@ import org.springframework.core.io.ClassPathResource;
*
* @author David Caruana
*/
public class ImporterBootstrap
public class ImporterBootstrap implements ApplicationListener
{
// View Properties (used in setBootstrapViews)
public static final String VIEW_PATH_PROPERTY = "path";
@@ -521,5 +525,17 @@ public class ImporterBootstrap
return true;
}
/*
* (non-Javadoc)
* @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
*/
public void onApplicationEvent(ApplicationEvent event)
{
if (event instanceof ContextRefreshedEvent)
{
bootstrap();
}
}
}