Author: rareddy
Date: 2009-02-23 14:46:08 -0500 (Mon, 23 Feb 2009)
New Revision: 482
Added:
trunk/server/src/main/java/com/metamatrix/server/FileLogListenerProvider.java
Modified:
trunk/server/src/main/java/com/metamatrix/server/Configuration.java
trunk/server/src/main/java/com/metamatrix/server/HostControllerGuiceModule.java
trunk/server/src/main/java/com/metamatrix/server/Main.java
trunk/server/src/main/java/com/metamatrix/server/ServerGuiceModule.java
trunk/server/src/main/java/com/metamatrix/server/ServerLogListernerProvider.java
Log:
TEIID-361
Modified: trunk/server/src/main/java/com/metamatrix/server/Configuration.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/Configuration.java 2009-02-23
17:43:19 UTC (rev 481)
+++ trunk/server/src/main/java/com/metamatrix/server/Configuration.java 2009-02-23
19:46:08 UTC (rev 482)
@@ -28,5 +28,7 @@
final String VMNAME = "VMName"; //$NON-NLS-1$
final String VMID = "VMId"; //$NON-NLS-1$
final String CLUSTERNAME = "ClusterName"; //$NON-NLS-1$
+ final String LOGFILE = "LogFile"; //$NON-NLS-1$
+ final String LOGDIR = "LogDir"; //$NON-NLS-1$
}
Added: trunk/server/src/main/java/com/metamatrix/server/FileLogListenerProvider.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/FileLogListenerProvider.java
(rev 0)
+++
trunk/server/src/main/java/com/metamatrix/server/FileLogListenerProvider.java 2009-02-23
19:46:08 UTC (rev 482)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * 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 (at your option) 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.server;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.PrintStream;
+import java.util.Properties;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.name.Named;
+import com.metamatrix.common.config.CurrentConfiguration;
+import com.metamatrix.core.MetaMatrixRuntimeException;
+import com.metamatrix.core.log.FileLimitSizeLogWriter;
+import com.metamatrix.core.log.LogListener;
+import com.metamatrix.internal.core.log.PlatformLog;
+
+public class FileLogListenerProvider implements Provider<LogListener> {
+
+ @Inject
+ @Named(com.metamatrix.server.Configuration.LOGFILE)
+ String logFile;
+
+ @Inject
+ @Named(com.metamatrix.server.Configuration.LOGDIR)
+ String path;
+
+ @Override
+ public LogListener get() {
+ final PlatformLog log = new PlatformLog();
+ try {
+ FileLimitSizeLogWriter flw = buildFileLogger();
+ log.addListener(flw);
+ } catch (FileNotFoundException e) {
+ throw new MetaMatrixRuntimeException(e);
+ }
+ return log;
+ }
+
+
+ FileLimitSizeLogWriter buildFileLogger() throws FileNotFoundException {
+ File tmpFile = new File(path, logFile);
+ tmpFile.getParentFile().mkdirs();
+
+ // if log file exists then create a archive
+ if (tmpFile.exists()) {
+ int index = logFile.lastIndexOf("."); //$NON-NLS-1$
+ String archiveName = FileLimitSizeLogWriter.buildArchiveFileName(logFile.substring(0,
index), logFile.substring(index));
+ tmpFile.renameTo(new File(path, archiveName));
+ }
+
+ FileOutputStream fos = new FileOutputStream(tmpFile);
+ PrintStream ps = new PrintStream(fos);
+
+ System.setOut(ps);
+ System.setErr(ps);
+
+ Properties logProps = new Properties();
+ Properties configProps = CurrentConfiguration.getInstance().getProperties();
+ if (configProps.containsKey(FileLimitSizeLogWriter.FILE_SIZE_LIMIT)) {
+ logProps.setProperty(FileLimitSizeLogWriter.FILE_SIZE_LIMIT,configProps.getProperty(FileLimitSizeLogWriter.FILE_SIZE_LIMIT));
+ }
+ if (configProps.containsKey(FileLimitSizeLogWriter.FILE_SIZE_MONITOR_TIME)) {
+ logProps.setProperty(FileLimitSizeLogWriter.FILE_SIZE_MONITOR_TIME,configProps.getProperty(FileLimitSizeLogWriter.FILE_SIZE_MONITOR_TIME));
+ }
+
+ FileLimitSizeLogWriter flw = new FileLimitSizeLogWriter(tmpFile,logProps, false);
+ return flw;
+ }
+
+}
Property changes on:
trunk/server/src/main/java/com/metamatrix/server/FileLogListenerProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/server/src/main/java/com/metamatrix/server/HostControllerGuiceModule.java
===================================================================
---
trunk/server/src/main/java/com/metamatrix/server/HostControllerGuiceModule.java 2009-02-23
17:43:19 UTC (rev 481)
+++
trunk/server/src/main/java/com/metamatrix/server/HostControllerGuiceModule.java 2009-02-23
19:46:08 UTC (rev 482)
@@ -64,6 +64,9 @@
bindConstant().annotatedWith(Names.named(Configuration.HOSTNAME)).to(host.getFullName());
bind(Host.class).annotatedWith(Names.named(Configuration.HOST)).toInstance(host);
bindConstant().annotatedWith(Names.named(Configuration.CLUSTERNAME)).to(systemName);
+ bindConstant().annotatedWith(Names.named(Configuration.LOGFILE)).to(StringUtil.replaceAll(host.getFullName(),
".", "_")+"_hc.log"); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
+ bindConstant().annotatedWith(Names.named(Configuration.LOGDIR)).to(host.getLogDirectory());
+
Names.bindProperties(binder(), CurrentConfiguration.getInstance().getProperties());
@@ -77,8 +80,7 @@
bind(LogConfiguration.class).toProvider(LogConfigurationProvider.class).in(Scopes.SINGLETON);
- String logFileName = StringUtil.replaceAll(host.getFullName(), ".",
"_")+"_hc.log"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- bind(LogListener.class).toProvider(new
ServerLogListernerProvider(host.getLogDirectory(), logFileName,
false)).in(Scopes.SINGLETON);
+ bind(LogListener.class).toProvider(FileLogListenerProvider.class).in(Scopes.SINGLETON);
// this needs to be removed.
binder().requestStaticInjection(LogManager.class);
Modified: trunk/server/src/main/java/com/metamatrix/server/Main.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/Main.java 2009-02-23 17:43:19 UTC
(rev 481)
+++ trunk/server/src/main/java/com/metamatrix/server/Main.java 2009-02-23 19:46:08 UTC
(rev 482)
@@ -55,44 +55,49 @@
@Inject
LogListener logListener;
- public static void main(String[] args) throws Exception{
+ public static void main(String[] args) {
- if (args.length < 2 || args.length > 4) {
- System.out.println("Usage: java com.metamatrix.server.Main
<vm_name> <host_name>"); //$NON-NLS-1$
- System.exit(1);
- }
+ try {
+ if (args.length < 2 || args.length > 4) {
+ System.out.println("Usage: java com.metamatrix.server.Main <vm_name>
<host_name>"); //$NON-NLS-1$
+ System.exit(1);
+ }
- String vmName = args[0];
- String hostName = args[1];
+ String vmName = args[0];
+ String hostName = args[1];
- Host host = null;
- try {
- host = CurrentConfiguration.getInstance().getHost(hostName);
- } catch (ConfigurationException e) {
- }
-
- if (host == null) {
- System.err.println(PlatformPlugin.Util.getString("SocketVMController.5",
hostName)); //$NON-NLS-1$
- System.exit(-1);
- }
-
- VMComponentDefn deployedVM =
CurrentConfiguration.getInstance().getConfiguration().getVMForHost(hostName, vmName);
- String bindAddress = deployedVM.getBindAddress();
-
- VMNaming.setVMName(vmName);
- VMNaming.setup(host.getFullName(), host.getHostAddress(), bindAddress);
-
- // write info log
- writeInfoLog(host, vmName);
-
- createTempDirectory();
-
- // wire up guice modules
- Main main = loadMain(host, vmName);
-
- // launch the server
-
- main.launchServer();
+ Host host = null;
+ try {
+ host = CurrentConfiguration.getInstance().getHost(hostName);
+ } catch (ConfigurationException e) {
+ }
+
+ if (host == null) {
+ System.err.println(PlatformPlugin.Util.getString("SocketVMController.5",
hostName)); //$NON-NLS-1$
+ System.exit(-1);
+ }
+
+ VMComponentDefn deployedVM =
CurrentConfiguration.getInstance().getConfiguration().getVMForHost(hostName, vmName);
+ String bindAddress = deployedVM.getBindAddress();
+
+ VMNaming.setVMName(vmName);
+ VMNaming.setup(host.getFullName(), host.getHostAddress(), bindAddress);
+
+ // write info log
+ writeInfoLog(host, vmName);
+
+ createTempDirectory();
+
+ // wire up guice modules
+ Main main = loadMain(host, vmName);
+
+ // launch the server
+
+ main.launchServer();
+ } catch (Throwable e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
}
Modified: trunk/server/src/main/java/com/metamatrix/server/ServerGuiceModule.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/server/ServerGuiceModule.java 2009-02-23
17:43:19 UTC (rev 481)
+++ trunk/server/src/main/java/com/metamatrix/server/ServerGuiceModule.java 2009-02-23
19:46:08 UTC (rev 482)
@@ -83,6 +83,8 @@
bindConstant().annotatedWith(Names.named(Configuration.VMID)).to(vmID);
bind(Host.class).annotatedWith(Names.named(Configuration.HOST)).toInstance(host);
bindConstant().annotatedWith(Names.named(Configuration.CLUSTERNAME)).to(systemName);
+ bindConstant().annotatedWith(Names.named(Configuration.LOGFILE)).to(StringUtil.replaceAll(host.getFullName(),
".", "_")+".log"); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
+ bindConstant().annotatedWith(Names.named(Configuration.LOGDIR)).to(host.getLogDirectory());
Names.bindProperties(binder(), CurrentConfiguration.getInstance().getProperties());
@@ -101,13 +103,9 @@
// this needs to be removed.
binder().requestStaticInjection(PlatformProxyHelper.class);
+ // Start the log file
bind(LogConfiguration.class).toProvider(LogConfigurationProvider.class).in(Scopes.SINGLETON);
bind(LogListener.class).toProvider(ServerLogListernerProvider.class).in(Scopes.SINGLETON);
-
- // Start the log file
- String logFileName = StringUtil.replaceAll(host.getFullName(), ".",
"_")+".log"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- bind(LogListener.class).toProvider(new
ServerLogListernerProvider(host.getLogDirectory(), logFileName,
true)).in(Scopes.SINGLETON);
-
// this needs to be removed.
binder().requestStaticInjection(LogManager.class);
Modified:
trunk/server/src/main/java/com/metamatrix/server/ServerLogListernerProvider.java
===================================================================
---
trunk/server/src/main/java/com/metamatrix/server/ServerLogListernerProvider.java 2009-02-23
17:43:19 UTC (rev 481)
+++
trunk/server/src/main/java/com/metamatrix/server/ServerLogListernerProvider.java 2009-02-23
19:46:08 UTC (rev 482)
@@ -22,15 +22,11 @@
package com.metamatrix.server;
-import java.io.File;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.PrintStream;
import java.util.EventObject;
import java.util.Properties;
import com.google.inject.Inject;
-import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.metamatrix.common.config.CurrentConfiguration;
import com.metamatrix.common.config.api.Configuration;
@@ -49,62 +45,52 @@
import com.metamatrix.platform.config.event.ConfigurationChangeEvent;
@Singleton
-class ServerLogListernerProvider implements Provider<LogListener> {
-
- String logFile;
- String path;
- boolean addDBLogger;
- DbLogListener dbLogger;
+class ServerLogListernerProvider extends FileLogListenerProvider {
+ public static final String LOG_DB_ENABLED =
"metamatrix.log.jdbcDatabase.enabled"; //$NON-NLS-1$
@Inject
MessageBus messsgeBus;
- public ServerLogListernerProvider(String path, String fileName, boolean addDbLogger) {
- this.path = path;
- this.logFile = fileName;
- this.addDBLogger = addDbLogger;
- }
-
@Override
public LogListener get() {
- final PlatformLog realLog = new PlatformLog();
+ final PlatformLog log = new PlatformLog();
try {
FileLimitSizeLogWriter flw = buildFileLogger();
- realLog.addListener(flw);
+ log.addListener(flw);
} catch (FileNotFoundException e) {
throw new MetaMatrixRuntimeException(e);
}
- if (this.addDBLogger) {
- this.dbLogger = buildDBLogger();
- realLog.addListener(this.dbLogger);
-
- try {
-
- this.messsgeBus.addListener(ConfigurationChangeEvent.class, new EventObjectListener()
{
-
- public void processEvent(EventObject obj) {
+ final DbLogListener dbLogger = buildDBLogger();
+ log.addListener(dbLogger);
+
+ try {
+
+ this.messsgeBus.addListener(ConfigurationChangeEvent.class, new EventObjectListener()
{
+
+ public void processEvent(EventObject obj) {
+ if(obj instanceof ConfigurationChangeEvent){
if(obj instanceof ConfigurationChangeEvent){
- if(obj instanceof ConfigurationChangeEvent){
- try {
- Configuration currentConfig =
CurrentConfiguration.getInstance().getConfiguration();
- dbLogger.determineIfEnabled(currentConfig.getProperties());
- } catch( ConfigurationException ce ) {
- LogManager.logError(LogContextsUtil.CommonConstants.CTX_MESSAGE_BUS, ce,
ce.getMessage());
- }
+ try {
+ Configuration currentConfig =
CurrentConfiguration.getInstance().getConfiguration();
+ Properties props = currentConfig.getProperties();
+ boolean enabled = PropertiesUtils.getBooleanProperty(props, LOG_DB_ENABLED,
true);
+ dbLogger.enableDBLogging(enabled);
+ } catch( ConfigurationException ce ) {
+ LogManager.logError(LogContextsUtil.CommonConstants.CTX_MESSAGE_BUS, ce,
ce.getMessage());
}
}
- }
- });
-
- } catch (MessagingException e) {
- throw new MetaMatrixRuntimeException(e);
- }
- }
- return realLog;
+ }
+ }
+ });
+
+ } catch (MessagingException e) {
+ throw new MetaMatrixRuntimeException(e);
+ }
+ return log;
}
private DbLogListener buildDBLogger() {
@@ -112,38 +98,5 @@
Properties resultsProps = PropertiesUtils.clone(currentProps, null, true, false);
return new DbLogListener(resultsProps);
}
-
- private FileLimitSizeLogWriter buildFileLogger()
- throws FileNotFoundException {
- File tmpFile = new File(path, logFile);
- tmpFile.getParentFile().mkdirs();
-
- // if log file exists then create a archive
- if (tmpFile.exists()) {
- int index = logFile.lastIndexOf("."); //$NON-NLS-1$
- String archiveName = FileLimitSizeLogWriter.buildArchiveFileName(logFile.substring(0,
index), logFile.substring(index));
- tmpFile.renameTo(new File(path, archiveName));
- }
-
- FileOutputStream fos = new FileOutputStream(tmpFile);
- PrintStream ps = new PrintStream(fos);
-
- System.setOut(ps);
- System.setErr(ps);
-
- Properties logProps = new Properties();
- Properties configProps = CurrentConfiguration.getInstance().getProperties();
- if (configProps.containsKey(FileLimitSizeLogWriter.FILE_SIZE_LIMIT)) {
- logProps.setProperty(FileLimitSizeLogWriter.FILE_SIZE_LIMIT,configProps.getProperty(FileLimitSizeLogWriter.FILE_SIZE_LIMIT));
- }
- if (configProps.containsKey(FileLimitSizeLogWriter.FILE_SIZE_MONITOR_TIME)) {
- logProps.setProperty(FileLimitSizeLogWriter.FILE_SIZE_MONITOR_TIME,configProps.getProperty(FileLimitSizeLogWriter.FILE_SIZE_MONITOR_TIME));
- }
-
- FileLimitSizeLogWriter flw = new FileLimitSizeLogWriter(tmpFile,logProps, false);
- return flw;
- }
-
-
}