Commit f03f57a9 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Refactoring to remove trackinfo logic.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@626 b35dd754-fafc-0310-a699-88a17e54d16e
parent 75a9411e
......@@ -14,8 +14,7 @@ package org.jivesoftware.admin;
import org.jivesoftware.util.ClassUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.messenger.XMPPServer;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.container.ServiceLookupFactory;
import org.jivesoftware.messenger.spi.BasicServer;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.DocumentFactory;
......@@ -135,15 +134,8 @@ public class AdminConsole {
}
else {
// Default to the Jive Messenger version if none has been provided via XML.
try {
XMPPServer xmppServer = (XMPPServer)ServiceLookupFactory.getLookup().lookup(
XMPPServer.class);
return xmppServer.getServerInfo().getVersion().getVersionString();
}
catch (UnauthorizedException ue) {
Log.error(ue);
return null;
}
XMPPServer xmppServer = BasicServer.getInstance();
return xmppServer.getServerInfo().getVersion().getVersionString();
}
}
......
......@@ -2,10 +2,7 @@ package org.jivesoftware.messenger;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.container.ServiceLookupFactory;
import org.jivesoftware.messenger.spi.PacketRouterImpl;
import org.jivesoftware.util.Log;
import org.jivesoftware.messenger.spi.BasicServer;
import org.jivesoftware.util.StringUtils;
import org.xmpp.packet.Packet;
import org.xmpp.packet.JID;
......@@ -116,14 +113,9 @@ public class ComponentManager {
*/
public void sendPacket(Packet packet) {
PacketRouter router;
try {
router = (PacketRouterImpl)ServiceLookupFactory.getLookup().lookup(PacketRouterImpl.class);
if (router != null) {
router.route(packet);
}
}
catch (UnauthorizedException e) {
Log.error(e);
router = BasicServer.getInstance().getPacketRouter();
if (router != null) {
router.route(packet);
}
}
......
......@@ -15,6 +15,7 @@ import org.jivesoftware.database.SequenceManager;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.util.*;
import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.messenger.spi.BasicServer;
import org.xmpp.packet.Message;
import org.dom4j.io.SAXReader;
import org.dom4j.DocumentFactory;
......@@ -44,15 +45,13 @@ public class OfflineMessageStore extends BasicModule {
private static final String DELETE_OFFLINE =
"DELETE FROM jiveOffline WHERE username=?";
private static OfflineMessageStore instance;
/**
* Returns a singleton instance of OfflineMessageStore.
* Returns the instance of <CODE>OfflineMessageStore</CODE> being used by the XMPPServer.
*
* @return an instance.
* @return the instance of <CODE>OfflineMessageStore</CODE> being used by the XMPPServer.
*/
public static OfflineMessageStore getInstance() {
return instance;
return BasicServer.getInstance().getOfflineMessageStore();
}
private SAXReader saxReader = new SAXReader();
......@@ -60,7 +59,6 @@ public class OfflineMessageStore extends BasicModule {
public OfflineMessageStore() {
super("Offline Message Store");
instance = this;
}
/**
......
......@@ -30,6 +30,7 @@ import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.messenger.spi.BasicStreamIDFactory;
import org.jivesoftware.messenger.spi.SessionImpl;
import org.jivesoftware.messenger.spi.BasicServer;
import org.jivesoftware.messenger.user.UserManager;
import org.jivesoftware.messenger.user.UserNotFoundException;
import org.jivesoftware.util.LocaleUtils;
......@@ -58,37 +59,17 @@ public class SessionManager extends BasicModule implements ConnectionCloseListen
private int conflictLimit;
private Random randomResource = new Random();
private static SessionManager singleton;
private static final Object LOCK = new Object();
/**
* Returns the singleton instance of <CODE>SessionManagerImpl</CODE>,
* <p/>
* creating it if necessary.
* <p/>
* <p/>
* Returns the instance of <CODE>SessionManagerImpl</CODE> being used by the XMPPServer.
*
* @return the singleton instance of <Code>SessionManagerImpl</CODE>
* @return the instance of <CODE>SessionManagerImpl</CODE> being used by the XMPPServer.
*/
public static SessionManager getInstance() {
// Synchronize on LOCK to ensure that we don't end up creating
// two singletons.
synchronized (LOCK) {
if (null == singleton) {
SessionManager manager = new SessionManager();
singleton = manager;
return manager;
}
}
return singleton;
return BasicServer.getInstance().getSessionManager();
}
public SessionManager() {
super("Session Manager");
if (singleton != null) {
throw new IllegalStateException();
}
singleton = this;
if (JiveGlobals.getBooleanProperty("xmpp.audit.active")) {
streamIDFactory = new AuditStreamIDFactory();
}
......
......@@ -23,6 +23,7 @@ import org.jivesoftware.messenger.audit.AuditManager;
import org.jivesoftware.messenger.disco.ServerFeaturesProvider;
import org.jivesoftware.messenger.disco.ServerItemsProvider;
import org.jivesoftware.messenger.disco.IQDiscoInfoHandler;
import org.jivesoftware.messenger.muc.MultiUserChatServer;
import java.util.List;
......@@ -65,6 +66,8 @@ public interface XMPPServer {
*/
public JID createJID(String username, String resource);
public boolean isSetupMode();
public ConnectionManager getConnectionManager();
public RoutingTable getRoutingTable();
......@@ -110,4 +113,6 @@ public interface XMPPServer {
public IQDiscoInfoHandler getIQDiscoInfoHandler();
public PrivateStorage getPrivateStorage();
public MultiUserChatServer getMultiUserChatServer();
}
......@@ -14,40 +14,10 @@ package org.jivesoftware.messenger.container;
import org.jivesoftware.messenger.XMPPServer;
/**
* <p>A skeleton Module implementation that takes care of the most
* common Module housekeeping chores.</p>
* <p>The basic module manages the lookup registration for the
* service but requires a small amount of help. In order to know
* what services should be registered, the basic module will go
* through the following during start()</p>
* <ul>
* <li>Call getServices(). If the result is not null, all services
* in the list are registered.</li>
* <li>Call getService(). If the result is not null, the service
* is registered.</li>
* <li>Call getServiceItemss(). If the result is not null, all service items
* in the list are registered.</li>
* <li>Call getServiceItem(). If the result is not null, the service item
* is registered.</li>
* </ul>
* <p>It is critical that inheriting classes overriding the module
* lifecycle methods call the parent life cycle
* methods in order to ensure these housekeeping tasks occur.</p>
* <p/>
* <h2>Tracker</h2>
* <p>The basic module can manage a ServiceTracker for inheriting classes. To
* use the built-in tracker, you must do the following:</p>
* <ol>
* <li>Override getTrackInfo() - and return an array of classes that you want
* the service tracker to track.</li>
* <li>Override addService() and removeService() - to receive services that are
* being added or removed from the lookup. It is important to react to both.
* Removal should result in the removal of any references to the service object
* so the garbage collector can clean up the service. It is also dangerous
* (e.g. throw NPE) to use services that have been removed from the lookup.</li>
* </ol>
* A default Module implementation that basically avoids subclasses having to implement the whole
* Module interface.</p>
*
* @author Iain Shigeoka
* @author Gaston Dombiak
*/
public class BasicModule implements Module {
......
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.container;
import org.jivesoftware.messenger.auth.UnauthorizedException;
/**
* Acts as a centralized coordinator of JVM-wide resources in the container.
* Components may directly access the container resources using the
* methods and resulting resource controllers. The container is passed to
* the module in it's initialize method.
*
* @author Iain Shigeoka
*/
public interface Container {
/**
* <p>Obtain the setup mode status of the container.</p>
* <p>If the container is in setup mode, return true. This is set to
* true if the jive property "setup" is not set to true. The property
* indicates that setup has already occured, while this method reports
* the setup status (true, you're in setup mode). Setup code should
* set the jive property "setup" to "true" by using the container's
* module context Container.getModuleContext().</p>
*
* @return True if the container is in setup mode
*/
boolean isSetupMode();
/**
* <p>Flag indicating if the container was started in stand alone mode.
* If the container is in stand alone mode, return true. Stand alone
* containers may be stopped.</p>
*
* @return True if the container is in stand alone mode
*/
boolean isStandAlone();
/**
* <p>Flag indicating if the container can be restarted.
* The container is restartable only if it is stand alone and
* a service wrapper deployment was used.</p>
*
* @return True if the container can be restarted
*/
boolean isRestartable();
/**
* Obtain the service lookup for the server. The service lookup may
* contain remote services. You should use the localServerAttribute to
* locate services that are known to be local to the server.
*
* @return The service lookup for finding and posting service items
* @throws UnauthorizedException If the caller does not have permission to
* access this resource
*/
ServiceLookup getServiceLookup() throws UnauthorizedException;
/**
* <p/>
* The container will attempt to start the given service if support
* classes can be found.
* </p>
* <p/>
* A container may not know about the requested service so
* callers should be prepared for a null return. The call blocks
* during service initializiation and startup so there may
* be some delays during the method call.
* </p>
*
* @param service The service to be started
* @return The service instance or null if one could not be started
* @throws UnauthorizedException If the caller does not have permission to
* access this resource
*/
Object startService(Class service) throws UnauthorizedException;
/**
* <p/>
* The container will attempt to stop the all matching services in
* the container.
* </p>
* <p/>
* A container may not know about the requested service or it may
* refuse to stop the service even if an authorized exception
* is not thrown. The call blocks during service shutdon so there may
* be some delays during the method call. In many cases, stopping a service
* will initiate the service stopping, but complete shutdown of the service
* may occur later on a separate thread (for example while waiting for
* transactions in progress to commit). It is not safe to assume that
* a successful return from this method means the service has finished
* shutting down.
* </p>
*
* @param service The service to be stopped
* @throws UnauthorizedException If the caller does not have permission
* to access this resource
*/
void stopService(Class service) throws UnauthorizedException;
/**
* Obtain a special entry that modules can use to locate or register local services in
* the service registrar.
* <p/>
* To help modules locate other modules, a Jini service registrar is
* provided. An entry is also given to narrow service
* search for modules that are in the local JVM.
* If your module needs to register itself with the registrar, it should
* add the local attribute entry to it's entry sets.
* </p>
*
* @return An Entry attribute used to mark local services/modules
* @throws UnauthorizedException
*/
Entry getLocalServerAttribute() throws UnauthorizedException;
/**
* <p>Stops the container and all hosted services.</p>
* <p>In standalone mode, this also shuts down the server VM.
* For app server deployments nothing happens.</p>
*
* @throws UnauthorizedException
*/
void stop() throws UnauthorizedException;
/**
* <p>Restarts the container and all it's hosted services. If the
* container is not restartable, this method does nothing.</p>
*
* @throws UnauthorizedException
*/
void restart() throws UnauthorizedException;
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.container;
import java.io.Serializable;
/**
* A portable data object used to conduct server searches and for
* temporary data storage in a Jive container. Entries must have
* a no-arg constructor. All fields must be a public Object (no
* primitives or private fields allowed). This allows quicker searching
* and comparisons of Entry objects. Entry objects that don't comply
* with these rules will cause an UnusableEntryException to be thrown
* by most services.
*
* @author Iain Shigeoka
*/
public interface Entry extends Serializable {
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.container;
import java.io.Serializable;
import java.util.EventObject;
/**
* Extends the standard Java event object for sequence ordering and payload
* delivery. Events are used to deliver data between services in a generic
* way. Event payloads should be serializable for transportation to
* services on other machines.
* <p/>
* The event ID identifies the event type. The combination
* of event type and source object determines a unique event type.
* All events of a type should identify an identical event within
* the context of the source object.
* </p><p>
* The sequence number is provided as a hint for ordering events in the system.
* Increasing sequence numbers indicate events occuring later in time.
* e.g. If event x has a higher sequence number than event y and both events
* share the same source object and event ID, then x occured after y.
* Services that don't want to transmit sequence information should send
* all events with the same sequence number.
* </p><p>
* Some services may have a stronger guarantee that sequence numbers are
* sequential without any missing or repeated sequence numbers. This
* guarantee can be used to detect missed or repeated events but is not
* a requirement of all event generators.
* </p>
*
* @author Iain Shigeoka
*/
public class Event extends EventObject {
/**
* the event id
*/
private long id;
/**
* The sequence number for the event
*/
private long sequenceNumber;
/**
* The payload for this event, may be null
*/
private Serializable payload;
/**
* Create a Jive event.
*
* @param source The source object that generated this event
* @param eventID The event identifier relative to the source object
* @param seqNumber The sequence number for this event
* @param payloadObject The payload for this event
* (may be null if not needed for event)
*/
public Event(Object source,
long eventID,
long seqNumber,
Serializable payloadObject) {
super(source);
this.id = eventID;
this.sequenceNumber = seqNumber;
this.payload = payloadObject;
}
/**
* Obtain the event id for this event.
*
* @return The event identifier
*/
public long getID() {
return id;
}
/**
* Obtain the sequence number for this event.
*
* @return The sequence number
*/
public long getSequenceNumber() {
return sequenceNumber;
}
/**
* Obtain the payload for this event.
*
* @return The payload for the event (may be null)
*/
public Serializable getPayload() {
return payload;
}
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.container;
/**
* Interface for objects interested in receiving Jive events.
*
* @author Iain Shigeoka
*/
public interface EventListener {
/**
* This method will be called with event notifications. Throw
* an UnknownEventException if you no longer want to receive
* events of the type sent in the current notification.
*
* @param e The event causing the notification
* @throws UnknownEventException Thrown if you no longer wish to receive events of this type
*/
void notifyEvent(Event e) throws UnknownEventException;
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.container;
import java.io.Serializable;
/**
* A class that groups all the information needed to manage an event
* listener registration.
*
* @author Iain Shigeoka
*/
public abstract class EventRegistration implements Serializable {
private long eventID;
private long seqNumber;
private Object sourceObject;
/**
* Serializable id. Increment whenever class signature changes.
*/
private static final long serialVersionUID = 1;
/**
* Constructor
*
* @param id The event ID for events associated with this registration
* @param source The source of the registration (the lookup)
* @param sequenceNumber The current sequence number when registering
*/
public EventRegistration(long id, Object source, long sequenceNumber) {
eventID = id;
this.sourceObject = source;
this.seqNumber = sequenceNumber;
}
/**
* Obtain the event ID that will be used with all events
* generated using this registration.
*
* @return The event id for all events from this registration
*/
public long getID() {
return eventID;
}
/**
* The sequence number current at the time of registration. Useful
* for tracking future event notifications relative to the registration.
*
* @return The sequence number current at time of registration
*/
public long getSequenceNumber() {
return seqNumber;
}
/**
* The source object that will be used for all events from this registration.
*
* @return The source object for events coming from this registration
*/
public Object getSource() {
return sourceObject;
}
/**
* Cancels the event registration.
*/
public abstract void cancel();
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.container;
import java.io.Serializable;
/**
* Special events sent by service lookup to registered listeners to notifyEvent of
* service registration changes. The extra information covers the service
* that caused the change, and the transition that occured. Sequence numbers
* are guaranteed to be sequential and increasing. Missing sequence numbers
* indicate an event may have been missed (missing numbers may also indicate
* that a remote server has crashed and recovered).
*
* @author Iain Shigeoka
*/
public class ServiceEvent extends Event {
private int transition;
private ServiceID serviceID;
private ServiceItem item;
/**
* Create a service event.
*
* @param source the event source (service lookup).
* @param eventID the event type.
* @param sequenceNumber the sequence number.
* @param payload the payload for the event.
* @param id the id of the server that caused the event.
* @param serviceItem the state of the service that caused the event.
* @param eventTransition the transition that triggered the event.
*/
public ServiceEvent(Object source, long eventID, long sequenceNumber,
Serializable payload, ServiceItem serviceItem, ServiceID id, int eventTransition)
{
super(source, eventID, sequenceNumber, payload);
this.transition = eventTransition;
this.serviceID = id;
this.item = serviceItem;
}
/**
* Returns the transition that caused the event.
*
* @return The transition that caused the event
*/
public int getTransition() {
return transition;
}
/**
* Returns the service id of the service that caused the event.
*
* @return The service id of the service that caused the event.
*/
public ServiceID getServiceID() {
return serviceID;
}
/**
* Returns the state of the item that caused the event.
*
* @return The state of the item that caused the event.
*/
public ServiceItem getServiceItem() {
return item;
}
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.container;
import java.io.Serializable;
import java.util.Random;
/**
* A globally unique identifier of services. Service IDs should be generated
* by the ServiceLookup (and found in the ServiceRegistration) and not by clients.
*
* @author Iain Shigeoka
*/
public class ServiceID implements Serializable {
private static final Random RANDOM_GENERATOR = new Random();
// mimic Jini UUID
private long highLong;
private long lowLong;
private String asString = null;
/**
* Serializable id. Increment whenever class signature changes.
*/
private static final long serialVersionUID = 1;
/**
* A weak implementation. Should move to a true unique ID soon.
*/
public ServiceID() {
highLong = RANDOM_GENERATOR.nextLong();
lowLong = RANDOM_GENERATOR.nextLong();
}
/**
* Create a copy of the given id
*
* @param id The object to copy
*/
public ServiceID(ServiceID id) {
highLong = id.highLong;
lowLong = id.lowLong;
}
/**
* <p>Conducts a comparison of service IDs only.</p>
*
* @param o The service ID to compare
* @return True if they are equal
*/
public boolean equals(Object o) {
boolean eq = false;
if (o instanceof ServiceID) {
ServiceID id = (ServiceID)o;
if (id.highLong == highLong && id.lowLong == lowLong) {
eq = true;
}
}
return eq;
}
/**
* <p>Generate a pseudo hash code based on the number.</p>
*
* @return A semi-unique hashcode for the item
*/
public int hashCode() {
return toString().hashCode();
}
/**
* <p>A string representation of the id.</p>
*
* @return The service id as a string
*/
public String toString() {
if (asString == null) {
asString = Long.toHexString(highLong) + "-" + Long.toHexString(lowLong);
}
return asString;
}
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.container;
import java.io.Serializable;
/**
* Represents a service registered in a lookup. See ServiceTemplate
* and ServiceLookup for how it is used.
*
* @author Iain Shigeoka
*/
public class ServiceItem implements Serializable {
/**
* The atributes associated with the item or null for wildcard
*/
public Entry[] attributes = null;
/**
* The service associated with the item or null for wildcard
*/
public Object service = null;
/**
* The service ID associated with the item or null for wildcard
*/
public ServiceID serviceID = null;
/**
* Serializable id. Increment whenever class signature changes.
*/
private static final long serialVersionUID = 1;
/**
* <p>Create an empty service item.</p>
*/
public ServiceItem() {
}
/**
* <p>Create a serviceObject item.</p>
*
* @param id The serviceObject ID for the serviceObject or null for wildcard
* @param serviceObject The serviceObject object or null to set it later
* @param atts The atts for the serviceObject or null for wildcard
*/
public ServiceItem(ServiceID id, Object serviceObject, Entry[] atts) {
this.serviceID = id;
this.service = serviceObject;
this.attributes = atts;
}
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.container;
/**
* <p>Allows a generic method of finding container services.</p>
* <p>A service is any
* Java object that has registered itself with the lookup including the
* container itself. The lookup and AuthFactory are the only static singletons
* in the system allowing any object in the JVM to locate Jive related objects.
* </p>
*
* @author Iain Shigeoka
*/
public interface ServiceLookup {
/**
* Indicates a transition that occurs when a service matches the lookup
* template before and after a change. Typically indicates an attribute
* change to an existing service.
*/
final int TRANSITION_MATCH_MATCH = 1;
/**
* <p>Indicates a transition that occurs when a service matches the lookup
* template before and does not match after a change.</p>
* <p/>
* Typically indicates a watched service is no longer in the lookup.</p>
*/
final int TRANSITION_MATCH_NOMATCH = 2;
/**
* <p>Indicates a transition that occurs when a service does not
* match the lookup template before and does match after a change.</p>
* <p>Typically indicates a new service has been registered that
* meets the search criteria.</p>
*/
final int TRANSITION_NOMATCH_MATCH = 4;
/**
* <p>Returns the service ID of the the service
* lookup (it is, itself, a service).</p>
*
* @return the service lookup's service id.
*/
ServiceID getServiceID();
/**
* <p>Returns the classes of all registered services that match the given service
* template.</p>
* <p/>
* Matches will return the most specific class that is not equal to,
* or a superclass of the template search class. Matches can be further restricted
* to those with names that begin with the given prefix (use null for the prefix
* to indicate any classes may match).</p>
*
* @return The list of matching service classes in the lookup
*/
Class[] getServiceTypes(ServiceTemplate tmpl, String prefix);
/**
* <p>Locates the a service based on it's class.</p>
* <p/>
* This is a convenience method for finding a service without having to create
* a lookup template. In most cases, we'll just want to find the a service
* implementing an interface, letting the service lookup do all the work.
* </p>
*
* @param type The class defining the type of service you want.
* @return An object guaranteed to implement the search type,
* or null if none are found
*/
Object lookup(Class type);
/**
* <p>Locates a service that matches the given service template.</p>
* <p>There are no
* guarantees about which service is returned as long as it matches the template
* (repeated calls may return the same matching service or different ones).
* </p><p>
* Note: The lookup returns the service (serviceItem.service), not the ServiceItem.
* </p>
*
* @param tmpl The lookup template to use
* @return The matching service (e.g. serviceItem.service)
*/
Object lookup(ServiceTemplate tmpl);
/**
* <p>Locate services that matche the given service template.</p>
* <p>In the case
* where maxMatches is smaller than the number of
* matching items, there are no guarantees about which
* subset of services is returned as long as they match the template
* (repeated calls may return the same matching set of services
* or different ones).
* </p>
* <p/>
* The items array in the returned matches is guaranteed to never be null, although
* it may contain a null entry.
* </p>
*
* @param tmpl The lookup template to use
* @param maxMatches The maximum number of matches to return
* @return The matching services
*/
ServiceMatches lookup(ServiceTemplate tmpl, int maxMatches);
/**
* <p>Register a service event listener for notification of lookup changes.</p>
* <p>Only transitions matching the given template and transition type will
* cause a notification (multiple transition types can be bit-wise OR'd together).
* The generated event is a ServiceEvent.</p>
*
* @param tmpl The lookup template to indicate what services to watch
* @param transitions The transition types to watch (multiple
* types may be bit-wise OR'd together)
* @param listener The listener to receive events
* @return The event registration object used to manage the registration
*/
EventRegistration notifyRegister(ServiceTemplate tmpl,
int transitions,
EventListener listener);
/**
* <p>Register a service with the lookup.</p>
* <p>The item contains all information relevant
* to the registration. New registrations should leave the item's ServiceID null
* so that the lookup can assign a new, unique ID. Previously registered services
* may be re-registered with the new item replacing the old one. Items are identified
* by service ID so you can easily replace any registration by reusing service IDs.
* It is preferable to replace dissimilar services by cancelling the previous service
* registration and registering a new service item with null ServiceID.</p>
*
* @param item The item to register
* @return The lookup registration object used to manage the registration
*/
ServiceRegistration register(ServiceItem item);
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.container;
import org.jivesoftware.messenger.auth.AuthToken;
import org.jivesoftware.messenger.auth.UnauthorizedException;
/**
* Works with the AuthFactory to create a simple way for classes
* (especially JSPs) to bootstrap their access to the container system.
* This factory singleton is static across the entire JVM (technically across
* the classloader context).
*
* @author Iain Shigeoka
*/
public class ServiceLookupFactory {
/**
* The provider of service lookups.
*/
private static ServiceLookupProvider provider = null;
/**
* Protect the factory class from being instantiated.
*/
private ServiceLookupFactory() {
}
/**
* Obtain a service lookup with a given authentication token. You can obtain
* the token from an AuthFactory.
*
* @param token The authentication token representing your system authorization
* @return The service lookup
* @throws UnauthorizedException If the caller doesn't have permission to
* invoke this method
*/
public static ServiceLookup getLookup(AuthToken token)
throws UnauthorizedException {
if (token == null || token.isAnonymous()) {
throw new UnauthorizedException("Auth token not valid");
}
if (provider == null) {
throw new IllegalStateException("Factory not configured with provider");
}
return provider.getServiceLookup();
}
/**
* Obtain a service lookup without an authentication token.
*
* @return the service lookup invokes this method.
* @throws UnauthorizedException if the caller does not have permission to obtain a lookup.
*/
public static ServiceLookup getLookup() throws UnauthorizedException {
if (provider == null) {
throw new IllegalStateException("Factory not configured with provider");
}
return provider.getServiceLookup();
}
/**
* Sets the provider this factory uses to generate lookups. The provider may only be
* added once (all subsequent calls are ignored). Calls to the getServiceLookup() methods
* will fail with an IllegalStateException until a provider is set (no default provider
* is available).
*
* @param slProvider The provider for this factory to use
*/
public static void setLookupProvider(ServiceLookupProvider slProvider) {
if (provider == null) {
provider = slProvider;
}
}
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.container;
import org.jivesoftware.messenger.auth.UnauthorizedException;
/**
* <p>Provides the service lookup factory with a producer of service
* lookups.</p>
*
* @author Iain Shigeoka
*/
public interface ServiceLookupProvider {
/**
* <p>Provide a lookup on demand. Implementations should cache
* the result (or use a singleton). The factory will call this
* method every time it has a service lookup request (the factory
* does no caching).</p>
*
* @return The lookup from this provider
* @throws UnauthorizedException If the caller does not have permission
* to access the service lookup
*/
ServiceLookup getServiceLookup() throws UnauthorizedException;
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.container;
import java.io.Serializable;
/**
* Used to return multiple service matches.
*
* @author Iain Shigeoka
*/
public class ServiceMatches implements Serializable {
/**
* The items that matched.
*/
public ServiceItem[] items;
/**
* The total number of items that matched
*/
public int totalMatches;
/**
* Serializable id. Increment whenever class signature changes.
*/
private static final long serialVersionUID = 1;
/**
* Create an empty match result.
*/
public ServiceMatches() {
items = new ServiceItem[]{
};
totalMatches = 0;
}
/**
* Create a match result with predefined settings.
*
* @param itemList the items found.
* @param matchCount the number of matches found.
*/
public ServiceMatches(ServiceItem[] itemList, int matchCount) {
if (itemList == null) {
items = new ServiceItem[]{};
totalMatches = 0;
}
else {
items = itemList;
}
this.totalMatches = matchCount;
}
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.container;
/**
* Provides the information needed to manage a service lookup registration.
*
* @author Iain Shigeoka
*/
public interface ServiceRegistration {
/**
* Obtains the serviceID for the service (created during registration).
*
* @return The service ID for the service this registration represents
*/
ServiceID getServiceID();
/**
* Deletes all existing lookup attributes for the service and adds the given
* attributes.
*
* @param attributes The new lookup attributes for the service
*/
void setAttributes(Entry[] attributes);
/**
* Cancels the lookup registration.
*/
void cancel();
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.container;
import java.io.Serializable;
/**
* <p>A template object used (query by example) in service lookups.
* Nulls are used to indicate wildcards.</p>
* <p/>
* Matches occur when the service item (i) and a service template (t):
* <ul>
* <li>i.serviceID.equals(t.serviceID) or t.serviceID == null</li>
* <li>AND</li>
* <li>for each Entry in t.attributes[n] there is a matching i.attributes[m]</li>
* <li>AND</li>
* <li>i.service is an instanceof all t.serviceTypes[n]</li>
* </ul>
* Entries match if the template Entry:
* <ul>
* <li>Is an instanceof the item Entry</li>
* <li>each field in the template entry is equal to the item, or is null</li>
* </ul>
* <p>The template attributes and/or serviceTypes arrays
* may be null to indicate a wildcard match.</p>
*
* @author Iain Shigeoka
*/
public class ServiceTemplate implements Serializable {
/**
* <p>The attributes to require for a match or null for wildcard.</p>
*/
public Entry[] attributes = null;
/**
* <p>The class type the service must implement
* for a match or null for wildcard.</p>
*/
public Class[] types = null;
/**
* <p>The ServiceID to require for a match or null for wildcard.</p>
*/
public ServiceID serviceID = null;
/**
* Serialization id. Increment whenever the class signature changes.
*/
private static final long serialVersionUID = 1;
/**
* <p>Create an empty service template.</p>
*/
public ServiceTemplate() {
}
/**
* <p>Create a service template with given properties.</p>
*
* @param id the service ID to search for or null for wildcard
* @param serviceAttributes The serviceAttributes to require
* for a match or null for wildcard
* @param serviceTypes The classes to require for a match or null for a wildcard
*/
public ServiceTemplate(ServiceID id,
Entry[] serviceAttributes,
Class[] serviceTypes) {
serviceID = id;
this.attributes = serviceAttributes;
this.types = serviceTypes;
}
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.container;
/**
* <p>Convenience class allowing very simple tracking of services
* in a container.</p>
* <p>To use the tracker, simply register a ServiceTrackerListener
* along with either one, or an array of classes to track. The tracker
* will use the listener methods to update the listener when services
* are added or removed from the lookup.</p>
* <p>All of the features here can be easily implemented using an
* event listener and the standard ServiceLookup.notifyEvent() method.
* This class just provides a default implementation of that for
* the most common case of wanting to know when certain services
* implementing an interface enter or leave the lookup.</p>
*
* @author Iain Shigeoka
*/
public class ServiceTracker {
private ServiceTrackerListener trackerListener;
private Class[] trackerClass;
private ServiceLookup trackerLookup;
private EventRegistration[] trackerRegs = null;
/**
* <p>Create a tracker to watch for the trackClass.</p>
*
* @param lookup The lookup to track services in
* @param listener The listener to be updated of trackClass services
* @param trackClass The class to track
* <p/>
*/
public ServiceTracker(ServiceLookup lookup,
ServiceTrackerListener listener,
Class trackClass) {
this(lookup, listener, new Class[]{trackClass});
}
/**
* <p>Create a tracker to watch for the trackClass.</p>
*
* @param lookup The lookup to track services in
* @param listener The listener to be updated of trackClass services
* @param trackClasses The classes to track
*/
public ServiceTracker(ServiceLookup lookup,
ServiceTrackerListener listener,
Class[] trackClasses) {
this.trackerListener = listener;
this.trackerClass = trackClasses;
this.trackerLookup = lookup;
setupTracking();
}
/**
* <p>Setup the tracking system.</p>
* <p>We just run through all the track classes and register our
* private event listener for match-nomatch and nomatch-match transitions.
* Our private event listener will decode the incoming events and generate
* the right tracker events.</p>
* <p/>
*/
private void setupTracking() {
TrackerEventListener eventListener = new TrackerEventListener();
trackerRegs = new EventRegistration[trackerClass.length];
for (int i = 0; i < trackerClass.length; i++) {
ServiceTemplate tmpl = new ServiceTemplate(null,
null,
new Class[]{trackerClass[i]});
trackerRegs[i] = trackerLookup.notifyRegister(tmpl,
ServiceLookup.TRANSITION_MATCH_NOMATCH |
ServiceLookup.TRANSITION_NOMATCH_MATCH,
eventListener);
}
// Now check to see if the service is already in the lookup
for (int i = 0; i < trackerClass.length; i++) {
ServiceTemplate tmpl = new ServiceTemplate(null,
null,
new Class[]{trackerClass[i]});
Object service = trackerLookup.lookup(tmpl);
if (service != null) {
trackerListener.addService(service);
}
}
// We don't need the classes anymore so free them
trackerClass = null;
}
/**
* Permanently cancels the tracking. Once you call this method, subsequent calls
* do nothing. The object becomes essentially worthless and you should remove
* any references to it so the garbage collector can clean it up.
*/
public void cancel() {
if (trackerRegs != null) {
for (int i = 0; i < trackerRegs.length; i++) {
trackerRegs[i].cancel();
}
trackerRegs = null;
trackerListener = null;
trackerClass = null;
trackerLookup = null;
}
}
/**
* Translates generic ServiceLookup notification events into the
* simplified tracker events that the ServiceTrackerListener expects.
* This class is all about convenience for users.
*
* @author Iain Shigeoka
*/
private class TrackerEventListener implements EventListener {
/**
* Receive notification of a ServiceLookup notification event.
*
* @param e The event that occured
* @throws UnknownEventException If the event is not what the listener expected
*/
public void notifyEvent(Event e) throws UnknownEventException {
if (e instanceof ServiceEvent) {
ServiceEvent event = (ServiceEvent)e;
switch (event.getTransition()) {
case ServiceLookup.TRANSITION_NOMATCH_MATCH:
trackerListener.addService(event.getServiceItem().service);
break;
case ServiceLookup.TRANSITION_MATCH_NOMATCH:
trackerListener.removeService(event.getServiceItem().service);
break;
default:
throw new UnknownEventException("Unexpected service event");
}
}
else {
throw new UnknownEventException();
}
}
}
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.container;
/**
* <p>A interface for listening to service tracking events.</p>
* <p>Implementations may choose to maintain a list of services
* obtained through the interface, or just one (first or last).
* It is critical that you watch for the removal of services as
* well as additions since services may go offline during hot
* deployments.</p>
*
* @author Iain Shigeoka
*/
public interface ServiceTrackerListener {
/**
* <p>A service has been added to the lookup matching a tracker class.</p>
* <p>The listener can check the instance of the service and use it
* appropriately. Instanceof is a bit expensive but since this only occurs
* when a service is added (startup, reconfiguration, shutdown) I don't
* think it should be an issue.</p>
*
* @param service The service that has just been added to the lookup.
*/
void addService(Object service);
/**
* <p>A service has been removed from the lookup matching a tracker class.</p>
* <p>The listener can check the instance of the service and use it
* appropriately. It is highly recommended that references to the service
* be removed (set to null) so that the garbage collector can remove them.
* Instanceof is a bit expensive but since this only occurs
* when a service is removed (startup, reconfiguration, shutdown) I don't
* think it should be an issue.</p>
*
* @param service The service that has just been added to the lookup.
*/
void removeService(Object service);
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.container;
import java.util.HashMap;
import java.util.Map;
/**
* <p>Information about tracker classes and the object to receive updates.</p>
*
* @author Iain Shigeoka
*/
public class TrackInfo {
/**
* The classes to use
*
* @see BasicModule#getTrackInfo();
*/
private Map trackerClasses = new HashMap();
/**
* Create a new TrackInfo object.
*/
public TrackInfo() {
}
/**
* <p>Obtain the tracker classes that a service tracker can register.</p>
* <p/>
* <p>The map is keyed on Class to track, and the result is the name of
* a field to assign the service to when it is found.</p>
*
* @return The tracker classes to be tracked and corresponding field names to alter
*/
public Map getTrackerClasses() {
return trackerClasses;
}
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.container;
/**
* Thrown by an event listener when an event is received that the
* listener does not wish to receive. This is a flag to the sender
* to no longer notifyEvent the listener of that event type.
*
* @author Iain Shigeoka
*/
public class UnknownEventException extends Exception {
/**
* Create an exception without a message.
*/
public UnknownEventException() {
super();
}
/**
* Create an exception with a message.
*
* @param msg The message to include with the exception
*/
public UnknownEventException(String msg) {
super(msg);
}
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.container;
/**
* Thrown if a service encounters an Entry class that does not
* follow the Entry class requirements.
*
* @author Iain Shigeoka
*/
public class UnuseableEntryException extends RuntimeException {
/**
* Creates an exception without a message.
*/
public UnuseableEntryException() {
super();
}
/**
* Create an exception with a message.
*
* @param msg the message to include with the exception.
*/
public UnuseableEntryException(String msg) {
super(msg);
}
}
......@@ -266,7 +266,7 @@ public interface MultiUserChatServer {
* 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
* of messages to log on each execution.
* @see org.jivesoftware.messenger.muc.spi.MultiUserChatServerImpl#initialize(org.jivesoftware.messenger.container.Container)
* @see org.jivesoftware.messenger.muc.spi.MultiUserChatServerImpl#initialize(org.jivesoftware.messenger.XMPPServer)
*
* @param room the room that received the message.
* @param message the message to log as part of the conversation in the room.
......
......@@ -25,6 +25,7 @@ import org.jivesoftware.messenger.disco.ServerFeaturesProvider;
import org.jivesoftware.messenger.disco.ServerItemsProvider;
import org.jivesoftware.messenger.handler.*;
import org.jivesoftware.messenger.muc.spi.MultiUserChatServerImpl;
import org.jivesoftware.messenger.muc.MultiUserChatServer;
import org.jivesoftware.messenger.transport.TransportHandler;
import org.jivesoftware.messenger.user.RosterManager;
import org.jivesoftware.messenger.user.UserManager;
......@@ -55,6 +56,8 @@ import java.util.*;
*/
public class BasicServer implements XMPPServer {
private static BasicServer instance;
private String name;
private Version version;
private Date startDate;
......@@ -84,10 +87,22 @@ public class BasicServer implements XMPPServer {
"org.jivesoftware.messenger.starter.ServerStarter";
private static final String WRAPPER_CLASSNAME =
"org.tanukisoftware.wrapper.WrapperManager";
/**
* Returns a singleton instance of BasicServer.
*
* @return an instance.
*/
public static BasicServer getInstance() {
return instance;
}
/**
* Creates a server and starts it.
*/
public BasicServer() {
instance = this;
start();
}
......@@ -275,8 +290,7 @@ public class BasicServer implements XMPPServer {
if (isRestartable()) {
try {
Class wrapperClass = Class.forName(WRAPPER_CLASSNAME);
Method stopMethod = wrapperClass.getMethod("stop",
new Class[]{Integer.TYPE});
Method stopMethod = wrapperClass.getMethod("stop", new Class[]{Integer.TYPE});
stopMethod.invoke(null, new Object[]{0});
}
catch (Exception e) {
......@@ -293,6 +307,10 @@ public class BasicServer implements XMPPServer {
}
}
public boolean isSetupMode() {
return setupMode;
}
private boolean isRestartable() {
boolean restartable = false;
try {
......@@ -322,8 +340,7 @@ public class BasicServer implements XMPPServer {
java.sql.Connection conn = null;
try {
conn = DbConnectionManager.getConnection();
PreparedStatement stmt = conn.prepareStatement(
"SELECT count(*) FROM jiveID");
PreparedStatement stmt = conn.prepareStatement("SELECT count(*) FROM jiveID");
ResultSet rs = stmt.executeQuery();
rs.next();
rs.close();
......@@ -620,4 +637,8 @@ public class BasicServer implements XMPPServer {
public PrivateStorage getPrivateStorage() {
return (PrivateStorage) modules.get(PrivateStorage.class);
}
public MultiUserChatServer getMultiUserChatServer() {
return (MultiUserChatServer) modules.get(MultiUserChatServerImpl.class);
}
}
\ No newline at end of file
......@@ -18,8 +18,8 @@ import org.jivesoftware.messenger.PresenceManager;
import org.jivesoftware.messenger.RoutingTable;
import org.jivesoftware.messenger.SessionManager;
import org.jivesoftware.messenger.XMPPServer;
import org.jivesoftware.messenger.spi.BasicServer;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.container.ServiceLookupFactory;
import org.jivesoftware.messenger.user.BasicRoster;
import org.jivesoftware.messenger.user.BasicRosterItem;
import org.jivesoftware.messenger.user.CachedRoster;
......@@ -99,8 +99,7 @@ public class CachedRosterImpl extends BasicRoster implements CachedRoster {
public void broadcastPresence(Presence packet) {
try {
if (routingTable == null) {
routingTable =
(RoutingTable)ServiceLookupFactory.getLookup().lookup(RoutingTable.class);
routingTable = BasicServer.getInstance().getRoutingTable();
}
if (routingTable == null) {
return;
......@@ -185,7 +184,7 @@ public class CachedRosterImpl extends BasicRoster implements CachedRoster {
if (cachedItem.getSubStatus() == RosterItem.SUB_BOTH
|| cachedItem.getSubStatus() == RosterItem.SUB_TO) {
if (presenceManager == null) {
presenceManager = (PresenceManager)ServiceLookupFactory.getLookup().lookup(PresenceManager.class);
presenceManager = BasicServer.getInstance().getPresenceManager();
}
presenceManager.probePresence(username, cachedItem.getJid());
}
......@@ -218,7 +217,7 @@ public class CachedRosterImpl extends BasicRoster implements CachedRoster {
private void broadcast(IQRoster roster) throws UnauthorizedException {
if (server == null) {
server = (XMPPServer)ServiceLookupFactory.getLookup().lookup(XMPPServer.class);
server = BasicServer.getInstance();
}
JID recipient = server.createJID(username, null);
roster.setTo(recipient);
......
......@@ -13,11 +13,10 @@ package org.jivesoftware.messenger.user.spi;
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.container.ServiceLookupFactory;
import org.jivesoftware.messenger.user.User;
import org.jivesoftware.messenger.user.UserManager;
import org.jivesoftware.messenger.user.UserNotFoundException;
import org.jivesoftware.messenger.spi.BasicServer;
/**
* An class that defines the logic to iterate through an array of long unique ID's of Jive objects.
......@@ -49,8 +48,7 @@ public class UserIterator implements Iterator {
/**
* Creates a new UserIterator.
*/
public UserIterator(String[] elements)
throws UnauthorizedException {
public UserIterator(String[] elements) {
this.elements = elements;
// Create an objectFactory to load users.
......@@ -60,9 +58,8 @@ public class UserIterator implements Iterator {
private class UserDOFactory {
private UserManager userManager;
public UserDOFactory() throws UnauthorizedException {
userManager =
(UserManager)ServiceLookupFactory.getLookup().lookup(UserManager.class);
public UserDOFactory() {
userManager = BasicServer.getInstance().getUserManager();
}
public Object loadObject(String username) {
......
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.net.spi;
import org.jivesoftware.net.ConnectionManager;
import org.jivesoftware.net.policies.BasicAcceptPolicy;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.*;
import org.jivesoftware.net.AcceptManager;
import org.jivesoftware.net.AcceptPort;
import org.jivesoftware.net.*;
import org.jivesoftware.messenger.container.*;
import org.jivesoftware.messenger.JiveGlobals;
import org.jivesoftware.util.*;
public class AcceptManagerImpl extends BasicModule implements AcceptManager {
private List<AcceptPort> ports = new ArrayList<AcceptPort>();
private AcceptPolicy policy = new BasicAcceptPolicy(true);
private ConnectionManager connManager;
public AcceptManagerImpl() {
super("Accept Manager");
}
public AcceptPolicy getGlobalAcceptPolicy() {
if (policy == null){
throw new IllegalStateException(
"Must initialize and start module before use");
}
return policy;
}
public int getAcceptPortCount() {
return ports.size();
}
public Iterator getAcceptPorts() {
return ports.iterator();
}
public Iterator getAcceptPorts(BasicResultFilter filter) {
return filter.filter(ports.iterator());
}
public AcceptPort getAcceptPort(InetSocketAddress portAddress)
throws NotFoundException {
AcceptPort matchedPort = null;
Iterator portIter = ports.iterator();
while (portIter.hasNext()){
AcceptPort acceptPort = (AcceptPort) portIter.next();
if (acceptPort.getInetSocketAddress().equals(portAddress)){
matchedPort = acceptPort;
}
}
if (matchedPort == null){
throw new NotFoundException(portAddress.toString());
}
return matchedPort;
}
public AcceptPort createAcceptPort(InetSocketAddress portAddress)
throws AlreadyExistsException {
if (connManager == null){
throw new IllegalStateException("Connection Manager not ready");
}
Iterator portIter = ports.iterator();
while (portIter.hasNext()){
AcceptPort acceptPort = (AcceptPort) portIter.next();
if (acceptPort.getInetSocketAddress().equals(portAddress)){
throw new AlreadyExistsException(portAddress.toString());
}
}
AcceptPort acceptPort = new AcceptPortImpl("acceptPorts.port" + ports.size(),
connManager, portAddress);
ports.add(acceptPort);
return acceptPort;
}
public void deleteAcceptPort(AcceptPort acceptPort) {
ports.remove(acceptPort);
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 {
acceptPort.close();
} catch (IOException e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
protected TrackInfo getTrackInfo() {
TrackInfo trackInfo = new TrackInfo();
trackInfo.getTrackerClasses().put(ConnectionManager.class,"");
return trackInfo;
}
protected void serviceAdded(Object service) {
if (service instanceof ConnectionManager){
connManager = (ConnectionManager) service;
for (String propName : JiveGlobals.getProperties("acceptPorts")) {
AcceptPort port = new AcceptPortImpl(propName, connManager);
ports.add(port);
}
if (ports.size() == 0) {
// Add a default
JiveGlobals.setProperty("acceptPorts.port1.portnumber", "5222");
AcceptPort port = new AcceptPortImpl("acceptPorts.port1", connManager);
ports.add(port);
}
}
}
}
......@@ -11,12 +11,8 @@
package org.jivesoftware.util;
import org.jivesoftware.messenger.container.Container;
import org.jivesoftware.messenger.container.ServiceLookup;
import org.jivesoftware.messenger.container.ServiceLookupFactory;
import org.jivesoftware.messenger.muc.MultiUserChatServer;
import org.jivesoftware.messenger.auth.AuthToken;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.user.User;
import org.jivesoftware.messenger.user.UserManager;
import org.jivesoftware.messenger.user.RosterManager;
......@@ -25,6 +21,7 @@ import org.jivesoftware.messenger.PrivateStorage;
import org.jivesoftware.messenger.PresenceManager;
import org.jivesoftware.messenger.SessionManager;
import org.jivesoftware.messenger.XMPPServerInfo;
import org.jivesoftware.messenger.spi.BasicServer;
import org.jivesoftware.messenger.group.GroupManager;
import java.util.LinkedHashMap;
......@@ -63,7 +60,7 @@ public class WebManager extends WebBean {
* Returns the XMPP server object -- can get many config items from here.
*/
public XMPPServer getXMPPServer() {
final XMPPServer xmppServer = (XMPPServer)getServiceLookup().lookup(XMPPServer.class);
final XMPPServer xmppServer = BasicServer.getInstance();
if (xmppServer == null) {
// Show that the server is down
showServerDown();
......@@ -97,7 +94,7 @@ public class WebManager extends WebBean {
}
public MultiUserChatServer getMultiUserChatServer() {
return getXMPPServer().getMultiUserChatServer;
return getXMPPServer().getMultiUserChatServer();
}
public XMPPServerInfo getServerInfo() {
......@@ -132,9 +129,9 @@ public class WebManager extends WebBean {
/**
* Restarts the container then sleeps for 3 seconds.
*/
/*public void restart(Container container) {
/*public void restart(XMPPServer server) {
try {
container.restart();
server.restart();
}
catch (Exception e) {
Log.error(e);
......@@ -145,7 +142,7 @@ public class WebManager extends WebBean {
/**
* Stops the server then sleeps for 3 seconds.
*/
public void stop(XMPPServer server) {
/*public void stop(XMPPServer server) {
try {
server.stop();
}
......@@ -153,7 +150,7 @@ public class WebManager extends WebBean {
Log.error(e);
}
sleep();
}
}*/
public WebManager getManager() {
return this;
......
......@@ -46,7 +46,7 @@
String logTimeout = ParamUtils.getParameter(request,"logTimeout");
// Get an audit manager:
AuditManager auditManager = (AuditManager)admin.getServiceLookup().lookup(AuditManager.class);
AuditManager auditManager = admin.getXMPPServer().getAuditManager();
Map errors = new HashMap();
if (update) {
......
......@@ -9,13 +9,11 @@
- a copy of which is included in this distribution.
--%>
<%@ page import="org.jivesoftware.messenger.container.ServiceLookup,
org.jivesoftware.messenger.container.ServiceLookupFactory,
org.jivesoftware.messenger.container.Container,
org.jivesoftware.messenger.auth.AuthToken,
<%@ page import="org.jivesoftware.messenger.auth.AuthToken,
org.jivesoftware.util.ClassUtils,
org.jivesoftware.messenger.XMPPServer,
org.jivesoftware.messenger.user.*"
org.jivesoftware.messenger.user.*,
org.jivesoftware.messenger.spi.BasicServer"
%>
<% // Security check
......@@ -40,9 +38,7 @@
}
// Check to see if we're in "setup" mode:
ServiceLookup lookup = ServiceLookupFactory.getLookup();
Container container = (Container)lookup.lookup(Container.class);
if (container.isSetupMode()) {
if (BasicServer.getInstance().isSetupMode()) {
response.sendRedirect("setup-index.jsp");
return;
}
......@@ -52,10 +48,10 @@
boolean isSystemAdmin = true;
// Otherwise, get the xmpp server
XMPPServer xmppServer = (XMPPServer)lookup.lookup(XMPPServer.class);
XMPPServer xmppServer = BasicServer.getInstance();
// The user object of the logged-in user
UserManager userManager = (UserManager)lookup.lookup(UserManager.class);
UserManager userManager = xmppServer.getUserManager();
User pageUser = null;
try {
pageUser = userManager.getUser(authToken.getUsername());
......
......@@ -9,9 +9,6 @@
org.jivesoftware.messenger.auth.AuthToken,
org.jivesoftware.messenger.auth.AuthFactory,
org.jivesoftware.messenger.auth.UnauthorizedException,
org.jivesoftware.messenger.container.Container,
org.jivesoftware.messenger.container.ServiceLookupFactory,
org.jivesoftware.messenger.container.ServiceLookup,
org.jivesoftware.messenger.JiveGlobals,
org.jivesoftware.util.Log,
org.jivesoftware.admin.AdminConsole"
......
......@@ -34,7 +34,7 @@
boolean openPerms = ParamUtils.getBooleanParameter(request,"openPerms");
// Get muc server
MultiUserChatServer mucServer = (MultiUserChatServer)admin.getServiceLookup().lookup(MultiUserChatServer.class);
MultiUserChatServer mucServer = admin.getMultiUserChatServer();
// Handle a save
Map errors = new HashMap();
......
......@@ -38,7 +38,7 @@
int numMessages = ParamUtils.getIntParameter(request,"numMessages",0);
// Get muc history
MultiUserChatServer mucServer = (MultiUserChatServer)admin.getServiceLookup().lookup(MultiUserChatServer.class);
MultiUserChatServer mucServer = admin.getMultiUserChatServer();
HistoryStrategy historyStrat = mucServer.getHistoryStrategy();
Map errors = new HashMap();
......
......@@ -29,7 +29,7 @@
boolean delete = ParamUtils.getBooleanParameter(request,"delete");
// Get muc server
MultiUserChatServer mucServer = (MultiUserChatServer)admin.getServiceLookup().lookup(MultiUserChatServer.class);
MultiUserChatServer mucServer = admin.getMultiUserChatServer();
// Handle a save
Map errors = new HashMap();
......
......@@ -35,7 +35,7 @@
boolean logSettingSuccess = request.getParameter("logSettingSuccess") != null;
// Get muc server
MultiUserChatServer mucServer = (MultiUserChatServer)admin.getServiceLookup().lookup(MultiUserChatServer.class);
MultiUserChatServer mucServer = admin.getMultiUserChatServer();
Map errors = new HashMap();
// Handle an update of the kicking task settings
......
......@@ -57,8 +57,7 @@
int quota = ParamUtils.getIntParameter(request,"quota",0);
// Get the offline message manager
OfflineMessageStrategy manager
= (OfflineMessageStrategy)admin.getServiceLookup().lookup(OfflineMessageStrategy.class);
OfflineMessageStrategy manager = admin.getXMPPServer().getOfflineMessageStrategy();
// Update the session kick policy if requested
Map errors = new HashMap();
......
<%@ page import="org.jivesoftware.messenger.container.Container,
org.jivesoftware.messenger.container.ServiceLookup,
org.jivesoftware.messenger.container.ServiceLookupFactory,
org.jivesoftware.util.Log,
org.jivesoftware.messenger.auth.UnauthorizedException"%>
<%--
- $RCSfile$
- $Revision$
- $Date$
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>Simple jsp page</title></head>
<body>Place your content here</body>
<% // Getting to this page means everything is setup, so restart the container.
// flush the page first
out.flush();
// Let them have a chance to get other page assets
try {
Thread.sleep(3000L);
}
catch (Exception ignored) {}
// then restart the server
Container container = null;
try {
ServiceLookup lookup = ServiceLookupFactory.getLookup();
container = (Container)lookup.lookup(Container.class);
}
catch (Exception e) {
Log.error(e);
}
// do the restart if the container is not null
if (container != null) {
try {
container.restart();
}
catch (UnauthorizedException e) {
Log.error(e);
}
}
%>
</html>
\ No newline at end of file
......@@ -13,12 +13,10 @@
org.jivesoftware.messenger.auth.UnauthorizedException,
org.jivesoftware.messenger.auth.AuthFactory,
org.jivesoftware.messenger.auth.AuthToken,
org.jivesoftware.messenger.container.ServiceLookup,
org.jivesoftware.messenger.container.ServiceLookupFactory,
org.jivesoftware.messenger.container.Container,
org.jivesoftware.messenger.JiveGlobals,
org.jivesoftware.messenger.auth.spi.DbAuthProvider,
org.jivesoftware.messenger.user.spi.UserManagerImpl" %>
org.jivesoftware.messenger.user.spi.UserManagerImpl,
org.jivesoftware.messenger.spi.BasicServer" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
......@@ -76,55 +74,35 @@
}
// if no errors, continue:
if (errors.size() == 0) {
AuthToken auth = null;
try {
auth = AuthFactory.getAuthToken("admin", password);
try {
ServiceLookup lookup = ServiceLookupFactory.getLookup(auth);
Container container = (Container)lookup.lookup(Container.class);
// Start the user manager service
container.startService(UserManager.class);
// Get the service
UserManager userManager = (UserManager)lookup.lookup(UserManager.class);
if(userManager == null) {
userManager = new UserManagerImpl();
userManager.initialize(container);
}
User adminUser = userManager.getUser("admin");
adminUser.setPassword(newPassword);
if (email != null) {
adminUser.getInfo().setEmail(email);
}
Date now = new Date();
adminUser.getInfo().setCreationDate(now);
adminUser.getInfo().setModificationDate(now);
adminUser.saveInfo();
// TODO: Check for Plugin
// setup is finished, indicate so:
setSetupFinished(session);
// All good so redirect
response.sendRedirect("setup-finished.jsp");
return;
}
catch (Exception e) {
System.err.println("Could not find UserManager");
errors.put("general","There was an unexpected error encountered when "
+ "setting the new admin information. Please check your error "
+ "logs and try to remedy the problem.");
// Get the service
UserManager userManager = new UserManagerImpl();
userManager.initialize(BasicServer.getInstance());
User adminUser = userManager.getUser("admin");
adminUser.setPassword(newPassword);
if (email != null) {
adminUser.getInfo().setEmail(email);
}
Date now = new Date();
adminUser.getInfo().setCreationDate(now);
adminUser.getInfo().setModificationDate(now);
adminUser.saveInfo();
// TODO: Check for Plugin
// setup is finished, indicate so:
setSetupFinished(session);
// All good so redirect
response.sendRedirect("setup-finished.jsp");
return;
}
catch (UnauthorizedException ue) {
errors.put("password", "The value you supplied for the current password field "
+ "does not appear to be the valid password for the admin account. "
+ "Try again with the correct password.");
catch (Exception e) {
System.err.println("Could not find UserManager");
errors.put("general","There was an unexpected error encountered when "
+ "setting the new admin information. Please check your error "
+ "logs and try to remedy the problem.");
}
}
}
......
......@@ -7,9 +7,6 @@
--%>
<%@ page import="org.jivesoftware.util.ParamUtils,
org.jivesoftware.messenger.container.Container,
org.jivesoftware.messenger.container.ServiceLookup,
org.jivesoftware.messenger.container.ServiceLookupFactory,
org.jivesoftware.messenger.auth.UnauthorizedException,
org.jivesoftware.messenger.JiveGlobals,
java.util.Map,
......
......@@ -17,30 +17,6 @@
<% // Figure out if we've already run setup:
boolean doSetup = false;
//
try {
// ServiceLookup lookup = ServiceLookupFactory.getServiceLookup();
// Class serviceLookupFactoryClass = loadClass("org.jivesoftware.messenger.container.ServiceLookupFactory");
// Method getLookupMethod = serviceLookupFactoryClass.getMethod("getServiceLookup",null);
// Object serviceLookupObj = getLookupMethod.invoke(serviceLookupFactoryClass,null);
//
// // Container container = (Container)lookup.lookup(Container.class);
// Method lookupMethod = serviceLookupObj.getClass().getMethod("lookup",new Class[]{java.lang.Class.class});
// Object containerObj = lookupMethod.invoke(serviceLookupObj,new Class[]{org.jivesoftware.messenger.container.Container.class});
//
// // boolean isSetup = container.isSetupMode()
// Method isSetupModeMethod = containerObj.getClass().getMethod("isSetupMode",null);
// Object isSetupObj = isSetupModeMethod.invoke(containerObj,null);
// boolean setupMode = ((Boolean)isSetupObj).booleanValue();
//
// if (setupMode) {
// doSetup = true;
// }
}
catch (Throwable t) {
//t.printStackTrace();
doSetup = true;
}
if (!doSetup) {
response.sendRedirect("setup-completed.jsp");
......
......@@ -12,8 +12,7 @@
java.sql.Statement,
java.sql.SQLException,
java.util.Map,
org.jivesoftware.util.ClassUtils,
org.jivesoftware.messenger.container.ServiceLookupFactory"
org.jivesoftware.util.ClassUtils"
%>
<jsp:useBean id="admin" class="org.jivesoftware.util.WebManager" />
......
......@@ -8,10 +8,7 @@
<%@ page import="org.jivesoftware.util.ParamUtils,
org.jivesoftware.messenger.JiveGlobals,
java.util.*,
org.jivesoftware.messenger.container.ServiceLookup,
org.jivesoftware.messenger.container.Container,
org.jivesoftware.messenger.container.ServiceLookupFactory" %>
java.util.*" %>
<%! // Global vars, methods, etc
......
......@@ -6,9 +6,6 @@
--%>
<%@ page import="org.jivesoftware.util.ParamUtils,
org.jivesoftware.messenger.container.Container,
org.jivesoftware.messenger.container.ServiceLookup,
org.jivesoftware.messenger.container.ServiceLookupFactory,
org.jivesoftware.messenger.auth.UnauthorizedException" %>
<%-- Define Administration Bean --%>
......
......@@ -9,10 +9,7 @@
- a copy of which is included in this distribution.
--%>
<%@ page import="org.jivesoftware.messenger.container.ServiceLookup,
org.jivesoftware.messenger.container.ServiceLookupFactory,
org.jivesoftware.messenger.container.Container,
org.jivesoftware.util.StringUtils,
<%@ page import="org.jivesoftware.util.StringUtils,
org.jivesoftware.admin.AdminConsole"
errorPage="error.jsp"
%>
......
......@@ -43,7 +43,7 @@
int userCount = webManager.getUserManager().getUserCount();
// Get the presence manager
PresenceManager presenceManager = (PresenceManager)webManager.getServiceLookup().lookup(PresenceManager.class);
PresenceManager presenceManager = webManager.getPresenceManager();
// paginator vars
int numPages = (int)Math.ceil((double)userCount/(double)range);
......
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