Commit cd6e17eb authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

Added disconnect of sessions on shutdown [GATE-17], probe of sessions on...

Added disconnect of sessions on shutdown [GATE-17], probe of sessions on startup [GATE-18], switched from XXXEnabled to XXX.enabled property [GATE-21], and added various listeners.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@5102 b35dd754-fafc-0310-a699-88a17e54d16e
parent 86fbcf0a
......@@ -16,11 +16,10 @@ import org.dom4j.QName;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.NotFoundException;
import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.SessionManager;
import org.jivesoftware.wildfire.container.PluginManager;
import org.jivesoftware.wildfire.roster.*;
import org.jivesoftware.wildfire.roster.Roster;
import org.jivesoftware.wildfire.roster.RosterItem;
import org.jivesoftware.wildfire.roster.RosterManager;
import org.jivesoftware.wildfire.roster.RosterEventListener;
import org.jivesoftware.wildfire.user.UserAlreadyExistsException;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.xmpp.component.Component;
......@@ -684,7 +683,16 @@ public abstract class BaseTransport implements Component, RosterEventListener {
* Handles startup of the transport.
*/
public void start() {
// Do nothing.
RosterEventDispatcher.addListener(this);
// Probe all registered users [if they are logged in] to auto-log them in
for (Registration registration : registrationManager.getRegistrations()) {
if (SessionManager.getInstance().getSessionCount(registration.getJID().getNode()) > 0) {
Presence p = new Presence(Presence.Type.probe);
p.setFrom(this.getJID());
p.setTo(registration.getJID());
sendPacket(p);
}
}
}
/**
......@@ -693,7 +701,11 @@ public abstract class BaseTransport implements Component, RosterEventListener {
* Cleans up all active sessions.
*/
public void shutdown() {
// TODO: actually make this function
RosterEventDispatcher.removeListener(this);
// Disconnect everyone's session
for (TransportSession session : sessionManager.getSessions()) {
registrationLoggedOut(session);
}
}
/**
......
......@@ -95,7 +95,7 @@ public class GatewayPlugin implements Plugin {
private void maybeStartService(String serviceName) {
TransportInstance trInstance = transports.get(serviceName);
trInstance.startInstance();
Log.debug("Starting transport service: "+serviceName);
Log.info("Starting transport service: "+serviceName);
}
/**
......@@ -104,7 +104,7 @@ public class GatewayPlugin implements Plugin {
public void enableService(String serviceName) {
TransportInstance trInstance = transports.get(serviceName);
trInstance.enable();
Log.debug("Enabling transport service: "+serviceName);
Log.info("Enabling transport service: "+serviceName);
}
/**
......@@ -113,7 +113,7 @@ public class GatewayPlugin implements Plugin {
public void disableService(String serviceName) {
TransportInstance trInstance = transports.get(serviceName);
trInstance.disable();
Log.debug("Disabling transport service: "+serviceName);
Log.info("Disabling transport service: "+serviceName);
}
/**
......
......@@ -13,6 +13,7 @@ package org.jivesoftware.wildfire.gateway;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.PropertyEventListener;
import org.jivesoftware.util.PropertyEventDispatcher;
import org.xmpp.component.ComponentManager;
import java.util.Map;
......@@ -47,7 +48,7 @@ public class TransportInstance implements PropertyEventListener {
this.type = type;
this.nameOfClass = classname;
this.componentManager = componentManager;
enabled = JiveGlobals.getBooleanProperty("plugin.gateway."+this.type.toString()+"Enabled", false);
enabled = JiveGlobals.getBooleanProperty("plugin.gateway."+this.type.toString()+".enabled", false);
}
/**
......@@ -82,7 +83,7 @@ public class TransportInstance implements PropertyEventListener {
*/
public void enable() {
enabled = true;
JiveGlobals.setProperty("plugin.gateway."+this.type.toString()+"Enabled", "true");
JiveGlobals.setProperty("plugin.gateway."+this.type.toString()+".enabled", "true");
if (!running) {
startInstance();
}
......@@ -93,7 +94,7 @@ public class TransportInstance implements PropertyEventListener {
*/
public void disable() {
enabled = false;
JiveGlobals.setProperty("plugin.gateway."+this.type.toString()+"Enabled", "false");
JiveGlobals.setProperty("plugin.gateway."+this.type.toString()+".enabled", "false");
if (running) {
stopInstance();
}
......@@ -109,7 +110,7 @@ public class TransportInstance implements PropertyEventListener {
transport = null;
Log.debug("Loading class "+nameOfClass);
//Log.debug("Loading class "+nameOfClass);
try {
transport = (BaseTransport)Class.forName(nameOfClass).newInstance();
......@@ -127,7 +128,7 @@ public class TransportInstance implements PropertyEventListener {
try {
componentManager.addComponent(this.type.toString(), transport);
//PropertyEventDispatcher.addListener(transport);
PropertyEventDispatcher.addListener(this);
running = true;
}
catch (Exception e) {
......@@ -143,7 +144,7 @@ public class TransportInstance implements PropertyEventListener {
return;
}
//PropertyEventDispatcher.removeListener(transport);
PropertyEventDispatcher.removeListener(this);
try {
componentManager.removeComponent(this.type.toString());
}
......@@ -162,7 +163,7 @@ public class TransportInstance implements PropertyEventListener {
}
public void propertySet(String property, Map params) {
if (property.equals("plugin.gateway."+this.type.toString()+"Enabled")) {
if (property.equals("plugin.gateway."+this.type.toString()+".enabled")) {
enabled = Boolean.parseBoolean((String)params.get("value"));
if (enabled) {
if (!running) {
......@@ -178,7 +179,7 @@ public class TransportInstance implements PropertyEventListener {
}
public void propertyDeleted(String property, Map params) {
if (property.equals("plugin.gateway."+this.type.toString()+"Enabled")) {
if (property.equals("plugin.gateway."+this.type.toString()+".enabled")) {
if (running) {
stopInstance();
}
......@@ -186,11 +187,27 @@ public class TransportInstance implements PropertyEventListener {
}
public void xmlPropertySet(String property, Map params) {
// Ignore
if (property.equals("plugin.gateway."+this.type.toString()+".enabled")) {
enabled = Boolean.parseBoolean((String)params.get("value"));
if (enabled) {
if (!running) {
startInstance();
}
}
else {
if (running) {
stopInstance();
}
}
}
}
public void xmlPropertyDeleted(String property, Map params) {
// Ignore
if (property.equals("plugin.gateway."+this.type.toString()+".enabled")) {
if (running) {
stopInstance();
}
}
}
}
......@@ -10,8 +10,8 @@
package org.jivesoftware.wildfire.gateway;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import org.jivesoftware.util.NotFoundException;
import org.xmpp.packet.JID;
......@@ -72,4 +72,13 @@ public class TransportSessionManager {
activeSessions.remove(new JID(jid.toBareJID()));
}
/**
* Retrieves a collection of all active sessions.
*
* @return List of active sessions.
*/
public Collection<TransportSession> getSessions() {
return activeSessions.values();
}
}
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