Commit 4a00801b authored by Matt Tucker's avatar Matt Tucker Committed by matt

Removed ModuleContext concept. Modules now load properties directly from JiveGlobals.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@111 b35dd754-fafc-0310-a699-88a17e54d16e
parent 0afc481e
...@@ -605,13 +605,13 @@ public class JiveGlobals { ...@@ -605,13 +605,13 @@ public class JiveGlobals {
* @param parent the name of the parent property to return the children for. * @param parent the name of the parent property to return the children for.
* @return all child property values for the given parent. * @return all child property values for the given parent.
*/ */
public static List getProperties(String parent) { public static List<String> getProperties(String parent) {
if (properties == null) { if (properties == null) {
properties = JiveProperties.getInstance(); properties = JiveProperties.getInstance();
} }
Collection propertyNames = properties.getChildrenNames(parent); Collection<String> propertyNames = properties.getChildrenNames(parent);
List values = new ArrayList(); List<String> values = new ArrayList<String>();
for (Iterator i=propertyNames.iterator(); i.hasNext(); ) { for (Iterator i=propertyNames.iterator(); i.hasNext(); ) {
String propName = (String)i.next(); String propName = (String)i.next();
String value = getProperty(propName); String value = getProperty(propName);
......
...@@ -13,12 +13,11 @@ package org.jivesoftware.messenger.audit.spi; ...@@ -13,12 +13,11 @@ package org.jivesoftware.messenger.audit.spi;
import org.jivesoftware.messenger.container.BasicModule; import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.messenger.container.Container; import org.jivesoftware.messenger.container.Container;
import org.jivesoftware.messenger.container.ModuleContext;
import org.jivesoftware.messenger.audit.AuditManager; import org.jivesoftware.messenger.audit.AuditManager;
import org.jivesoftware.messenger.audit.Auditor; import org.jivesoftware.messenger.audit.Auditor;
import java.util.Iterator; import org.jivesoftware.messenger.JiveGlobals;
import java.util.LinkedList;
import java.util.List; import java.util.*;
public class AuditManagerImpl extends BasicModule implements AuditManager { public class AuditManagerImpl extends BasicModule implements AuditManager {
...@@ -28,7 +27,6 @@ public class AuditManagerImpl extends BasicModule implements AuditManager { ...@@ -28,7 +27,6 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
private boolean auditIQ; private boolean auditIQ;
private boolean auditXPath; private boolean auditXPath;
private List xpath = new LinkedList(); private List xpath = new LinkedList();
private ModuleContext context;
private AuditorImpl auditor = null; private AuditorImpl auditor = null;
private int maxSize; private int maxSize;
private int maxCount; private int maxCount;
...@@ -45,7 +43,7 @@ public class AuditManagerImpl extends BasicModule implements AuditManager { ...@@ -45,7 +43,7 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
public void setEnabled(boolean enabled) { public void setEnabled(boolean enabled) {
this.enabled = enabled; this.enabled = enabled;
context.setProperty("xmpp.audit.active", enabled ? "true" : "false"); JiveGlobals.setProperty("xmpp.audit.active", enabled ? "true" : "false");
} }
public Auditor getAuditor() { public Auditor getAuditor() {
...@@ -62,7 +60,7 @@ public class AuditManagerImpl extends BasicModule implements AuditManager { ...@@ -62,7 +60,7 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
public void setMaxFileSize(int size) { public void setMaxFileSize(int size) {
maxSize = size; maxSize = size;
auditor.setMaxValues(maxSize, maxCount); auditor.setMaxValues(maxSize, maxCount);
context.setProperty("xmpp.audit.maxsize", Integer.toString(size)); JiveGlobals.setProperty("xmpp.audit.maxsize", Integer.toString(size));
} }
public int getMaxFileCount() { public int getMaxFileCount() {
...@@ -72,7 +70,7 @@ public class AuditManagerImpl extends BasicModule implements AuditManager { ...@@ -72,7 +70,7 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
public void setMaxFileCount(int count) { public void setMaxFileCount(int count) {
maxCount = count; maxCount = count;
auditor.setMaxValues(maxSize, maxCount); auditor.setMaxValues(maxSize, maxCount);
context.setProperty("xmpp.audit.maxcount", Integer.toString(count)); JiveGlobals.setProperty("xmpp.audit.maxcount", Integer.toString(count));
} }
public boolean isAuditMessage() { public boolean isAuditMessage() {
...@@ -81,7 +79,7 @@ public class AuditManagerImpl extends BasicModule implements AuditManager { ...@@ -81,7 +79,7 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
public void setAuditMessage(boolean auditMessage) { public void setAuditMessage(boolean auditMessage) {
this.auditMessage = auditMessage; this.auditMessage = auditMessage;
context.setProperty("xmpp.audit.message", auditMessage ? "true" : "false"); JiveGlobals.setProperty("xmpp.audit.message", auditMessage ? "true" : "false");
} }
public boolean isAuditPresence() { public boolean isAuditPresence() {
...@@ -90,7 +88,7 @@ public class AuditManagerImpl extends BasicModule implements AuditManager { ...@@ -90,7 +88,7 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
public void setAuditPresence(boolean auditPresence) { public void setAuditPresence(boolean auditPresence) {
this.auditPresence = auditPresence; this.auditPresence = auditPresence;
context.setProperty("xmpp.audit.presence", auditPresence ? "true" : "false"); JiveGlobals.setProperty("xmpp.audit.presence", auditPresence ? "true" : "false");
} }
public boolean isAuditIQ() { public boolean isAuditIQ() {
...@@ -99,12 +97,7 @@ public class AuditManagerImpl extends BasicModule implements AuditManager { ...@@ -99,12 +97,7 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
public void setAuditIQ(boolean auditIQ) { public void setAuditIQ(boolean auditIQ) {
this.auditIQ = auditIQ; this.auditIQ = auditIQ;
if (auditIQ) { JiveGlobals.setProperty("xmpp.audit.iq", Boolean.toString(auditIQ));
context.setProperty("xmpp.audit.iq", auditIQ ? "true" : "false");
}
else {
context.setProperty("xmpp.audit.iq", "false");
}
} }
public boolean isAuditXPath() { public boolean isAuditXPath() {
...@@ -113,7 +106,7 @@ public class AuditManagerImpl extends BasicModule implements AuditManager { ...@@ -113,7 +106,7 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
public void setAuditXPath(boolean auditXPath) { public void setAuditXPath(boolean auditXPath) {
this.auditXPath = auditXPath; this.auditXPath = auditXPath;
context.setProperty("xmpp.audit.xpath", auditXPath ? "true" : "false"); JiveGlobals.setProperty("xmpp.audit.xpath", Boolean.toString(auditXPath));
} }
public void addXPath(String xpathExpression) { public void addXPath(String xpathExpression) {
...@@ -129,7 +122,7 @@ public class AuditManagerImpl extends BasicModule implements AuditManager { ...@@ -129,7 +122,7 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
private void saveXPath() { private void saveXPath() {
String[] filters = new String[xpath.size()]; String[] filters = new String[xpath.size()];
filters = (String[])xpath.toArray(filters); filters = (String[])xpath.toArray(filters);
context.setProperties("xmpp.audit.filter.xpath", filters); // TODO: save XPath values!
} }
public Iterator getXPathFilters() { public Iterator getXPathFilters() {
...@@ -140,30 +133,21 @@ public class AuditManagerImpl extends BasicModule implements AuditManager { ...@@ -140,30 +133,21 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
// Basic module methods // Basic module methods
// ######################################################################### // #########################################################################
public void initialize(ModuleContext context, Container container) { public void initialize(Container container) {
super.initialize(context, container); super.initialize(container);
this.context = context; setEnabled(JiveGlobals.getBooleanProperty("xmpp.audit.active"));
setEnabled("true".equals(context.getProperty("xmpp.audit.active"))); setEnabled(JiveGlobals.getBooleanProperty("xmpp.audit.message"));
setAuditMessage("true".equals(context.getProperty("xmpp.audit.message"))); setEnabled(JiveGlobals.getBooleanProperty("xmpp.audit.presence"));
setAuditPresence("true".equals(context.getProperty("xmpp.audit.presence"))); setEnabled(JiveGlobals.getBooleanProperty("xmpp.audit.iq"));
setAuditIQ("true".equals(context.getProperty("xmpp.audit.iq"))); setEnabled(JiveGlobals.getBooleanProperty("xmpp.audit.xpath"));
setAuditXPath("true".equals(context.getProperty("xmpp.audit.xpath"))); // TODO: load xpath values!
String[] filters = context.getProperties("xmpp.audit.filter.xpath"); // String[] filters = context.getProperties("xmpp.audit.filter.xpath");
for (int i = 0; i < filters.length; i++) { // for (int i = 0; i < filters.length; i++) {
xpath.add(filters[i]); // xpath.add(filters[i]);
} // }
saveXPath(); maxSize = JiveGlobals.getIntProperty("xmpp.audit.maxsize", MAX_FILE_SIZE);
String prop = context.getProperty("xmpp.audit.maxsize"); maxCount = JiveGlobals.getIntProperty("xmpp.audit.maxcount", MAX_FILE_COUNT);
maxSize = MAX_FILE_SIZE; auditor = new AuditorImpl(this);
if (prop != null && prop.trim().length() > 0) {
maxSize = Integer.parseInt(prop);
}
prop = context.getProperty("xmpp.audit.maxcount");
maxCount = MAX_FILE_COUNT;
if (prop != null && prop.trim().length() > 0) {
maxCount = Integer.parseInt(prop);
}
auditor = new AuditorImpl(this, context);
auditor.setMaxValues(maxSize, maxCount); auditor.setMaxValues(maxSize, maxCount);
} }
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
package org.jivesoftware.messenger.audit.spi; package org.jivesoftware.messenger.audit.spi;
import org.jivesoftware.messenger.container.ModuleContext;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.messenger.*; import org.jivesoftware.messenger.*;
...@@ -30,7 +29,6 @@ import javax.xml.stream.XMLStreamWriter; ...@@ -30,7 +29,6 @@ import javax.xml.stream.XMLStreamWriter;
public class AuditorImpl implements Auditor { public class AuditorImpl implements Auditor {
private AuditManager auditManager; private AuditManager auditManager;
private ModuleContext moduleContext;
private File currentAuditFile; private File currentAuditFile;
private Writer writer; private Writer writer;
private XMLStreamWriter xmlSerializer; private XMLStreamWriter xmlSerializer;
...@@ -39,9 +37,8 @@ public class AuditorImpl implements Auditor { ...@@ -39,9 +37,8 @@ public class AuditorImpl implements Auditor {
private long maxCount; private long maxCount;
private boolean closed = false; private boolean closed = false;
public AuditorImpl(AuditManager manager, ModuleContext context) { public AuditorImpl(AuditManager manager) {
auditManager = manager; auditManager = manager;
moduleContext = context;
} }
public void audit(XMPPPacket packet) { public void audit(XMPPPacket packet) {
...@@ -172,7 +169,8 @@ public class AuditorImpl implements Auditor { ...@@ -172,7 +169,8 @@ public class AuditorImpl implements Auditor {
int i; int i;
// Find the next available log file name // Find the next available log file name
for (i = 0; maxCount < 1 || i < maxCount; i++) { for (i = 0; maxCount < 1 || i < maxCount; i++) {
currentAuditFile = new File(moduleContext.getLogDirectory(), "jive.audit-" + i + ".log"); currentAuditFile = new File(JiveGlobals.getMessengerHome() + File.separator + "logs",
"jive.audit-" + i + ".log");
if (!currentAuditFile.exists()) { if (!currentAuditFile.exists()) {
break; break;
} }
...@@ -191,9 +189,11 @@ public class AuditorImpl implements Auditor { ...@@ -191,9 +189,11 @@ public class AuditorImpl implements Auditor {
// Rotate the files // Rotate the files
for (i--; i >= 0; i--) { for (i--; i >= 0; i--) {
String previousName = "jive.audit-" + i + ".log"; String previousName = "jive.audit-" + i + ".log";
File previousFile = new File(moduleContext.getLogDirectory(), previousName); File previousFile = new File(JiveGlobals.getMessengerHome() + File.separator + "logs",
previousName);
previousFile.renameTo(currentAuditFile); previousFile.renameTo(currentAuditFile);
currentAuditFile = new File(moduleContext.getLogDirectory(), previousName); currentAuditFile = new File(JiveGlobals.getMessengerHome() + File.separator + "logs",
previousName);
} }
} }
......
...@@ -13,7 +13,6 @@ package org.jivesoftware.messenger.auth.spi; ...@@ -13,7 +13,6 @@ package org.jivesoftware.messenger.auth.spi;
import org.jivesoftware.util.CacheManager; import org.jivesoftware.util.CacheManager;
import org.jivesoftware.messenger.container.BasicModule; import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.messenger.container.Container; import org.jivesoftware.messenger.container.Container;
import org.jivesoftware.messenger.container.ModuleContext;
import org.jivesoftware.util.Cache; import org.jivesoftware.util.Cache;
import org.jivesoftware.util.*; import org.jivesoftware.util.*;
import org.jivesoftware.messenger.Entity; import org.jivesoftware.messenger.Entity;
...@@ -138,11 +137,11 @@ public class GroupManagerImpl extends BasicModule implements GroupManager { ...@@ -138,11 +137,11 @@ public class GroupManagerImpl extends BasicModule implements GroupManager {
// Module management // Module management
// ##################################################################### // #####################################################################
public void initialize(ModuleContext context, Container container) { public void initialize(Container container) {
super.initialize(context, container); super.initialize(container);
CacheManager.initializeCache(GROUP_CACHE_NAME, 128 * 1024, context); CacheManager.initializeCache(GROUP_CACHE_NAME, 128 * 1024);
CacheManager.initializeCache(GROUP_ID_CACHE_NAME, 128 * 1024, context); CacheManager.initializeCache(GROUP_ID_CACHE_NAME, 128 * 1024);
CacheManager.initializeCache(GROUP_MEMBER_CACHE_NAME, 16 * 1024, context); CacheManager.initializeCache(GROUP_MEMBER_CACHE_NAME, 16 * 1024);
groupCache = CacheManager.getCache(GROUP_CACHE_NAME); groupCache = CacheManager.getCache(GROUP_CACHE_NAME);
groupIDCache = CacheManager.getCache(GROUP_ID_CACHE_NAME); groupIDCache = CacheManager.getCache(GROUP_ID_CACHE_NAME);
......
...@@ -10,12 +10,11 @@ ...@@ -10,12 +10,11 @@
*/ */
package org.jivesoftware.messenger.chat; package org.jivesoftware.messenger.chat;
import org.jivesoftware.messenger.container.ModuleContext;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.messenger.Message; import org.jivesoftware.messenger.Message;
import java.util.Iterator; import org.jivesoftware.messenger.JiveGlobals;
import java.util.LinkedList;
import java.util.ListIterator; import java.util.*;
/** /**
* <p>Chat rooms may cache history of the conversations in the room in order to * <p>Chat rooms may cache history of the conversations in the room in order to
...@@ -28,33 +27,16 @@ import java.util.ListIterator; ...@@ -28,33 +27,16 @@ import java.util.ListIterator;
*/ */
public class HistoryStrategy { public class HistoryStrategy {
private Type type = Type.number;
/**
* <p>List containing the history of messages.</p>
*/
private LinkedList history = new LinkedList();
/** /**
* Default max number. * Default max number.
*/ */
private static final int DEFAULT_MAX_NUMBER = 25; private static final int DEFAULT_MAX_NUMBER = 25;
/**
* <p>The maximum number of chat history messages stored for the room.</p> private Type type = Type.number;
*/ private LinkedList history = new LinkedList();
private int maxNumber; private int maxNumber;
/**
* <p>The parent history used for default settings, or null if no parent
* (chat server defaults).
*/
private HistoryStrategy parent; private HistoryStrategy parent;
/**
* <p>Track the latest room subject change or null if none exists yet.</p>
*/
private Message roomSubject = null; private Message roomSubject = null;
/**
* <p>If set, indicates settings should be saved to the given context.</p>
*/
private ModuleContext context = null;
/** /**
* <p>The string prefix to be used on the context property names * <p>The string prefix to be used on the context property names
* (do not include trailing dot).</p> * (do not include trailing dot).</p>
...@@ -96,14 +78,14 @@ public class HistoryStrategy { ...@@ -96,14 +78,14 @@ public class HistoryStrategy {
*/ */
public void setMaxNumber(int max) { public void setMaxNumber(int max) {
this.maxNumber = max; this.maxNumber = max;
if (context != null) { if (contextPrefix != null) {
context.setProperty(contextPrefix + ".maxNumber", JiveGlobals.setProperty(contextPrefix + ".maxNumber",
Integer.toString(maxNumber)); Integer.toString(maxNumber));
} }
} }
/** /**
* <p>Set the type of history strategy being used.</p> * Sets the type of history strategy being used.
* *
* @param newType The new type of chat history to use * @param newType The new type of chat history to use
*/ */
...@@ -111,13 +93,13 @@ public class HistoryStrategy { ...@@ -111,13 +93,13 @@ public class HistoryStrategy {
if (newType != null) { if (newType != null) {
type = newType; type = newType;
} }
if (context != null) { if (contextPrefix != null) {
context.setProperty(contextPrefix + ".type", type.toString()); JiveGlobals.setProperty(contextPrefix + ".type", type.toString());
} }
} }
/** /**
* <p>Obtain the type of history strategy being used.</p> * Returns the type of history strategy being used.
* *
* @return The current type of strategy being used * @return The current type of strategy being used
*/ */
...@@ -126,10 +108,10 @@ public class HistoryStrategy { ...@@ -126,10 +108,10 @@ public class HistoryStrategy {
} }
/** /**
* <p>Add a message to the current chat history.</p> * Adds a message to this chat history. The strategy type will
* <p>The strategy type will determine what actually happens to the message.</p> * determine what actually happens to the message.
* *
* @param packet The packet to add to the chatroom's history. * @param packet the packet to add to the chatroom's history.
*/ */
public void addMessage(Message packet) { public void addMessage(Message packet) {
// get the conditions based on default or not // get the conditions based on default or not
...@@ -182,13 +164,13 @@ public class HistoryStrategy { ...@@ -182,13 +164,13 @@ public class HistoryStrategy {
} }
/** /**
* <p>Obtain the current history as an iterator of messages to play * Returns the current history as an iterator of messages to play
* back to a new room member.</p> * back to a new room member.
* *
* @return An iterator of Message objects to be sent to the new room member * @return an iterator of Message objects to be sent to the new room member
*/ */
public Iterator getMessageHistory() { public Iterator getMessageHistory() {
LinkedList list = new LinkedList(history); List list = new ArrayList(history);
return list.iterator(); return list.iterator();
} }
...@@ -221,17 +203,14 @@ public class HistoryStrategy { ...@@ -221,17 +203,14 @@ public class HistoryStrategy {
} }
/** /**
* <p>Sets the context and string prefix to use for retrieving and saving * Set the prefix to use for retrieving and saving settings
* settings (and also triggers an immediate loading of properties).</p>
* *
* @param newContext The context to use to read/write properties * @param prefix the prefix to use (without trailing dot) on property names
* @param prefix The prefix to use (without trailing dot) on property names
*/ */
public void setContext(ModuleContext newContext, String prefix) { public void setContext(String prefix) {
this.context = newContext;
this.contextPrefix = prefix; this.contextPrefix = prefix;
setTypeFromString(context.getProperty(prefix + ".type")); setTypeFromString(JiveGlobals.getProperty(prefix + ".type"));
String maxNumberString = context.getProperty(prefix + ".maxNumber"); String maxNumberString = JiveGlobals.getProperty(prefix + ".maxNumber");
if (maxNumberString != null && maxNumberString.trim().length() > 0) { if (maxNumberString != null && maxNumberString.trim().length() > 0) {
try { try {
setMaxNumber(Integer.parseInt(maxNumberString)); setMaxNumber(Integer.parseInt(maxNumberString));
......
...@@ -13,7 +13,6 @@ package org.jivesoftware.messenger.chat.spi; ...@@ -13,7 +13,6 @@ package org.jivesoftware.messenger.chat.spi;
import org.jivesoftware.messenger.chat.*; import org.jivesoftware.messenger.chat.*;
import org.jivesoftware.messenger.container.BasicModule; import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.messenger.container.Container; import org.jivesoftware.messenger.container.Container;
import org.jivesoftware.messenger.container.ModuleContext;
import org.jivesoftware.messenger.container.TrackInfo; import org.jivesoftware.messenger.container.TrackInfo;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
...@@ -237,31 +236,21 @@ public class ChatServerImpl extends BasicModule implements ChatServer, RoutableC ...@@ -237,31 +236,21 @@ public class ChatServerImpl extends BasicModule implements ChatServer, RoutableC
* @param name the new server address. * @param name the new server address.
*/ */
public void setChatServerName(String name) { public void setChatServerName(String name) {
if (context != null) { JiveGlobals.setProperty("xmpp.chat.domain", name);
context.setProperty("xmpp.chat.domain", name);
}
} }
// ##################################################################### public void initialize(Container container) {
// Module management chatServerName = JiveGlobals.getProperty("xmpp.chat.domain");
// ##################################################################### // Trigger the strategy to load itself from the context
private ModuleContext context = null; historyStrategy.setContext("xmpp.chat.history");
public void initialize(ModuleContext modcontext, Container container) {
this.context = modcontext;
if (context != null) {
chatServerName = context.getProperty("xmpp.chat.domain");
// Trigger the strategy to load itself from the context
historyStrategy.setContext(context, "xmpp.chat.history");
// Pseudo MUC support for non-anonymous rooms - all or nothing setting // Pseudo MUC support for non-anonymous rooms - all or nothing setting
useAnonRooms = !"false".equals(context.getProperty("xmpp.chat.anonymous_rooms")); useAnonRooms = JiveGlobals.getBooleanProperty("xmpp.chat.anonymous_rooms");
}
if (chatServerName == null) { if (chatServerName == null) {
chatServerName = "chat.127.0.0.1"; chatServerName = "chat.127.0.0.1";
} }
chatServerAddress = new XMPPAddress(null, chatServerName, null); chatServerAddress = new XMPPAddress(null, chatServerName, null);
super.initialize(context, container); super.initialize(container);
} }
public void start() { public void start() {
......
...@@ -514,10 +514,9 @@ public class BasicModule implements Module { ...@@ -514,10 +514,9 @@ public class BasicModule implements Module {
* <p>Inheriting classes that choose to override this method MUST * <p>Inheriting classes that choose to override this method MUST
* call this initialize() method before accessing BasicModule resources.</p> * call this initialize() method before accessing BasicModule resources.</p>
* *
* @param context The context for the module
* @param container The container hosting the module * @param container The container hosting the module
*/ */
public void initialize(ModuleContext context, Container container) { public void initialize(Container container) {
try { try {
lookup = container.getServiceLookup(); lookup = container.getServiceLookup();
trackInfo = getTrackInfo(); trackInfo = getTrackInfo();
......
...@@ -106,15 +106,6 @@ public interface Container { ...@@ -106,15 +106,6 @@ public interface Container {
*/ */
void stopService(Class service) throws UnauthorizedException; void stopService(Class service) throws UnauthorizedException;
/**
* Obtain the general module context for this container. The module context
* may be empty since context often is picked up on a module by module basis.
*
* @return ModuleContext the module context for the container
* @throws UnauthorizedException If caller doesn't have appropriate permission
*/
ModuleContext getModuleContext() throws UnauthorizedException;
/** /**
* Obtain a special entry that modules can use to locate or register local services in * Obtain a special entry that modules can use to locate or register local services in
* the service registrar. * the service registrar.
......
...@@ -47,14 +47,13 @@ public interface Module { ...@@ -47,14 +47,13 @@ public interface Module {
String getName(); String getName();
/** /**
* Initialize the module with the given properties and it's container. * Initialize the module with the container.
* Modules may be initialized and never started, so modules * Modules may be initialized and never started, so modules
* should be prepared for a call to destroy() to follow initialize(). * should be prepared for a call to destroy() to follow initialize().
* *
* @param context Initialization properties for this module * @param container the container hosting this module.
* @param container The container hosting this module.
*/ */
void initialize(ModuleContext context, Container container); void initialize(Container container);
/** /**
* Start the module (must return quickly). Any long running * Start the module (must return quickly). Any long running
......
/*
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 1999-2003 CoolServlets, Inc. All rights reserved.
*
* This software is the proprietary information of CoolServlets, Inc.
* Use is subject to license terms.
*/
package org.jivesoftware.messenger.container;
import java.io.File;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
/**
* <p>A way of passing context information between the container and
* a module. This allows all modules to gather important information
* regarding their environment.</p>
* <p/>
* <p>Context information is stored in an XML configuration file to allow
* both programmatic and manual editing of configuration information.</p>
* <p/>
* <p>There are some special Jive properties that will always be set:</p>
* <p/>
* <ul>
* <li><strong>messengerHome</strong> - The directory where the XMPP server is
* installed</li>
* <li><strong>locale</strong> - The locale settings used by Jive including
* timezone, character encoding, date formats, etc.</li>
* </ul>
*
* @author Iain Shigeoka
*/
public interface ModuleContext extends ModuleProperties {
/**
* Returns the global Locale used by Jive. A locale specifies language
* and country codes, and is used for internationalization. The default
* locale is system dependant - Locale.getDefault().
*
* @return the global locale used by Jive.
*/
Locale getLocale();
/**
* Sets the global locale used by Jive. A locale specifies language
* and country codes, and is used for formatting dates and numbers.
* The default locale is Locale.US.
*
* @param newLocale the global Locale for Jive.
*/
void setLocale(Locale newLocale);
/**
* Returns the character set that Jive uses for encoding. This
* is used for displaying content in skins, sending email watch
* updates, etc. The default encoding is ISO-8895-1, which is suitable for
* most Latin languages. If you need to support double byte character sets
* such as Chinese or Japanese, it's recommend that you use utf-8
* as the charset (Unicode). Unicode offers simultaneous support for a
* large number of languages and is easy to convert into native charsets
* as necessary. You may also specifiy any other charset that is supported
* by your JVM. A list of encodings supported by the Sun JVM can be found
* <a href="http://java.sun.com/j2se/1.3/docs/guide/intl/encoding.doc.html">
* here.</a><p>
* <p/>
* In order for a particular encoding to work (such as Unicode), your
* application server and database may need to be specially configured.
* Please consult your server documentation for more information. For
* example, SQLServer has a special column type for Unicode text, and the
* Resin application server can be configured to use a custom charset by
* adding a &lt;character-encoding&gt; element to the web.xml/resin.conf
* file. Any Servlet 2.3 compliant application servers also supports the
* method HttpServletRequest.setCharacterEncoding(String). A Servlet 2.3
* Filter called SetCharacterEncodingFilter is installed in the default
* Jive Forums web.xml file, which will set the incoming character encoding
* to the one reported by this method.
*
* @return the global Jive character encoding.
*/
String getCharacterEncoding();
/**
* Sets the character set that Jive uses for encoding. This
* is used for displaying content in skins, sending email watch
* updates, etc. The default encoding is ISO-8859-1, which is suitable for
* most Latin languages. If you need to support double byte character sets
* such as Chinese or Japanese, it's recommend that you use utf-8
* as the charset (Unicode). Unicode offers simultaneous support for a
* large number of languages and is easy to convert into native charsets
* as necessary. You may also specifiy any other charset that is supported
* by your JVM. A list of encodings supported by the Sun JVM can be found
* <a href="http://java.sun.com/j2se/1.3/docs/guide/intl/encoding.doc.html">
* here.</a><p>
* <p/>
* In order for a particular encoding to work (such as Unicode), your
* application server and database may need to be specially configured.
* Please consult your server documentation for more information. For
* example, SQLServer has a special column type for Unicode text, and the
* Resin application server can be configured to use a custom charset by
* adding a &lt;character-encoding&gt; element to the web.xml/resin.conf
* file. Any Servlet 2.3 compliant application servers also supports the
* method HttpServletRequest.setCharacterEncoding(String). A Servlet 2.3
* Filter called SetCharacterEncodingFilter is installed in the default
* Jive Forums web.xml file, which will set the incoming character encoding
* to the one reported by this method.
*
* @param characterEncoding the global Jive character encoding.
*/
void setCharacterEncoding(String characterEncoding);
/**
* Returns the global TimeZone used by Jive. The default is the VM's
* default time zone.
*
* @return the global time zone used by Jive.
*/
TimeZone getTimeZone();
/**
* Sets the global time zone used by Jive. The default time zone is the VM's
* time zone.
*
* @param newTimeZone The new timezone for the context to use
*/
void setTimeZone(TimeZone newTimeZone);
/**
* Formats a Date object to return a date using the global locale.
*
* @param date the Date to format.
* @return a String representing the date.
*/
String formatDate(Date date);
/**
* Formats a Date object to return a date and time using the global locale.
*
* @param date the Date to format.
* @return a String representing the date and time.
*/
String formatDateTime(Date date);
/**
* Returns the location of the home directory for the module.
*
* @return the location of the home dir for the module
*/
File getHomeDirectory();
/**
* Returns the location of the log directory for the module.
*
* @return the location of the log dir for the module
*/
File getLogDirectory();
}
/*
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 1999-2003 CoolServlets, Inc. All rights reserved.
*
* This software is the proprietary information of CoolServlets, Inc.
* Use is subject to license terms.
*/
package org.jivesoftware.messenger.container;
import java.util.Iterator;
/**
* A way of passing context information between the container and
* a module. This allows all modules to gather important information
* regarding their environment.
* <p/>
* Properties can by any arbitrary key/value String pair. However,
* we strongly suggest that you use dots to separate attribute groups
* using the format: &quot;parent.child.propName&quot; although this is not required.
* The default property save/load implementation will store these
* values in an XML file with the format:
* <pre>
* <p/>
* &lt;parent&gt;
* &lt;child&gt;
* &lt;propName&gt;
* propValue
* &lt;/propName&gt;
* &lt;/child&gt;
* &lt;/parent&gt;
* <p/>
* </pre>
*
* @author Iain Shigeoka
*/
public interface ModuleProperties {
/**
* Returns a Jive property. Jive properties are stored in the file
* <tt>jive-messenger.xml</tt> that exists in the <tt>messengerHome/conf</tt> directory.
* Properties are always specified as "foo.bar.prop", which would map to
* the following entry in the XML file:
* <pre>
* &lt;foo&gt;
* &lt;bar&gt;
* &lt;prop&gt;some value&lt;/prop&gt;
* &lt;/bar&gt;
* &lt;/foo&gt;
* </pre>
*
* @param name the name of the property to return.
* @return the property value specified by name.
*/
String getProperty(String name);
/**
* Return all values who's path matches the given property name as a String array,
* or an empty array if the if there are no children. This allows you to retrieve
* several values with the same property name.
* For example, consider the XML file entry:
* <pre>
* &lt;foo&gt;
* &lt;bar&gt;
* &lt;prop&gt;some value&lt;/prop&gt;
* &lt;prop&gt;other value&lt;/prop&gt;
* &lt;prop&gt;last value&lt;/prop&gt;
* &lt;/bar&gt;
* &lt;/foo&gt;
* </pre>
* If you call getProperties("foo.bar.prop") will return a string array containing
* {"some value", "other value", "last value"}.
*
* @param name the name of the property to retrieve
* @return all child property values for the given node name.
*/
String[] getProperties(String name);
/**
* <p>Creates a ModuleProperties object as a new child element with the given
* root node name.</p>
* <p/>
* <p>This method provides a convenient method of adding a new item to a series
* of parallel properties. For example if there is an existing xml tree:</p>
* <pre>
* <a>
* <b>item-data</b>
* </a>
* </pre>
* <p>And the following code is called:
* <pre><code>
* ModuleProperties childProp = parentProp.createChildProperty("a.b");
* childProp.setProperty("b.c","foo");
* </code></pre>
* <p/>
* <p>The resulting XML will look like:</p>
* <pre>
* <a>
* <b>item-data</b>
* <b>
* <c>foo</c>
* </b>
* </a>
* </pre>
*
* @param name the property name of the root of the new ModuleProperties object
* @return The ModuleProperties object created or null if no property matched the given name
*/
ModuleProperties createChildProperty(String name);
/**
* Return an iterator of ModuleProperties objects (possibly empty)
* that are rooted in the given property name. Each sub-property object
* represents a matching child element within the given root element.
* This allows you to retrieve several complex property 'trees' with
* the same property name. For example, consider the XML file entry:
* <pre>
* <a>
* <b>
* <c>
* <d>d-one</d>
* <e>e-one</e>
* <f>
* <g>g-one</g>
* </f>
* </c>
* <c>
* <d>d-two</d>
* <e>e-two</e>
* <f>
* <g>g-two</g>
* </f>
* </c>
* <c>
* <d>d-three</d>
* <e>e-three</e>
* <f>
* <g>g-three</g>
* </f>
* </c>
* </b>
* </a>
* </pre>
* <p>If you call getChildProperties("a.b.c") you will receieve an Iterator
* containing three ModuleProperties. If you call getProperty("c.f.g") on
* the first ModuleProperties you'll receive "g-one", and the same call
* on the second ModuleProperties in the Iterator will return "g-two".</p>
* <p/>
* <p>Note that the child ModuleProperties are linked to their parent property.
* Changes to child ModuleProperties are automatically reflected in the parent
* ModuleProperty. Deleting or changing the parent ModuleProperty can cause
* child ModuleProperties to become invalid or detached from the parent.
* Care must be taken not to acces child properties after they have been
* deleted at the parent level.</p>
*
* @param name the name of the property to retrieve
* @return Iterator of ModuleProperties objects that have roots at the given name.
* The child ModuleProperties objects will have the last element name as their
* new root property name.
*/
Iterator getChildProperties(String name);
/**
* Sets a property to an array of values. Multiple values matching the same property
* is mapped to an XML file as multiple elements containing each value.
* For example, using the name "foo.bar.prop", and the value string array containing
* {"some value", "other value", "last value"} would produce the following XML:
* <pre>
* &lt;foo&gt;
* &lt;bar&gt;
* &lt;prop&gt;some value&lt;/prop&gt;
* &lt;prop&gt;other value&lt;/prop&gt;
* &lt;prop&gt;last value&lt;/prop&gt;
* &lt;/bar&gt;
* &lt;/foo&gt;
* </pre>
*
* @param name the name of the property.
* @param values The array of values for the property (can be empty but not null)
*/
void setProperties(String name, String[] values);
/**
* Sets a Jive property. If the property doesn't already exists, a new
* one will be created. Jive properties are stored in the file
* <tt>jive-messenger.xml</tt> that exists in the <tt>messengerHome/conf</tt> directory.
* Properties are always specified as "foo.bar.prop", which would map to
* the following entry in the XML file:
* <pre>
* &lt;foo&gt;
* &lt;bar&gt;
* &lt;prop&gt;some value&lt;/prop&gt;
* &lt;/bar&gt;
* &lt;/foo&gt;
* </pre>
*
* @param name the name of the property being set.
* @param value the value of the property being set.
*/
void setProperty(String name, String value);
/**
* Deletes a Jive property. If the property doesn't exist, the method
* does nothing.
*
* @param name the name of the property to delete.
*/
void deleteProperty(String name);
}
...@@ -12,9 +12,7 @@ package org.jivesoftware.messenger.container.spi; ...@@ -12,9 +12,7 @@ package org.jivesoftware.messenger.container.spi;
import org.jivesoftware.database.DbConnectionManager; import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.messenger.container.*; import org.jivesoftware.messenger.container.*;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.*;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.XPPReader;
import org.jivesoftware.messenger.JiveGlobals; import org.jivesoftware.messenger.JiveGlobals;
import org.jivesoftware.messenger.auth.UnauthorizedException; import org.jivesoftware.messenger.auth.UnauthorizedException;
...@@ -122,16 +120,12 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv ...@@ -122,16 +120,12 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv
protected abstract String getFileCoreName(); protected abstract String getFileCoreName();
/** /**
* <p>The root context for the server. modules will use this as * The lookup for the bootstrap container.
* a parent context to their own module context.</p>
*/
private XMLModuleContext context;
/**
* <p>The lookup for the bootstrap container.</p>
*/ */
private ServiceLookup lookup; private ServiceLookup lookup;
/** /**
* <p>The registration of the service with itself.</p> * The registration of the service with itself.
*/ */
private ServiceRegistration containerRegistration; private ServiceRegistration containerRegistration;
...@@ -145,8 +139,6 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv ...@@ -145,8 +139,6 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv
* located here. * located here.
*/ */
private File messengerHome; private File messengerHome;
private File logDir;
private File configFile;
private ClassLoader loader; private ClassLoader loader;
/** /**
...@@ -154,7 +146,6 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv ...@@ -154,7 +146,6 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv
*/ */
private boolean setupMode = true; private boolean setupMode = true;
private static final String JIVE_LOG_DIR = "logs";
private static final String STARTER_CLASSNAME = private static final String STARTER_CLASSNAME =
"org.jivesoftware.messenger.container.starter.ServerStarter"; "org.jivesoftware.messenger.container.starter.ServerStarter";
private static final String WRAPPER_CLASSNAME = private static final String WRAPPER_CLASSNAME =
...@@ -171,14 +162,13 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv ...@@ -171,14 +162,13 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv
} }
/** /**
* <p>Starts the container.</p> * Starts the container.
*/ */
private void start() { private void start() {
try { try {
// Let's specify jive_messenger.xml as the new config file. // Let's specify jive_messenger.xml as the new config file.
locateJiveHome(); locateMessenger();
context = new XMLModuleContext(null, configFile, messengerHome, logDir); if ("true".equals(JiveGlobals.getXMLProperty("setup"))) {
if ("true".equals(context.getProperty("setup"))) {
setupMode = false; setupMode = false;
} }
...@@ -192,7 +182,6 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv ...@@ -192,7 +182,6 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv
loader = Thread.currentThread().getContextClassLoader(); loader = Thread.currentThread().getContextClassLoader();
if (setupMode) { if (setupMode) {
loadCorePlugins(getSetupModuleNames()); loadCorePlugins(getSetupModuleNames());
} }
...@@ -243,14 +232,14 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv ...@@ -243,14 +232,14 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv
java.sql.Connection conn = null; java.sql.Connection conn = null;
try { try {
conn = DbConnectionManager.getConnection(); conn = DbConnectionManager.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELECT userID FROM jiveUser WHERE userID=1"); PreparedStatement stmt = conn.prepareStatement("SELECT count(*) FROM jiveID");
ResultSet rs = stmt.executeQuery(); ResultSet rs = stmt.executeQuery();
while (rs.next()) { rs.next();
}
rs.close(); rs.close();
stmt.close();
} }
catch (Exception e) { catch (Exception e) {
System.out.println("Database setup or configuration error: " + System.err.println("Database setup or configuration error: " +
"Please verify your database settings and check the " + "Please verify your database settings and check the " +
"logs/error.log file for detailed error messages."); "logs/error.log file for detailed error messages.");
Log.error("Database could not be accessed", e); Log.error("Database could not be accessed", e);
...@@ -258,12 +247,8 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv ...@@ -258,12 +247,8 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv
} }
finally { finally {
if (conn != null) { if (conn != null) {
try { try { conn.close(); }
conn.close(); catch (SQLException e) { Log.error(e); }
}
catch (SQLException e) {
Log.error("Could not close open connection ", e);
}
} }
} }
} }
...@@ -280,7 +265,7 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv ...@@ -280,7 +265,7 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv
try { try {
Class modClass = loader.loadClass(modules[i]); Class modClass = loader.loadClass(modules[i]);
mod = (Module)modClass.newInstance(); mod = (Module)modClass.newInstance();
mod.initialize(context, this); mod.initialize(this);
isInitialized = true; isInitialized = true;
this.modules.add(mod); this.modules.add(mod);
} }
...@@ -350,8 +335,8 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv ...@@ -350,8 +335,8 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv
File[] plugins = pluginDir.listFiles(); File[] plugins = pluginDir.listFiles();
for (int i = 0; i < plugins.length; i++) { for (int i = 0; i < plugins.length; i++) {
if (plugins[i].isDirectory()) { if (plugins[i].isDirectory()) {
// Only load admin plugin if in setup mode.
if (setupMode) { if (setupMode) {
// Only load web-admin plug-in
if ("admin".equals(plugins[i].getName())) { if ("admin".equals(plugins[i].getName())) {
loadPlugin(plugins[i]); loadPlugin(plugins[i]);
} }
...@@ -385,11 +370,10 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv ...@@ -385,11 +370,10 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv
try { try {
File moduleConfig = new File(pluginDir, "module.xml"); File moduleConfig = new File(pluginDir, "module.xml");
if (moduleConfig.exists()) { if (moduleConfig.exists()) {
ModuleContext modContext = XMLProperties moduleProps = new XMLProperties(moduleConfig);
new XMLModuleContext(context, moduleConfig, pluginDir, logDir);
JiveModuleLoader modLoader = new JiveModuleLoader(pluginDir.toString()); JiveModuleLoader modLoader = new JiveModuleLoader(pluginDir.toString());
mod = modLoader.loadModule(modContext.getProperty("module")); mod = modLoader.loadModule(moduleProps.getProperty("module"));
mod.initialize(modContext, this); mod.initialize(this);
mod.start(); mod.start();
this.modules.add(mod); this.modules.add(mod);
} }
...@@ -435,10 +419,6 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv ...@@ -435,10 +419,6 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv
} }
} }
public ModuleContext getModuleContext() throws UnauthorizedException {
return context;
}
public Entry getLocalServerAttribute() throws UnauthorizedException { public Entry getLocalServerAttribute() throws UnauthorizedException {
return new Entry() { return new Entry() {
}; };
...@@ -559,7 +539,7 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv ...@@ -559,7 +539,7 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv
* *
* @throws FileNotFoundException If jiveHome could not be located * @throws FileNotFoundException If jiveHome could not be located
*/ */
private void locateJiveHome() throws FileNotFoundException { private void locateMessenger() throws FileNotFoundException {
String jiveConfigName = "conf" + File.separator + "jive-" + getFileCoreName() + ".xml"; String jiveConfigName = "conf" + File.separator + "jive-" + getFileCoreName() + ".xml";
// First, try to load it jiveHome as a system property. // First, try to load it jiveHome as a system property.
if (messengerHome == null) { if (messengerHome == null) {
...@@ -574,21 +554,14 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv ...@@ -574,21 +554,14 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv
} }
} }
// If we still don't have jiveHome, let's assume this is standalone // If we still don't have messengerHome, let's assume this is standalone
// and just look for jiveHome in a standard sub-dir location and verify // and just look for messengerHome in a standard sub-dir location and verify
// by looking for the config file // by looking for the config file
if (messengerHome == null) { if (messengerHome == null) {
try { try {
messengerHome = verifyHome("..", jiveConfigName); messengerHome = verifyHome("..", jiveConfigName);
} }
catch (FileNotFoundException fe) { catch (FileNotFoundException fe) {
String path = "..";
try {
path = new File("..").getCanonicalPath();
}
catch (Exception e) {
System.err.println("Could not resolve path to '..'");
}
} }
} }
...@@ -637,8 +610,6 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv ...@@ -637,8 +610,6 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv
} }
else { else {
JiveGlobals.messengerHome = messengerHome.toString(); JiveGlobals.messengerHome = messengerHome.toString();
configFile = new File(messengerHome, jiveConfigName);
logDir = new File(messengerHome, JIVE_LOG_DIR);
} }
} }
} }
...@@ -11,12 +11,13 @@ ...@@ -11,12 +11,13 @@
package org.jivesoftware.messenger.container.spi; package org.jivesoftware.messenger.container.spi;
import org.jivesoftware.messenger.container.*; import org.jivesoftware.messenger.container.*;
import org.jivesoftware.messenger.JiveGlobals;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import java.io.File; import java.io.File;
import org.mortbay.jetty.Server; import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.WebApplicationContext; import org.mortbay.jetty.servlet.WebApplicationContext;
import org.mortbay.log.OutputStreamLogSink; import org.mortbay.log.*;
/** /**
* A simple wrapper that allows Jetty to run inside the Messenger * A simple wrapper that allows Jetty to run inside the Messenger
...@@ -42,30 +43,35 @@ public class JettyModule implements Module { ...@@ -42,30 +43,35 @@ public class JettyModule implements Module {
} }
public String getName() { public String getName() {
return "Embedded Webserver"; return "Admin Console";
} }
public void initialize(ModuleContext context, Container container) { public void initialize(Container container) {
try { try {
// Configure logging to a file, creating log dir if needed // Configure logging to a file, creating log dir if needed
File logDir = context.getLogDirectory(); // File logDir = new File(JiveGlobals.getMessengerHome(), "logs");
if (!logDir.exists()) { // if (!logDir.exists()) {
logDir.mkdirs(); // logDir.mkdirs();
} // }
File logFile = new File(logDir, "embedded-web.log"); // File logFile = new File(logDir, "admin_console.log");
OutputStreamLogSink logSink = new OutputStreamLogSink(logFile.toString()); // OutputStreamLogSink logSink = new OutputStreamLogSink(logFile.toString());
logSink.start(); // logSink.start();
// LogImpl log = (LogImpl)Factory.getFactory().getInstance("");
// log.reset();
// log.add(logSink);
jetty = new Server(); jetty = new Server();
// Configure HTTP socket listener // Configure HTTP socket listener
port = context.getProperty("embedded-web.port"); port = JiveGlobals.getProperty("embedded-web.port", "9090");
jetty.addListener(port); jetty.addListener(port);
this.serverContainer = container; this.serverContainer = container;
// Add web-app // Add web-app
webAppContext = jetty.addWebApplication("/", // TODO this shouldn't be hardcoded to look for the "admin" plugin.
context.getHomeDirectory() + "/webapp/"); webAppContext = jetty.addWebApplication("/", JiveGlobals.getMessengerHome() +
File.separator + "plugins" + File.separator + "admin" +
File.separator + "webapp");
} }
catch (Exception e) { catch (Exception e) {
Log.error("Trouble initializing Jetty", e); Log.error("Trouble initializing Jetty", e);
......
...@@ -87,16 +87,13 @@ public class JiveModuleLoader { ...@@ -87,16 +87,13 @@ public class JiveModuleLoader {
* *
* @param className The fully qualified name of the class to load * @param className The fully qualified name of the class to load
* @return The module object loaded * @return The module object loaded
* @throws java.lang.ClassNotFoundException * @throws ClassNotFoundException if the class could not be loaded by this class loader.
* if the class could not be loaded by this class loader. * @throws IllegalAccessException if the class constructor was private or protected.
* @throws java.lang.IllegalAccessException * @throws InstantiationException if the class could not be instantiated (initialization error).
* if the class constructor was private or protected. * @throws SecurityException if the custom class loader not allowed.
* @throws java.lang.InstantiationException
* if the class could not be instantiated (initialization error).
* @throws java.lang.SecurityException if the custom class loader not allowed.
*/ */
public Module loadModule(String className) throws ClassNotFoundException, IllegalAccessException, public Module loadModule(String className) throws ClassNotFoundException, IllegalAccessException,
InstantiationException, SecurityException InstantiationException, SecurityException
{ {
Class moduleClass = classLoader.loadClass(className); Class moduleClass = classLoader.loadClass(className);
Module mod = (Module)moduleClass.newInstance(); Module mod = (Module)moduleClass.newInstance();
...@@ -118,5 +115,4 @@ public class JiveModuleLoader { ...@@ -118,5 +115,4 @@ public class JiveModuleLoader {
} }
return parent; return parent;
} }
}
} \ No newline at end of file
/*
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 1999-2003 CoolServlets, Inc. All rights reserved.
*
* This software is the proprietary information of CoolServlets, Inc.
* Use is subject to license terms.
*/
package org.jivesoftware.messenger.container.spi;
import org.jivesoftware.messenger.container.ModuleContext;
import org.jivesoftware.messenger.container.ModuleProperties;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.XMLProperties;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.util.*;
/**
* A way of passing context information between the container and
* a module. This allows all modules to gather important information
* regarding their environment.
* <p/>
* Properties can by any arbitrary key/value String pair. However,
* we strongly suggest that you use dots to separate attribute groups
* using the format: &quot;parent.child.propName&quot; although this is not required.
* The default property save/load implementation will store these
* values in an XML file with the format:
* <pre>
* <p/>
* &lt;parent&gt;
* &lt;child&gt;
* &lt;propName&gt;
* propValue
* &lt;/propName&gt;
* &lt;/child&gt;
* &lt;/parent&gt;
* <p/>
* </pre>
* </p>
*
* @author Iain Shigeoka
*/
public class XMLModuleContext implements ModuleContext {
/**
* Should only be created by Jive internal classes.
*
* @param parent the parent context.
* @param filename the name of the file this context where it is loaded/saved.
* @param home the home directory for the server.
* @param log the log directory for the server.
*/
public XMLModuleContext(ModuleContext parent,
File filename,
File home,
File log) {
this.parentContext = parent;
this.homeDir = home;
this.logDir = log;
loadProperties(filename);
}
/**
* XML properties to actually get and set the Jive properties.
*/
private XMLProperties properties = null;
private ModuleContext parentContext;
private Locale locale = null;
private TimeZone timeZone = null;
private String characterEncoding = null;
private DateFormat dateFormat = null;
private DateFormat dateTimeFormat = null;
private File homeDir;
private File logDir;
public Locale getLocale() {
Locale loc = locale;
if (locale == null && parentContext != null) {
loc = parentContext.getLocale();
}
else {
loc = Locale.getDefault();
}
return loc;
}
public void setLocale(Locale newLocale) {
if (newLocale == null) {
locale = Locale.getDefault();
}
else {
locale = newLocale;
}
// Save values to Jive properties.
setProperty("locale.country", locale.getCountry());
setProperty("locale.language", locale.getLanguage());
// Reset the date formatter objects
dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
DateFormat.MEDIUM, locale);
dateFormat.setTimeZone(timeZone);
dateTimeFormat.setTimeZone(timeZone);
}
public String getCharacterEncoding() {
String encoding = characterEncoding;
if (characterEncoding == null && parentContext != null) {
encoding = parentContext.getCharacterEncoding();
}
return encoding;
}
public void setCharacterEncoding(String encoding) {
this.characterEncoding = encoding;
setProperty("locale.characterEncoding", encoding);
}
public TimeZone getTimeZone() {
TimeZone zone = timeZone;
if (timeZone == null && parentContext != null) {
zone = parentContext.getTimeZone();
}
if (zone == null) {
zone = TimeZone.getDefault();
}
return zone;
}
public void setTimeZone(TimeZone newTimeZone) {
timeZone = newTimeZone;
dateFormat.setTimeZone(timeZone);
dateTimeFormat.setTimeZone(timeZone);
setProperty("locale.timeZone", timeZone.getID());
}
public String formatDate(Date date) {
String formattedDate;
if (dateFormat == null && parentContext != null) {
formattedDate = parentContext.formatDate(date);
}
else {
formattedDate = dateFormat.format(date);
}
return formattedDate;
}
public String formatDateTime(Date date) {
String formattedDate;
if (dateTimeFormat == null && parentContext != null) {
formattedDate = parentContext.formatDateTime(date);
}
else {
formattedDate = dateTimeFormat.format(date);
}
return formattedDate;
}
public File getHomeDirectory() {
return homeDir;
}
public File getLogDirectory() {
return logDir;
}
public String getProperty(String name) {
String prop = null;
if (parentContext != null) {
prop = parentContext.getProperty(name);
}
if (prop == null && properties != null) {
prop = properties.getProperty(name);
}
return prop;
}
public String[] getProperties(String name) {
String[] props = null;
if (parentContext != null) {
props = parentContext.getProperties(name);
}
if (props == null && properties != null) {
props = properties.getProperties(name);
}
if (props == null) {
props = new String[]{};
}
return props;
}
public ModuleProperties createChildProperty(String name) {
ModuleProperties props = null;
if (parentContext != null) {
props = parentContext.createChildProperty(name);
}
if (props == null && properties != null) {
props = properties.createChildProperty(name);
}
return props;
}
public Iterator getChildProperties(String name) {
Iterator props = null;
if (parentContext != null) {
props = parentContext.getChildProperties(name);
}
if (props == null && properties != null) {
props = properties.getChildProperties(name);
}
if (props == null) {
props = Collections.EMPTY_LIST.iterator();
}
return props;
}
public void setProperties(String name, String[] values) {
if (parentContext != null) {
parentContext.setProperties(name, values);
}
else if (properties != null) {
properties.setProperties(name, values);
}
}
public void setProperty(String name, String value) {
if (parentContext != null) {
parentContext.setProperty(name, value);
}
else {
if (properties != null) {
properties.setProperty(name, value);
}
}
}
public void deleteProperty(String name) {
if (properties != null) {
properties.deleteProperty(name);
}
}
/**
* Loads properties if necessary. Property loading must be done lazily so
* that we give outside classes a chance to set <tt>messengerHome</tt>.
*/
private synchronized void loadProperties(File filename) {
if (properties == null) {
// Create a manager with the full path to the xml config file.
try {
properties = new XMLProperties(filename.toString());
}
catch (IOException ioe) {
Log.error(ioe);
return;
}
}
if (locale == null) {
String language = getDefaultProperty("locale.language", "");
String country = getDefaultProperty("locale.country", "");
// If no locale info is specified, default to system default Locale
if ("".equals(language) && "".equals(country)) {
locale = Locale.getDefault();
}
else {
locale = new Locale(language, country);
}
// The default encoding is ISO-8859-1. We use the version of
// the encoding name that seems to be most widely compatible.
characterEncoding = getDefaultProperty("locale.characterEncoding",
"ISO-8859-1");
String timeZoneID = getDefaultProperty("locale.timeZone",
TimeZone.getDefault().getID());
timeZone = TimeZone.getTimeZone(timeZoneID);
dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
DateFormat.MEDIUM, locale);
dateFormat.setTimeZone(timeZone);
dateTimeFormat.setTimeZone(timeZone);
}
}
/**
* Loads a property with the given name. Null properties will have the default value
* returned instead.
*
* @param name the name of the jive property to load.
* @param value the default value of the property if it doesn't exist in the file
* @return the value of the property
*/
private String getDefaultProperty(String name, String value) {
String prop = properties.getProperty(name);
if (prop == null) {
prop = value;
}
return prop;
}
}
...@@ -59,6 +59,7 @@ abstract public class ServerStarter { ...@@ -59,6 +59,7 @@ abstract public class ServerStarter {
// TODO: Possibly load this lib dir as a java property? // TODO: Possibly load this lib dir as a java property?
File libDir = new File("../lib"); File libDir = new File("../lib");
ClassLoader loader = new JiveClassLoader(parent, libDir); ClassLoader loader = new JiveClassLoader(parent, libDir);
Thread.currentThread().setContextClassLoader(loader); Thread.currentThread().setContextClassLoader(loader);
Class containerClass = loader.loadClass(getBootContainerClassName()); Class containerClass = loader.loadClass(getBootContainerClassName());
containerClass.newInstance(); containerClass.newInstance();
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
package org.jivesoftware.messenger.handler; package org.jivesoftware.messenger.handler;
import org.jivesoftware.messenger.container.Container; import org.jivesoftware.messenger.container.Container;
import org.jivesoftware.messenger.container.ModuleContext;
import org.jivesoftware.messenger.container.TrackInfo; import org.jivesoftware.messenger.container.TrackInfo;
import org.jivesoftware.messenger.disco.ServerFeaturesProvider; import org.jivesoftware.messenger.disco.ServerFeaturesProvider;
import org.jivesoftware.messenger.forms.DataForm; import org.jivesoftware.messenger.forms.DataForm;
...@@ -83,8 +82,8 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid ...@@ -83,8 +82,8 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
info = new IQHandlerInfo("query", "jabber:iq:register"); info = new IQHandlerInfo("query", "jabber:iq:register");
} }
public void initialize(ModuleContext context, Container container) { public void initialize(Container container) {
super.initialize(context, container); super.initialize(container);
if (probeResult == null) { if (probeResult == null) {
// Create the basic element of the probeResult which contains the basic registration // Create the basic element of the probeResult which contains the basic registration
// information (e.g. username, passoword and email) // information (e.g. username, passoword and email)
......
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
*/ */
package org.jivesoftware.messenger.muc; package org.jivesoftware.messenger.muc;
import org.jivesoftware.messenger.container.ModuleContext;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.messenger.Message; import org.jivesoftware.messenger.Message;
import org.jivesoftware.messenger.JiveGlobals;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
...@@ -56,10 +56,6 @@ public class HistoryStrategy { ...@@ -56,10 +56,6 @@ public class HistoryStrategy {
* Track the latest room subject change or null if none exists yet. * Track the latest room subject change or null if none exists yet.
*/ */
private Message roomSubject = null; private Message roomSubject = null;
/**
* If set, indicates settings should be saved to the given context.
*/
private ModuleContext context = null;
/** /**
* The string prefix to be used on the context property names * The string prefix to be used on the context property names
* (do not include trailing dot). * (do not include trailing dot).
...@@ -99,8 +95,8 @@ public class HistoryStrategy { ...@@ -99,8 +95,8 @@ public class HistoryStrategy {
*/ */
public void setMaxNumber(int max) { public void setMaxNumber(int max) {
this.maxNumber = max; this.maxNumber = max;
if (context != null){ if (contextPrefix != null){
context.setProperty(contextPrefix + ".maxNumber", JiveGlobals.setProperty(contextPrefix + ".maxNumber",
Integer.toString(maxNumber)); Integer.toString(maxNumber));
} }
} }
...@@ -114,8 +110,8 @@ public class HistoryStrategy { ...@@ -114,8 +110,8 @@ public class HistoryStrategy {
if (newType != null){ if (newType != null){
type = newType; type = newType;
} }
if (context != null){ if (contextPrefix != null){
context.setProperty(contextPrefix + ".type", type.toString()); JiveGlobals.setProperty(contextPrefix + ".type", type.toString());
} }
} }
...@@ -234,17 +230,15 @@ public class HistoryStrategy { ...@@ -234,17 +230,15 @@ public class HistoryStrategy {
} }
/** /**
* Sets the context and string prefix to use for retrieving and saving settings (and also * Sets the prefix to use for retrieving and saving settings (and also
* triggers an immediate loading of properties). * triggers an immediate loading of properties).
* *
* @param newContext The context to use to read/write properties. * @param prefix the prefix to use (without trailing dot) on property names.
* @param prefix The prefix to use (without trailing dot) on property names.
*/ */
public void setContext(ModuleContext newContext, String prefix) { public void setContext(String prefix) {
this.context = newContext;
this.contextPrefix = prefix; this.contextPrefix = prefix;
setTypeFromString(context.getProperty(prefix + ".type")); setTypeFromString(JiveGlobals.getProperty(prefix + ".type"));
String maxNumberString = context.getProperty(prefix + ".maxNumber"); String maxNumberString = JiveGlobals.getProperty(prefix + ".maxNumber");
if (maxNumberString != null && maxNumberString.trim().length() > 0){ if (maxNumberString != null && maxNumberString.trim().length() > 0){
try { try {
setMaxNumber(Integer.parseInt(maxNumberString)); setMaxNumber(Integer.parseInt(maxNumberString));
......
...@@ -12,7 +12,6 @@ package org.jivesoftware.messenger.muc; ...@@ -12,7 +12,6 @@ package org.jivesoftware.messenger.muc;
import java.util.List; import java.util.List;
import org.jivesoftware.messenger.muc.HistoryStrategy;
import org.jivesoftware.messenger.auth.UnauthorizedException; import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.user.UserNotFoundException; import org.jivesoftware.messenger.user.UserNotFoundException;
import org.jivesoftware.messenger.*; import org.jivesoftware.messenger.*;
...@@ -20,9 +19,7 @@ import org.jivesoftware.messenger.*; ...@@ -20,9 +19,7 @@ import org.jivesoftware.messenger.*;
/** /**
* Manages groupchat conversations, chatrooms, and users. This class is designed to operate * Manages groupchat conversations, chatrooms, and users. This class is designed to operate
* independently from the rest of the Jive server infrastruture. This theoretically allows * independently from the rest of the Jive server infrastruture. This theoretically allows
* deployment of the groupchat on a separate server from the main IM server. <p/> * deployment of the groupchat on a separate server from the main IM server.
*
* TODO Enforce chat security and authorization using proxies
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
...@@ -181,7 +178,7 @@ public interface MultiUserChatServer { ...@@ -181,7 +178,7 @@ public interface MultiUserChatServer {
* the logged messages in memory until the logging process saves them to the database. It's * the logged messages in memory until the logging process saves them to the database. It's
* possible to configure the logging process to run every X milliseconds and also the number * possible to configure the logging process to run every X milliseconds and also the number
* of messages to log on each execution. * of messages to log on each execution.
* @see org.jivesoftware.messenger.muc.spi.MultiUserChatServerImpl#initialize(org.jivesoftware.messenger.container.ModuleContext, org.jivesoftware.messenger.container.Container) * @see org.jivesoftware.messenger.muc.spi.MultiUserChatServerImpl#initialize(org.jivesoftware.messenger.container.Container)
* *
* @param room the room that received the message. * @param room the room that received the message.
* @param message the message to log as part of the conversation in the room. * @param message the message to log as part of the conversation in the room.
......
...@@ -12,7 +12,6 @@ package org.jivesoftware.messenger.spi; ...@@ -12,7 +12,6 @@ package org.jivesoftware.messenger.spi;
import org.jivesoftware.messenger.container.BasicModule; import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.messenger.container.Container; import org.jivesoftware.messenger.container.Container;
import org.jivesoftware.messenger.container.ModuleContext;
import org.jivesoftware.messenger.container.ServiceLookup; import org.jivesoftware.messenger.container.ServiceLookup;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
...@@ -40,7 +39,6 @@ public class BasicServer ...@@ -40,7 +39,6 @@ public class BasicServer
private ServiceLookup lookup; private ServiceLookup lookup;
private ConnectionManager connectionManager; private ConnectionManager connectionManager;
private boolean initialized = false; private boolean initialized = false;
private ModuleContext modContext = null;
/** /**
* Create a default loopback test server. * Create a default loopback test server.
...@@ -64,7 +62,7 @@ public class BasicServer ...@@ -64,7 +62,7 @@ public class BasicServer
if (!initialized) { if (!initialized) {
throw new IllegalStateException("Not initialized yet"); throw new IllegalStateException("Not initialized yet");
} }
return new XMPPServerInfoImpl(modContext, name, version, startDate, stopDate, ports); return new XMPPServerInfoImpl(name, version, startDate, stopDate, ports);
} }
public boolean isLocal(XMPPAddress jid) { public boolean isLocal(XMPPAddress jid) {
...@@ -91,12 +89,11 @@ public class BasicServer ...@@ -91,12 +89,11 @@ public class BasicServer
return "XMPP Server Kernel"; return "XMPP Server Kernel";
} }
public void initialize(ModuleContext context, Container container) { public void initialize(Container container) {
super.initialize(context, container); super.initialize(container);
modContext = context;
try { try {
lookup = container.getServiceLookup(); lookup = container.getServiceLookup();
name = context.getProperty("xmpp.domain"); name = JiveGlobals.getProperty("xmpp.domain");
if (name == null) { if (name == null) {
name = "127.0.0.1"; name = "127.0.0.1";
} }
......
...@@ -12,7 +12,6 @@ package org.jivesoftware.messenger.spi; ...@@ -12,7 +12,6 @@ package org.jivesoftware.messenger.spi;
import org.jivesoftware.messenger.container.BasicModule; import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.messenger.container.Container; import org.jivesoftware.messenger.container.Container;
import org.jivesoftware.messenger.container.ModuleContext;
import org.jivesoftware.messenger.container.TrackInfo; import org.jivesoftware.messenger.container.TrackInfo;
import org.jivesoftware.util.Cache; import org.jivesoftware.util.Cache;
import org.jivesoftware.util.*; import org.jivesoftware.util.*;
...@@ -434,8 +433,8 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -434,8 +433,8 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
// Module management // Module management
// ##################################################################### // #####################################################################
public void initialize(ModuleContext context, Container container) { public void initialize(Container container) {
super.initialize(context, container); super.initialize(container);
initializeCaches(); initializeCaches();
} }
......
...@@ -74,8 +74,6 @@ public class SessionManagerImpl extends BasicModule implements SessionManager, ...@@ -74,8 +74,6 @@ public class SessionManagerImpl extends BasicModule implements SessionManager,
*/ */
private Random randomResource = new Random(); private Random randomResource = new Random();
private ModuleContext context;
public SessionManagerImpl() { public SessionManagerImpl() {
super("Session Manager"); super("Session Manager");
} }
...@@ -880,7 +878,7 @@ public class SessionManagerImpl extends BasicModule implements SessionManager, ...@@ -880,7 +878,7 @@ public class SessionManagerImpl extends BasicModule implements SessionManager,
public void setConflictKickLimit(int limit) { public void setConflictKickLimit(int limit) {
conflictLimit = limit; conflictLimit = limit;
context.setProperty("xmpp.session.conflict-limit", Integer.toString(conflictLimit)); JiveGlobals.setProperty("xmpp.session.conflict-limit", Integer.toString(conflictLimit));
} }
/** /**
...@@ -929,20 +927,19 @@ public class SessionManagerImpl extends BasicModule implements SessionManager, ...@@ -929,20 +927,19 @@ public class SessionManagerImpl extends BasicModule implements SessionManager,
} }
} }
public void initialize(ModuleContext context, Container container) { public void initialize(Container container) {
super.initialize(context, container); super.initialize(container);
this.context = context; if (JiveGlobals.getBooleanProperty("xmpp.audit.active")) {
if ("true".equals(context.getProperty("xmpp.audit.active"))) {
streamIDFactory = new AuditStreamIDFactory(); streamIDFactory = new AuditStreamIDFactory();
} }
else { else {
streamIDFactory = new BasicStreamIDFactory(); streamIDFactory = new BasicStreamIDFactory();
} }
String conflictLimitProp = context.getProperty("xmpp.session.conflict-limit"); String conflictLimitProp = JiveGlobals.getProperty("xmpp.session.conflict-limit");
if (conflictLimitProp == null) { if (conflictLimitProp == null) {
conflictLimit = 0; conflictLimit = 0;
context.setProperty("xmpp.session.conflict-limit", Integer.toString(conflictLimit)); JiveGlobals.setProperty("xmpp.session.conflict-limit", Integer.toString(conflictLimit));
} }
else { else {
try { try {
...@@ -950,7 +947,7 @@ public class SessionManagerImpl extends BasicModule implements SessionManager, ...@@ -950,7 +947,7 @@ public class SessionManagerImpl extends BasicModule implements SessionManager,
} }
catch (NumberFormatException e) { catch (NumberFormatException e) {
conflictLimit = 0; conflictLimit = 0;
context.setProperty("xmpp.session.conflict-limit", Integer.toString(conflictLimit)); JiveGlobals.setProperty("xmpp.session.conflict-limit", Integer.toString(conflictLimit));
} }
} }
} }
......
...@@ -10,9 +10,10 @@ ...@@ -10,9 +10,10 @@
*/ */
package org.jivesoftware.messenger.spi; package org.jivesoftware.messenger.spi;
import org.jivesoftware.messenger.container.ModuleContext;
import org.jivesoftware.util.Version; import org.jivesoftware.util.Version;
import org.jivesoftware.messenger.XMPPServerInfo; import org.jivesoftware.messenger.XMPPServerInfo;
import org.jivesoftware.messenger.JiveGlobals;
import java.util.Date; import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
...@@ -23,30 +24,25 @@ import java.util.Iterator; ...@@ -23,30 +24,25 @@ import java.util.Iterator;
* @author Iain Shigeoka * @author Iain Shigeoka
*/ */
public class XMPPServerInfoImpl implements XMPPServerInfo { public class XMPPServerInfoImpl implements XMPPServerInfo {
private Date startDate; private Date startDate;
private Date stopDate; private Date stopDate;
private String name; private String name;
private Version ver; private Version ver;
private Iterator ports; private Iterator ports;
private ModuleContext modContext;
/** /**
* Simple constructor * Simple constructor
* *
* @param context the context for the server.
* @param serverName The server's serverName (e.g. jivesoftware.com) * @param serverName The server's serverName (e.g. jivesoftware.com)
* @param version The server's version number * @param version The server's version number
* @param startDate The server's last start time (can be null indicating it hasn't been started) * @param startDate The server's last start time (can be null indicating it hasn't been started)
* @param stopDate The server's last stop time (can be null indicating it is running or hasn't been started) * @param stopDate The server's last stop time (can be null indicating it is running or hasn't been started)
* @param portIter The portIter active on the server * @param portIter The portIter active on the server
*/ */
public XMPPServerInfoImpl(ModuleContext context, public XMPPServerInfoImpl(String serverName, Version version, Date startDate, Date stopDate,
String serverName, Iterator portIter)
Version version, {
Date startDate,
Date stopDate,
Iterator portIter) {
modContext = context;
this.name = serverName; this.name = serverName;
this.ver = version; this.ver = version;
this.startDate = startDate; this.startDate = startDate;
...@@ -65,10 +61,10 @@ public class XMPPServerInfoImpl implements XMPPServerInfo { ...@@ -65,10 +61,10 @@ public class XMPPServerInfoImpl implements XMPPServerInfo {
public void setName(String serverName) { public void setName(String serverName) {
name = serverName; name = serverName;
if (serverName == null) { if (serverName == null) {
modContext.deleteProperty("xmpp.domain"); JiveGlobals.deleteProperty("xmpp.domain");
} }
else { else {
modContext.setProperty("xmpp.domain", serverName); JiveGlobals.setProperty("xmpp.domain", serverName);
} }
} }
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
package org.jivesoftware.messenger.spi; package org.jivesoftware.messenger.spi;
import org.jivesoftware.messenger.container.Container; import org.jivesoftware.messenger.container.Container;
import org.jivesoftware.messenger.container.ModuleContext;
import org.jivesoftware.messenger.Session; import org.jivesoftware.messenger.Session;
import org.jivesoftware.messenger.XMPPAddress; import org.jivesoftware.messenger.XMPPAddress;
import org.jivesoftware.messenger.XMPPServer; import org.jivesoftware.messenger.XMPPServer;
...@@ -68,8 +67,8 @@ public class XMPPServerProxy implements XMPPServer { ...@@ -68,8 +67,8 @@ public class XMPPServerProxy implements XMPPServer {
return server.getName(); return server.getName();
} }
public void initialize(ModuleContext context, Container container) { public void initialize(Container container) {
server.initialize(context, container); server.initialize(container);
} }
public void start() { public void start() {
......
...@@ -13,13 +13,12 @@ package org.jivesoftware.messenger.user.spi; ...@@ -13,13 +13,12 @@ package org.jivesoftware.messenger.user.spi;
import org.jivesoftware.database.DbConnectionManager; import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.messenger.container.BasicModule; import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.messenger.container.Container; import org.jivesoftware.messenger.container.Container;
import org.jivesoftware.messenger.container.ModuleContext;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.util.XPPReader; import org.jivesoftware.util.XPPReader;
import org.jivesoftware.messenger.PrivateStore; import org.jivesoftware.messenger.PrivateStore;
import org.jivesoftware.messenger.JiveGlobals;
import org.jivesoftware.messenger.auth.UnauthorizedException; import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.database.DbConnectionManager;
import java.io.StringReader; import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
...@@ -45,17 +44,20 @@ import org.dom4j.Element; ...@@ -45,17 +44,20 @@ import org.dom4j.Element;
*/ */
public class DbPrivateStore extends BasicModule implements PrivateStore { public class DbPrivateStore extends BasicModule implements PrivateStore {
private static final String LOAD_PRIVATE = "SELECT value FROM jivePrivate WHERE userID=? AND namespace=?"; private static final String LOAD_PRIVATE =
private static final String INSERT_PRIVATE = "INSERT INTO jivePrivate (value,name,userID,namespace) VALUES (?,?,?,?)"; "SELECT value FROM jivePrivate WHERE userID=? AND namespace=?";
private static final String UPDATE_PRIVATE = "UPDATE jivePrivate SET value=?, name=? WHERE userID=? AND namespace=?"; private static final String INSERT_PRIVATE =
"INSERT INTO jivePrivate (value,name,userID,namespace) VALUES (?,?,?,?)";
private static final String UPDATE_PRIVATE =
"UPDATE jivePrivate SET value=?, name=? WHERE userID=? AND namespace=?";
// currently no delete supported, we can detect an add of an empty element and use that to // currently no delete supported, we can detect an add of an empty element and use that to
// signal a delete but that optimization doesn't seem necessary. // signal a delete but that optimization doesn't seem necessary.
private static final String DELETE_PRIVATE = "DELETE FROM jivePrivate WHERE userID=? AND name=? AND namespace=?"; private static final String DELETE_PRIVATE =
"DELETE FROM jivePrivate WHERE userID=? AND name=? AND namespace=?";
// TODO: As with IQAuthHandler, this is not multi-server safe // TODO: As with IQAuthHandler, this is not multi-server safe
private static boolean enabled; private static boolean enabled;
private ModuleContext context;
public DbPrivateStore() { public DbPrivateStore() {
super("Private user data storage"); super("Private user data storage");
...@@ -67,7 +69,7 @@ public class DbPrivateStore extends BasicModule implements PrivateStore { ...@@ -67,7 +69,7 @@ public class DbPrivateStore extends BasicModule implements PrivateStore {
public void setEnabled(boolean enabled) { public void setEnabled(boolean enabled) {
DbPrivateStore.enabled = enabled; DbPrivateStore.enabled = enabled;
context.setProperty("xmpp.private", enabled ? "true" : "false"); JiveGlobals.setProperty("xmpp.private", Boolean.toString(enabled));
} }
public void add(long userID, Element data) throws UnauthorizedException { public void add(long userID, Element data) throws UnauthorizedException {
...@@ -160,9 +162,8 @@ public class DbPrivateStore extends BasicModule implements PrivateStore { ...@@ -160,9 +162,8 @@ public class DbPrivateStore extends BasicModule implements PrivateStore {
return data; return data;
} }
public void initialize(ModuleContext context, Container container) { public void initialize(Container container) {
super.initialize(context, container); super.initialize(container);
this.context = context; enabled = JiveGlobals.getBooleanProperty("xmpp.private");
enabled = "true".equals(context.getProperty("xmpp.private"));
} }
} }
\ No newline at end of file
...@@ -12,7 +12,6 @@ package org.jivesoftware.messenger.user.spi; ...@@ -12,7 +12,6 @@ package org.jivesoftware.messenger.user.spi;
import org.jivesoftware.messenger.container.BasicModule; import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.messenger.container.Container; import org.jivesoftware.messenger.container.Container;
import org.jivesoftware.messenger.container.ModuleContext;
import org.jivesoftware.messenger.container.TrackInfo; import org.jivesoftware.messenger.container.TrackInfo;
import org.jivesoftware.messenger.*; import org.jivesoftware.messenger.*;
import org.jivesoftware.messenger.auth.UnauthorizedException; import org.jivesoftware.messenger.auth.UnauthorizedException;
...@@ -31,7 +30,6 @@ public class OfflineMessageStrategyImpl extends BasicModule implements OfflineMe ...@@ -31,7 +30,6 @@ public class OfflineMessageStrategyImpl extends BasicModule implements OfflineMe
private static int quota = -1; private static int quota = -1;
private static Type type = Type.store; private static Type type = Type.store;
private ModuleContext context;
public int getQuota() { public int getQuota() {
return quota; return quota;
...@@ -39,7 +37,7 @@ public class OfflineMessageStrategyImpl extends BasicModule implements OfflineMe ...@@ -39,7 +37,7 @@ public class OfflineMessageStrategyImpl extends BasicModule implements OfflineMe
public void setQuota(int quota) { public void setQuota(int quota) {
OfflineMessageStrategyImpl.quota = quota; OfflineMessageStrategyImpl.quota = quota;
context.setProperty("xmpp.offline.quota", Integer.toString(quota)); JiveGlobals.setProperty("xmpp.offline.quota", Integer.toString(quota));
} }
public OfflineMessageStrategy.Type getType() { public OfflineMessageStrategy.Type getType() {
...@@ -51,7 +49,7 @@ public class OfflineMessageStrategyImpl extends BasicModule implements OfflineMe ...@@ -51,7 +49,7 @@ public class OfflineMessageStrategyImpl extends BasicModule implements OfflineMe
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
OfflineMessageStrategyImpl.type = type; OfflineMessageStrategyImpl.type = type;
context.setProperty("xmpp.offline.type", type.toString()); JiveGlobals.setProperty("xmpp.offline.type", type.toString());
} }
public void storeOffline(Message message) throws UnauthorizedException, UserNotFoundException { public void storeOffline(Message message) throws UnauthorizedException, UserNotFoundException {
...@@ -94,14 +92,13 @@ public class OfflineMessageStrategyImpl extends BasicModule implements OfflineMe ...@@ -94,14 +92,13 @@ public class OfflineMessageStrategyImpl extends BasicModule implements OfflineMe
messageStore.addMessage(message); messageStore.addMessage(message);
} }
public void initialize(ModuleContext context, Container container) { public void initialize(Container container) {
super.initialize(context, container); super.initialize(container);
this.context = context; String quota = JiveGlobals.getProperty("xmpp.offline.quota");
String quota = context.getProperty("xmpp.offline.quota");
if (quota != null && quota.length() > 0) { if (quota != null && quota.length() > 0) {
OfflineMessageStrategyImpl.quota = Integer.parseInt(quota); OfflineMessageStrategyImpl.quota = Integer.parseInt(quota);
} }
String type = context.getProperty("xmpp.offline.type"); String type = JiveGlobals.getProperty("xmpp.offline.type");
if (type != null && type.length() > 0) { if (type != null && type.length() > 0) {
OfflineMessageStrategyImpl.type = Type.valueOf(type); OfflineMessageStrategyImpl.type = Type.valueOf(type);
} }
......
...@@ -14,9 +14,7 @@ import org.jivesoftware.util.Cache; ...@@ -14,9 +14,7 @@ import org.jivesoftware.util.Cache;
import org.jivesoftware.util.CacheManager; import org.jivesoftware.util.CacheManager;
import org.jivesoftware.messenger.container.BasicModule; import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.messenger.container.Container; import org.jivesoftware.messenger.container.Container;
import org.jivesoftware.messenger.container.ModuleContext;
import org.jivesoftware.util.StringUtils; import org.jivesoftware.util.StringUtils;
import org.jivesoftware.util.CacheManager;
import org.jivesoftware.messenger.NodePrep; import org.jivesoftware.messenger.NodePrep;
import org.jivesoftware.messenger.auth.UnauthorizedException; import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.user.*; import org.jivesoftware.messenger.user.*;
...@@ -51,10 +49,10 @@ public class UserManagerImpl extends BasicModule implements UserManager { ...@@ -51,10 +49,10 @@ public class UserManagerImpl extends BasicModule implements UserManager {
super("User Manager"); super("User Manager");
} }
private void initializeCaches(ModuleContext context) { private void initializeCaches() {
CacheManager.initializeCache("username2userid", 128 * 1024, context); // 1/8 MB CacheManager.initializeCache("username2userid", 128 * 1024); // 1/8 MB
CacheManager.initializeCache("userid2user", 521 * 1024, context); // 1/2 MB CacheManager.initializeCache("userid2user", 521 * 1024); // 1/2 MB
CacheManager.initializeCache("userid2roster", 521 * 1024, context); // 1/2 MB CacheManager.initializeCache("userid2roster", 521 * 1024); // 1/2 MB
id2userCache = CacheManager.getCache("userid2user"); id2userCache = CacheManager.getCache("userid2user");
name2idCache = CacheManager.getCache("username2userid"); name2idCache = CacheManager.getCache("username2userid");
...@@ -167,8 +165,8 @@ public class UserManagerImpl extends BasicModule implements UserManager { ...@@ -167,8 +165,8 @@ public class UserManagerImpl extends BasicModule implements UserManager {
// Module management // Module management
// ##################################################################### // #####################################################################
public void initialize(ModuleContext context, Container container) { public void initialize(Container container) {
super.initialize(context, container); super.initialize(container);
initializeCaches(context); initializeCaches();
} }
} }
\ No newline at end of file
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
package org.jivesoftware.messenger.user.spi; package org.jivesoftware.messenger.user.spi;
import org.jivesoftware.messenger.container.Container; import org.jivesoftware.messenger.container.Container;
import org.jivesoftware.messenger.container.ModuleContext;
import org.jivesoftware.util.JiveConstants; import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.messenger.auth.AuthToken; import org.jivesoftware.messenger.auth.AuthToken;
import org.jivesoftware.messenger.auth.Permissions; import org.jivesoftware.messenger.auth.Permissions;
...@@ -105,8 +104,8 @@ public class UserManagerProxy implements UserManager { ...@@ -105,8 +104,8 @@ public class UserManagerProxy implements UserManager {
return null; return null;
} }
public void initialize(ModuleContext context, Container container) { public void initialize(Container container) {
userManager.initialize(context, container); userManager.initialize(container);
} }
public void start() { public void start() {
......
...@@ -16,19 +16,18 @@ import org.jivesoftware.net.policies.BasicAcceptPolicy; ...@@ -16,19 +16,18 @@ import org.jivesoftware.net.policies.BasicAcceptPolicy;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.Iterator; import java.util.*;
import java.util.LinkedList;
import org.jivesoftware.net.AcceptManager; import org.jivesoftware.net.AcceptManager;
import org.jivesoftware.net.AcceptPort; import org.jivesoftware.net.AcceptPort;
import org.jivesoftware.net.*; import org.jivesoftware.net.*;
import org.jivesoftware.messenger.container.*; import org.jivesoftware.messenger.container.*;
import org.jivesoftware.messenger.JiveGlobals;
import org.jivesoftware.util.*; import org.jivesoftware.util.*;
public class AcceptManagerImpl extends BasicModule implements AcceptManager { public class AcceptManagerImpl extends BasicModule implements AcceptManager {
private ModuleContext context; private List<AcceptPort> ports = new ArrayList<AcceptPort>();
private LinkedList ports = new LinkedList();
private AcceptPolicy policy = new BasicAcceptPolicy(true); private AcceptPolicy policy = new BasicAcceptPolicy(true);
private ConnectionManager connManager; private ConnectionManager connManager;
...@@ -87,14 +86,20 @@ public class AcceptManagerImpl extends BasicModule implements AcceptManager { ...@@ -87,14 +86,20 @@ public class AcceptManagerImpl extends BasicModule implements AcceptManager {
throw new AlreadyExistsException(portAddress.toString()); throw new AlreadyExistsException(portAddress.toString());
} }
} }
return new AcceptPortImpl(context.createChildProperty("accept.port"), AcceptPort acceptPort = new AcceptPortImpl("port" + ports.size(),
connManager, connManager, portAddress);
portAddress); ports.add(acceptPort);
return acceptPort;
} }
public void deleteAcceptPort(AcceptPort acceptPort) { public void deleteAcceptPort(AcceptPort acceptPort) {
ports.remove(acceptPort); ports.remove(acceptPort);
// TODO: save remaining ports
JiveGlobals.deleteProperty("acceptPorts");
for (int i=0; i<ports.size(); i++) {
((AcceptPortImpl)ports.get(i)).setContext("acceptPorts.port" + i);
((AcceptPortImpl)ports.get(i)).savePort();
}
try { try {
acceptPort.close(); acceptPort.close();
...@@ -109,18 +114,15 @@ public class AcceptManagerImpl extends BasicModule implements AcceptManager { ...@@ -109,18 +114,15 @@ public class AcceptManagerImpl extends BasicModule implements AcceptManager {
return trackInfo; return trackInfo;
} }
public void initialize(ModuleContext context, Container container) { public void initialize(Container container) {
super.initialize(context, container); super.initialize(container);
this.context = context;
} }
protected void serviceAdded(Object service) { protected void serviceAdded(Object service) {
if (service instanceof ConnectionManager){ if (service instanceof ConnectionManager){
connManager = (ConnectionManager) service; connManager = (ConnectionManager) service;
Iterator portIter = context.getChildProperties("portIter.port"); for (String propName : JiveGlobals.getProperties("acceptPorts")) {
while (portIter.hasNext()){ AcceptPort port = new AcceptPortImpl(propName, connManager);
AcceptPort port = new AcceptPortImpl((ModuleProperties) portIter.next(),
connManager);
ports.add(port); ports.add(port);
} }
} }
......
...@@ -18,12 +18,12 @@ import java.net.InetSocketAddress; ...@@ -18,12 +18,12 @@ import java.net.InetSocketAddress;
import java.nio.channels.*; import java.nio.channels.*;
import org.jivesoftware.net.*; import org.jivesoftware.net.*;
import org.jivesoftware.messenger.container.ModuleProperties; import org.jivesoftware.messenger.JiveGlobals;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
public class AcceptPortImpl implements AcceptPort { public class AcceptPortImpl implements AcceptPort {
private ModuleProperties properties; private String context;
private InetSocketAddress address; private InetSocketAddress address;
private boolean secure; private boolean secure;
private AcceptPolicy policy = new BasicAcceptPolicy(true); private AcceptPolicy policy = new BasicAcceptPolicy(true);
...@@ -34,23 +34,27 @@ public class AcceptPortImpl implements AcceptPort { ...@@ -34,23 +34,27 @@ public class AcceptPortImpl implements AcceptPort {
private AcceptThread acceptThread = null; private AcceptThread acceptThread = null;
private ConnectionManager conManager; private ConnectionManager conManager;
public AcceptPortImpl(ModuleProperties props, ConnectionManager connectionManager) { public AcceptPortImpl(String context, ConnectionManager connectionManager) {
properties = props; this.context = context;
conManager = connectionManager; conManager = connectionManager;
String hostname = properties.getProperty("port.hostname"); String hostname = JiveGlobals.getProperty(context + ".hostname");
String port = properties.getProperty("port.portnumber"); String port = JiveGlobals.getProperty(".portnumber");
address = new InetSocketAddress(hostname,Integer.parseInt(port)); address = new InetSocketAddress(hostname,Integer.parseInt(port));
} }
public AcceptPortImpl(ModuleProperties props, public AcceptPortImpl(String context, ConnectionManager connectionManager,
ConnectionManager connectionManager, InetSocketAddress bindAddress)
InetSocketAddress bindAddress) { {
properties = props; this.context = context;
conManager = connectionManager; conManager = connectionManager;
address = bindAddress; address = bindAddress;
savePort(); savePort();
} }
public void setContext(String context) {
this.context = context;
}
public boolean isSecure() { public boolean isSecure() {
return secure; return secure;
} }
...@@ -95,9 +99,7 @@ public class AcceptPortImpl implements AcceptPort { ...@@ -95,9 +99,7 @@ public class AcceptPortImpl implements AcceptPort {
} }
public void remove() throws IOException { public void remove() throws IOException {
if (properties != null){ JiveGlobals.deleteProperty(context);
properties.deleteProperty("port");
}
if (startTime > 0){ if (startTime > 0){
close(); close();
} }
...@@ -119,10 +121,10 @@ public class AcceptPortImpl implements AcceptPort { ...@@ -119,10 +121,10 @@ public class AcceptPortImpl implements AcceptPort {
return disconnectMonitor; return disconnectMonitor;
} }
private void savePort(){ public void savePort(){
if (properties != null && address != null){ if (address != null){
properties.setProperty("port.hostname",address.getHostName()); JiveGlobals.setProperty(context + ".hostname",address.getHostName());
properties.setProperty("port.portnumber",Integer.toString(address.getPort())); JiveGlobals.setProperty(context + ".portnumber",Integer.toString(address.getPort()));
} }
} }
...@@ -147,18 +149,22 @@ public class AcceptPortImpl implements AcceptPort { ...@@ -147,18 +149,22 @@ public class AcceptPortImpl implements AcceptPort {
SocketChannel socket = server.accept(); SocketChannel socket = server.accept();
Connection conn = new SocketChannelConnection(socket); Connection conn = new SocketChannelConnection(socket);
acceptMonitor.addSample(conn); acceptMonitor.addSample(conn);
if (policy.evaluate(conn)){ if (policy.evaluate(conn)) {
conManager.addConnection(conn); conManager.addConnection(conn);
connectMonitor.addSample(conn); connectMonitor.addSample(conn);
} else { }
else {
disconnectMonitor.addSample(conn); disconnectMonitor.addSample(conn);
} }
} catch (ClosedChannelException ce){ }
catch (ClosedChannelException ce){
startTime = -1; startTime = -1;
running = false; running = false;
} catch (NotYetBoundException ce){ }
catch (NotYetBoundException ce){
throw new IllegalStateException("Must init thread before running"); throw new IllegalStateException("Must init thread before running");
} catch (IOException e) { }
catch (IOException e) {
Log.error(e); Log.error(e);
} }
} }
...@@ -169,7 +175,8 @@ public class AcceptPortImpl implements AcceptPort { ...@@ -169,7 +175,8 @@ public class AcceptPortImpl implements AcceptPort {
startTime = -1; startTime = -1;
try { try {
server.close(); server.close();
} catch (IOException e) { }
catch (IOException e) {
// //
} }
} }
......
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
*/ */
package org.jivesoftware.util; package org.jivesoftware.util;
import org.jivesoftware.messenger.container.ModuleContext; import org.jivesoftware.messenger.JiveGlobals;
import java.util.Hashtable; import java.util.*;
/** /**
* A centralized, JVM static manager of Jive caches. Caches are essential for * A centralized, JVM static manager of Jive caches. Caches are essential for
...@@ -22,7 +22,7 @@ import java.util.Hashtable; ...@@ -22,7 +22,7 @@ import java.util.Hashtable;
*/ */
public class CacheManager { public class CacheManager {
private static Hashtable caches = new Hashtable(); private static Map caches = new HashMap();
private static long maxLifetime = JiveConstants.HOUR * 6; private static long maxLifetime = JiveConstants.HOUR * 6;
/** /**
...@@ -35,21 +35,13 @@ public class CacheManager { ...@@ -35,21 +35,13 @@ public class CacheManager {
* The property names should be "cache.name.size" where 'name' will be the same as the cache name. * The property names should be "cache.name.size" where 'name' will be the same as the cache name.
* If the property exists, that value will be used instead of the defaultMaxCacheSize.</p> * If the property exists, that value will be used instead of the defaultMaxCacheSize.</p>
* *
* @param name the name of the cache to create. * @param name the name of the cache to create.
* @param defaultMaxCacheSize The default max size the cache can grow to, in bytes. * @param defaultMaxCacheSize the default max size the cache can grow to, in bytes.
*/ */
public static void initializeCache(String name, int defaultMaxCacheSize, ModuleContext context) { public static void initializeCache(String name, int defaultMaxCacheSize) {
Cache cache = (Cache)caches.get(name); Cache cache = (Cache)caches.get(name);
if (cache == null) { if (cache == null) {
String cacheSize = context.getProperty("cache." + name + ".size"); int maxCacheSize = JiveGlobals.getIntProperty("cache." + name + ".size", defaultMaxCacheSize);
int maxCacheSize = defaultMaxCacheSize;
if (cacheSize != null) {
try {
maxCacheSize = Integer.parseInt(cacheSize);
}
catch (NumberFormatException e) { /* ignore */
}
}
caches.put(name, new Cache(name, maxCacheSize, maxLifetime)); caches.put(name, new Cache(name, maxCacheSize, maxLifetime));
} }
} }
...@@ -63,4 +55,4 @@ public class CacheManager { ...@@ -63,4 +55,4 @@ public class CacheManager {
public static Cache getCache(String name) { public static Cache getCache(String name) {
return (Cache)caches.get(name); return (Cache)caches.get(name);
} }
} }
\ No newline at end of file
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